Bug 674725 - Part W - Implement SmsRequestManager. r=smaug

This commit is contained in:
Mounir Lamouri 2011-12-20 13:07:16 +01:00
parent e3e59333be
commit de42946157
5 changed files with 183 additions and 1 deletions

View File

@ -67,6 +67,7 @@ EXPORTS_mozilla/dom/sms = \
Constants.h \
Types.h \
SmsMessage.h \
SmsRequestManager.h \
$(NULL)
CPPSRCS = \
@ -81,6 +82,7 @@ CPPSRCS = \
SmsChild.cpp \
SmsDatabaseService.cpp \
SmsRequest.cpp \
SmsRequestManager.cpp \
$(NULL)
LOCAL_INCLUDES = \

View File

@ -51,6 +51,8 @@ class SmsRequest : public nsIDOMMozSmsRequest
, public nsDOMEventTargetWrapperCache
{
public:
friend class SmsRequestManager;
enum ErrorType {
eNoError = 0,
eInternalError,

View File

@ -0,0 +1,99 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "SmsRequestManager.h"
#include "SmsRequest.h"
namespace mozilla {
namespace dom {
namespace sms {
SmsRequestManager* SmsRequestManager::sInstance = nsnull;
void
SmsRequestManager::Init()
{
NS_PRECONDITION(!sInstance,
"sInstance shouldn't be set. Did you call Init() twice?");
sInstance = new SmsRequestManager();
}
void
SmsRequestManager::Shutdown()
{
NS_PRECONDITION(sInstance, "sInstance should be set. Did you call Init()?");
delete sInstance;
sInstance = nsnull;
}
/* static */ SmsRequestManager*
SmsRequestManager::GetInstance()
{
return sInstance;
}
PRInt32
SmsRequestManager::CreateRequest(nsPIDOMWindow* aWindow,
nsIScriptContext* aScriptContext,
nsIDOMMozSmsRequest** aRequest)
{
nsCOMPtr<nsIDOMMozSmsRequest> request =
new SmsRequest(aWindow, aScriptContext);
PRInt32 size = mRequests.Count();
// Look for empty slots.
for (PRInt32 i=0; i<size; ++i) {
if (mRequests[i]) {
continue;
}
mRequests.ReplaceObjectAt(request, i);
NS_ADDREF(*aRequest = request);
return i;
}
mRequests.AppendObject(request);
NS_ADDREF(*aRequest = request);
return size;
}
} // namespace sms
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,73 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mounir Lamouri <mounir.lamouri@mozilla.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_dom_sms_SmsRequestManager_h
#define mozilla_dom_sms_SmsRequestManager_h
#include "nsCOMArray.h"
class nsIDOMMozSmsRequest;
class nsPIDOMWindow;
class nsIScriptContext;
namespace mozilla {
namespace dom {
namespace sms {
class SmsRequestManager
{
public:
static void Init();
static void Shutdown();
static SmsRequestManager* GetInstance();
PRInt32 CreateRequest(nsPIDOMWindow* aWindow,
nsIScriptContext* aScriptContext,
nsIDOMMozSmsRequest** aRequest);
private:
static SmsRequestManager* sInstance;
nsCOMArray<nsIDOMMozSmsRequest> mRequests;
};
} // namespace sms
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_sms_SmsRequestManager_h

View File

@ -125,10 +125,12 @@
#include "nsHyphenationManager.h"
#include "nsEditorSpellCheck.h"
#include "nsDOMMemoryReporter.h"
#include "mozilla/dom/sms/SmsRequestManager.h"
extern void NS_ShutdownChainItemPool();
using namespace mozilla;
using namespace mozilla::dom;
nsrefcnt nsLayoutStatics::sLayoutStaticRefcnt = 0;
@ -161,7 +163,7 @@ nsLayoutStatics::Initialize()
}
nsGlobalWindow::Init();
dom::Navigator::Init();
Navigator::Init();
rv = nsContentUtils::Init();
if (NS_FAILED(rv)) {
@ -270,12 +272,16 @@ nsLayoutStatics::Initialize()
nsDOMMemoryMultiReporter::Init();
sms::SmsRequestManager::Init();
return NS_OK;
}
void
nsLayoutStatics::Shutdown()
{
sms::SmsRequestManager::Shutdown();
// Don't need to shutdown nsDOMMemoryReporter, that will be done by the memory
// reporter manager.