Bug 950315 part 2. Convert some idb classes to passing a Window or nsDOMEventTargetHelper directly to the constructor of their ancestor nsDOMEventTargetHelper. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 07 Jan 2014 00:32:20 -0500
changeset 162316 1fc3ac9b4a2c669b7b72d72a8c2ffbd59ff77b99
parent 162315 215f5bc6284dfc1778d01ae0fe52a9ea96d6bf2a
child 162318 5734ebc705fdeab0f0590f48e2ba8218b6949c75
push id38161
push userbzbarsky@mozilla.com
push dateTue, 07 Jan 2014 05:32:44 +0000
treeherdermozilla-inbound@1fc3ac9b4a2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs950315
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 950315 part 2. Convert some idb classes to passing a Window or nsDOMEventTargetHelper directly to the constructor of their ancestor nsDOMEventTargetHelper. r=khuey
dom/indexedDB/IDBDatabase.cpp
dom/indexedDB/IDBDatabase.h
dom/indexedDB/IDBRequest.cpp
dom/indexedDB/IDBRequest.h
dom/indexedDB/IDBTransaction.cpp
dom/indexedDB/IDBTransaction.h
dom/indexedDB/IDBWrapperCache.h
--- a/dom/indexedDB/IDBDatabase.cpp
+++ b/dom/indexedDB/IDBDatabase.cpp
@@ -184,19 +184,18 @@ IDBDatabase::Create(IDBWrapperCache* aOw
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(aFactory, "Null pointer!");
   NS_ASSERTION(!aASCIIOrigin.IsEmpty(), "Empty origin!");
 
   nsRefPtr<DatabaseInfo> databaseInfo(aDatabaseInfo);
   NS_ASSERTION(databaseInfo, "Null pointer!");
 
-  nsRefPtr<IDBDatabase> db(new IDBDatabase());
+  nsRefPtr<IDBDatabase> db(new IDBDatabase(aOwnerCache));
 
-  db->BindToOwner(aOwnerCache);
   db->SetScriptOwner(aOwnerCache->GetScriptOwner());
   db->mFactory = aFactory;
   db->mDatabaseId = databaseInfo->id;
   db->mName = databaseInfo->name;
   db->mFilePath = databaseInfo->filePath;
   db->mPersistenceType = databaseInfo->persistenceType;
   db->mGroup = databaseInfo->group;
   databaseInfo.swap(db->mDatabaseInfo);
@@ -223,28 +222,27 @@ IDBDatabase::Create(IDBWrapperCache* aOw
 // static
 IDBDatabase*
 IDBDatabase::FromStorage(nsIOfflineStorage* aStorage)
 {
   return aStorage->GetClient()->GetType() == Client::IDB ?
          static_cast<IDBDatabase*>(aStorage) : nullptr;
 }
 
-IDBDatabase::IDBDatabase()
-: mActorChild(nullptr),
+IDBDatabase::IDBDatabase(IDBWrapperCache* aOwnerCache)
+: IDBWrapperCache(aOwnerCache),
+  mActorChild(nullptr),
   mActorParent(nullptr),
   mContentParent(nullptr),
   mInvalidated(false),
   mRegistered(false),
   mClosed(false),
   mRunningVersionChange(false)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-
-  SetIsDOMBinding();
 }
 
 IDBDatabase::~IDBDatabase()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 void
--- a/dom/indexedDB/IDBDatabase.h
+++ b/dom/indexedDB/IDBDatabase.h
@@ -225,17 +225,17 @@ public:
 
   already_AddRefed<IDBRequest>
   MozCreateFileHandle(const nsAString& aName, const Optional<nsAString>& aType,
                       ErrorResult& aRv);
 
   virtual void LastRelease() MOZ_OVERRIDE;
 
 private:
-  IDBDatabase();
+  IDBDatabase(IDBWrapperCache* aOwnerCache);
   ~IDBDatabase();
 
   void OnUnlink();
 
   // The factory must be kept alive when IndexedDB is used in multiple
   // processes. If it dies then the entire actor tree will be destroyed with it
   // and the world will explode.
   nsRefPtr<IDBFactory> mFactory;
--- a/dom/indexedDB/IDBRequest.cpp
+++ b/dom/indexedDB/IDBRequest.cpp
@@ -38,47 +38,59 @@ uint64_t gNextRequestSerialNumber = 1;
 #endif
 
 } // anonymous namespace
 
 USING_INDEXEDDB_NAMESPACE
 using mozilla::dom::OwningIDBObjectStoreOrIDBIndexOrIDBCursor;
 using namespace mozilla;
 
-IDBRequest::IDBRequest()
-: mResultVal(JSVAL_VOID),
+IDBRequest::IDBRequest(IDBDatabase* aDatabase)
+: IDBWrapperCache(aDatabase),
+  mResultVal(JSVAL_VOID),
   mActorParent(nullptr),
 #ifdef MOZ_ENABLE_PROFILER_SPS
   mSerialNumber(gNextRequestSerialNumber++),
 #endif
   mErrorCode(NS_OK),
   mLineNo(0),
   mHaveResultOrErrorCode(false)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+}
 
-  SetIsDOMBinding();
+IDBRequest::IDBRequest(nsPIDOMWindow* aOwner)
+: IDBWrapperCache(aOwner),
+  mResultVal(JSVAL_VOID),
+  mActorParent(nullptr),
+#ifdef MOZ_ENABLE_PROFILER_SPS
+  mSerialNumber(gNextRequestSerialNumber++),
+#endif
+  mErrorCode(NS_OK),
+  mLineNo(0),
+  mHaveResultOrErrorCode(false)
+{
+  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 IDBRequest::~IDBRequest()
 {
   mResultVal = JSVAL_VOID;
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 // static
 already_AddRefed<IDBRequest>
 IDBRequest::Create(IDBDatabase* aDatabase,
                    IDBTransaction* aTransaction)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-  nsRefPtr<IDBRequest> request(new IDBRequest());
+  nsRefPtr<IDBRequest> request(new IDBRequest(aDatabase));
 
   request->mTransaction = aTransaction;
-  request->BindToOwner(aDatabase);
   request->SetScriptOwner(aDatabase->GetScriptOwner());
 
   if (!aDatabase->Factory()->FromIPC()) {
     request->CaptureCaller();
   }
 
 
   return request.forget();
@@ -375,40 +387,38 @@ IDBRequest::PreHandleEvent(nsEventChainP
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 
   aVisitor.mCanHandle = true;
   aVisitor.mParentTarget = mTransaction;
   return NS_OK;
 }
 
-IDBOpenDBRequest::IDBOpenDBRequest()
+IDBOpenDBRequest::IDBOpenDBRequest(nsPIDOMWindow* aOwner)
+  : IDBRequest(aOwner)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-
-  SetIsDOMBinding();
 }
 
 IDBOpenDBRequest::~IDBOpenDBRequest()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
 }
 
 // static
 already_AddRefed<IDBOpenDBRequest>
 IDBOpenDBRequest::Create(IDBFactory* aFactory,
                          nsPIDOMWindow* aOwner,
                          JS::Handle<JSObject*> aScriptOwner)
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(aFactory, "Null pointer!");
 
-  nsRefPtr<IDBOpenDBRequest> request = new IDBOpenDBRequest();
+  nsRefPtr<IDBOpenDBRequest> request = new IDBOpenDBRequest(aOwner);
 
-  request->BindToOwner(aOwner);
   request->SetScriptOwner(aScriptOwner);
   request->mFactory = aFactory;
 
   if (!aFactory->FromIPC()) {
     request->CaptureCaller();
   }
 
   return request.forget();
--- a/dom/indexedDB/IDBRequest.h
+++ b/dom/indexedDB/IDBRequest.h
@@ -140,17 +140,18 @@ public:
 
   IDBRequestReadyState
   ReadyState() const;
 
   IMPL_EVENT_HANDLER(success);
   IMPL_EVENT_HANDLER(error);
 
 protected:
-  IDBRequest();
+  IDBRequest(IDBDatabase* aDatabase);
+  IDBRequest(nsPIDOMWindow* aOwner);
   ~IDBRequest();
 
   // At most one of these three fields can be non-null.
   nsRefPtr<IDBObjectStore> mSourceAsObjectStore;
   nsRefPtr<IDBIndex> mSourceAsIndex;
   nsRefPtr<IDBCursor> mSourceAsCursor;
 
   // Check that the above condition holds.
@@ -206,17 +207,17 @@ public:
   virtual JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
 
   // WebIDL
   IMPL_EVENT_HANDLER(blocked);
   IMPL_EVENT_HANDLER(upgradeneeded);
 
 protected:
-  IDBOpenDBRequest();
+  IDBOpenDBRequest(nsPIDOMWindow* aOwner);
   ~IDBOpenDBRequest();
 
   // Only touched on the main thread.
   nsRefPtr<IDBFactory> mFactory;
 };
 
 END_INDEXEDDB_NAMESPACE
 
--- a/dom/indexedDB/IDBTransaction.cpp
+++ b/dom/indexedDB/IDBTransaction.cpp
@@ -100,19 +100,18 @@ IDBTransaction::CreateInternal(IDBDataba
   NS_ASSERTION(IndexedDatabaseManager::IsMainProcess() || !aDispatchDelayed,
                "No support for delayed-dispatch transactions in child "
                "process!");
   NS_ASSERTION(!aIsVersionChangeTransactionChild ||
                (!IndexedDatabaseManager::IsMainProcess() &&
                 aMode == IDBTransaction::VERSION_CHANGE),
                "Busted logic!");
 
-  nsRefPtr<IDBTransaction> transaction = new IDBTransaction();
+  nsRefPtr<IDBTransaction> transaction = new IDBTransaction(aDatabase);
 
-  transaction->BindToOwner(aDatabase);
   transaction->SetScriptOwner(aDatabase->GetScriptOwner());
   transaction->mDatabase = aDatabase;
   transaction->mMode = aMode;
   transaction->mDatabaseInfo = aDatabase->Info();
   transaction->mObjectStoreNames.AppendElements(aObjectStoreNames);
   transaction->mObjectStoreNames.Sort();
 
   IndexedDBTransactionChild* actor = nullptr;
@@ -152,35 +151,34 @@ IDBTransaction::CreateInternal(IDBDataba
   if (actor) {
     NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
     actor->SetTransaction(transaction);
   }
 
   return transaction.forget();
 }
 
-IDBTransaction::IDBTransaction()
-: mReadyState(IDBTransaction::INITIAL),
+IDBTransaction::IDBTransaction(IDBDatabase* aDatabase)
+: IDBWrapperCache(aDatabase),
+  mReadyState(IDBTransaction::INITIAL),
   mMode(IDBTransaction::READ_ONLY),
   mPendingRequests(0),
   mSavepointCount(0),
   mActorChild(nullptr),
   mActorParent(nullptr),
   mAbortCode(NS_OK),
 #ifdef MOZ_ENABLE_PROFILER_SPS
   mSerialNumber(gNextTransactionSerialNumber++),
 #endif
   mCreating(false)
 #ifdef DEBUG
   , mFiredCompleteOrAbort(false)
 #endif
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
-
-  SetIsDOMBinding();
 }
 
 IDBTransaction::~IDBTransaction()
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(!mPendingRequests, "Should have no pending requests here!");
   NS_ASSERTION(!mSavepointCount, "Should have released them all!");
   NS_ASSERTION(!mConnection, "Should have called CommitOrRollback!");
--- a/dom/indexedDB/IDBTransaction.h
+++ b/dom/indexedDB/IDBTransaction.h
@@ -265,17 +265,17 @@ private:
   // Should only be called directly through IndexedDBDatabaseChild.
   static already_AddRefed<IDBTransaction>
   CreateInternal(IDBDatabase* aDatabase,
                  const Sequence<nsString>& aObjectStoreNames,
                  Mode aMode,
                  bool aDispatchDelayed,
                  bool aIsVersionChangeTransactionChild);
 
-  IDBTransaction();
+  IDBTransaction(IDBDatabase* aDatabase);
   ~IDBTransaction();
 
   nsresult CommitOrRollback();
 
   nsRefPtr<IDBDatabase> mDatabase;
   nsRefPtr<DatabaseInfo> mDatabaseInfo;
   nsRefPtr<DOMError> mError;
   nsTArray<nsString> mObjectStoreNames;
--- a/dom/indexedDB/IDBWrapperCache.h
+++ b/dom/indexedDB/IDBWrapperCache.h
@@ -44,18 +44,21 @@ public:
   void AssertIsRooted() const;
 #else
   inline void AssertIsRooted() const
   {
   }
 #endif
 
 protected:
-  IDBWrapperCache()
-  : mScriptOwner(nullptr)
+  IDBWrapperCache(nsDOMEventTargetHelper* aOwner)
+    : nsDOMEventTargetHelper(aOwner), mScriptOwner(nullptr)
+  { }
+  IDBWrapperCache(nsPIDOMWindow* aOwner)
+    : nsDOMEventTargetHelper(aOwner), mScriptOwner(nullptr)
   { }
 
   virtual ~IDBWrapperCache();
 
 private:
   JS::Heap<JSObject*> mScriptOwner;
 };