Bug 1289375 - Rollback incomplete change of preloading cursors for IndexedDB. r=khuey
authorBevis Tseng <btseng@mozilla.com>
Tue, 26 Jul 2016 18:51:19 +0800
changeset 308039 eda36a4f93032a0e76b35861c48694eed8710f33
parent 308038 7eb40c545894888263c099243b2986e9fce0839f
child 308040 cc4286c4da37de45da2de785bb2a314ea4fba083
push id30528
push usercbook@mozilla.com
push dateThu, 04 Aug 2016 13:58:28 +0000
treeherdermozilla-central@0ba72e8027cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1289375
milestone51.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 1289375 - Rollback incomplete change of preloading cursors for IndexedDB. r=khuey
dom/indexedDB/ActorsChild.cpp
dom/indexedDB/ActorsChild.h
dom/indexedDB/ActorsParent.cpp
dom/indexedDB/IDBCursor.cpp
dom/indexedDB/IDBCursor.h
dom/indexedDB/PBackgroundIDBCursor.ipdl
--- a/dom/indexedDB/ActorsChild.cpp
+++ b/dom/indexedDB/ActorsChild.cpp
@@ -2638,94 +2638,34 @@ void
 BackgroundCursorChild::AssertIsOnOwningThread() const
 {
   MOZ_ASSERT(mOwningThread == PR_GetCurrentThread());
 }
 
 #endif // DEBUG
 
 void
-BackgroundCursorChild::SendContinueInternal(const CursorRequestParams& aParams,
-                                            const Key& aKey)
+BackgroundCursorChild::SendContinueInternal(const CursorRequestParams& aParams)
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(mRequest);
   MOZ_ASSERT(mTransaction);
   MOZ_ASSERT(mCursor);
   MOZ_ASSERT(!mStrongRequest);
   MOZ_ASSERT(!mStrongCursor);
 
   // Make sure all our DOM objects stay alive.
   mStrongCursor = mCursor;
 
   MOZ_ASSERT(mRequest->ReadyState() == IDBRequestReadyState::Done);
   mRequest->Reset();
 
   mTransaction->OnNewRequest();
 
-  CursorRequestParams params = aParams;
-  Key key = aKey;
-
-  switch (params.type()) {
-    case CursorRequestParams::TContinueParams: {
-      if (key.IsUnset()) {
-        break;
-      }
-      while (!mCachedResponses.IsEmpty()) {
-        if (mCachedResponses[0].mKey == key) {
-          break;
-        }
-        mCachedResponses.RemoveElementAt(0);
-      }
-      break;
-    }
-
-    case CursorRequestParams::TAdvanceParams: {
-      uint32_t& advanceCount = params.get_AdvanceParams().count();
-      while (advanceCount > 1 && !mCachedResponses.IsEmpty()) {
-        key = mCachedResponses[0].mKey;
-        mCachedResponses.RemoveElementAt(0);
-        --advanceCount;
-      }
-      break;
-    }
-
-    default:
-      MOZ_CRASH("Should never get here!");
-  }
-
-  if (!mCachedResponses.IsEmpty()) {
-    nsCOMPtr<nsIRunnable> continueRunnable = new DelayedActionRunnable(
-      this, &BackgroundCursorChild::SendDelayedContinueInternal);
-    MOZ_ALWAYS_SUCCEEDS(NS_DispatchToCurrentThread(continueRunnable));
-  } else {
-    MOZ_ALWAYS_TRUE(PBackgroundIDBCursorChild::SendContinue(params, key));
-  }
-}
-
-void
-BackgroundCursorChild::SendDelayedContinueInternal()
-{
-  AssertIsOnOwningThread();
-  MOZ_ASSERT(mTransaction);
-  MOZ_ASSERT(mCursor);
-  MOZ_ASSERT(mStrongCursor);
-  MOZ_ASSERT(!mCachedResponses.IsEmpty());
-
-  RefPtr<IDBCursor> cursor;
-  mStrongCursor.swap(cursor);
-
-  auto& item = mCachedResponses[0];
-  mCursor->Reset(Move(item.mKey), Move(item.mCloneInfo));
-  mCachedResponses.RemoveElementAt(0);
-
-  ResultHelper helper(mRequest, mTransaction, mCursor);
-  DispatchSuccessEvent(&helper);
-
-  mTransaction->OnRequestFinished(/* aActorDestroyedNormally */ true);
+  MOZ_ALWAYS_TRUE(PBackgroundIDBCursorChild::SendContinue(aParams));
 }
 
 void
 BackgroundCursorChild::SendDeleteMeInternal()
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(!mStrongRequest);
   MOZ_ASSERT(!mStrongCursor);
@@ -2739,24 +2679,16 @@ BackgroundCursorChild::SendDeleteMeInter
     mCursor->ClearBackgroundActor();
     mCursor = nullptr;
 
     MOZ_ALWAYS_TRUE(PBackgroundIDBCursorChild::SendDeleteMe());
   }
 }
 
 void
-BackgroundCursorChild::InvalidateCachedResponses()
-{
-  AssertIsOnOwningThread();
-
-  mCachedResponses.Clear();
-}
-
-void
 BackgroundCursorChild::HandleResponse(nsresult aResponse)
 {
   AssertIsOnOwningThread();
   MOZ_ASSERT(NS_FAILED(aResponse));
   MOZ_ASSERT(NS_ERROR_GET_MODULE(aResponse) == NS_ERROR_MODULE_DOM_INDEXEDDB);
   MOZ_ASSERT(mRequest);
   MOZ_ASSERT(mTransaction);
   MOZ_ASSERT(!mStrongRequest);
@@ -2811,24 +2743,17 @@ BackgroundCursorChild::HandleResponse(
 
     ConvertActorsToBlobs(mTransaction->Database(),
                          response.cloneInfo(),
                          cloneReadInfo.mFiles);
 
     RefPtr<IDBCursor> newCursor;
 
     if (mCursor) {
-      if (mCursor->IsContinueCalled()) {
-        mCursor->Reset(Move(response.key()), Move(cloneReadInfo));
-      } else {
-        CachedResponse cachedResponse;
-        cachedResponse.mKey = Move(response.key());
-        cachedResponse.mCloneInfo = Move(cloneReadInfo);
-        mCachedResponses.AppendElement(Move(cachedResponse));
-      }
+      mCursor->Reset(Move(response.key()), Move(cloneReadInfo));
     } else {
       newCursor = IDBCursor::Create(this,
                                     Move(response.key()),
                                     Move(cloneReadInfo));
       mCursor = newCursor;
     }
   }
 
@@ -3041,26 +2966,16 @@ DelayedActionRunnable::Cancel()
   }
 
   // This must always run to clean up our state.
   Run();
 
   return NS_OK;
 }
 
-BackgroundCursorChild::CachedResponse::CachedResponse()
-{
-}
-
-BackgroundCursorChild::CachedResponse::CachedResponse(CachedResponse&& aOther)
-  : mKey(Move(aOther.mKey))
-{
-  mCloneInfo = Move(aOther.mCloneInfo);
-}
-
 /*******************************************************************************
  * BackgroundUtilsChild
  ******************************************************************************/
 
 BackgroundUtilsChild::BackgroundUtilsChild(IndexedDatabaseManager* aManager)
   : mManager(aManager)
 #ifdef DEBUG
   , mOwningThread(NS_GetCurrentThread())
--- a/dom/indexedDB/ActorsChild.h
+++ b/dom/indexedDB/ActorsChild.h
@@ -683,45 +683,32 @@ private:
 class BackgroundCursorChild final
   : public PBackgroundIDBCursorChild
 {
   friend class BackgroundTransactionChild;
   friend class BackgroundVersionChangeTransactionChild;
 
   class DelayedActionRunnable;
 
-  struct CachedResponse
-  {
-    CachedResponse();
-
-    CachedResponse(CachedResponse&& aOther);
-
-    Key mKey;
-    Key mObjectKey;
-    StructuredCloneReadInfo mCloneInfo;
-  };
-
   IDBRequest* mRequest;
   IDBTransaction* mTransaction;
   IDBObjectStore* mObjectStore;
   IDBIndex* mIndex;
   IDBCursor* mCursor;
 
   // These are only set while a request is in progress.
   RefPtr<IDBRequest> mStrongRequest;
   RefPtr<IDBCursor> mStrongCursor;
 
   Direction mDirection;
 
 #ifdef DEBUG
   PRThread* mOwningThread;
 #endif
 
-  nsTArray<CachedResponse> mCachedResponses;
-
 public:
   BackgroundCursorChild(IDBRequest* aRequest,
                         IDBObjectStore* aObjectStore,
                         Direction aDirection);
 
   BackgroundCursorChild(IDBRequest* aRequest,
                         IDBIndex* aIndex,
                         Direction aDirection);
@@ -730,24 +717,21 @@ public:
   AssertIsOnOwningThread() const
 #ifdef DEBUG
   ;
 #else
   { }
 #endif
 
   void
-  SendContinueInternal(const CursorRequestParams& aParams, const Key& aKey);
+  SendContinueInternal(const CursorRequestParams& aParams);
 
   void
   SendDeleteMeInternal();
 
-  void
-  InvalidateCachedResponses();
-
   IDBRequest*
   GetRequest() const
   {
     AssertIsOnOwningThread();
 
     return mRequest;
   }
 
@@ -776,19 +760,16 @@ public:
   }
 
 private:
   // Only destroyed by BackgroundTransactionChild or
   // BackgroundVersionChangeTransactionChild.
   ~BackgroundCursorChild();
 
   void
-  SendDelayedContinueInternal();
-
-  void
   HandleResponse(nsresult aResponse);
 
   void
   HandleResponse(const void_t& aResponse);
 
   void
   HandleResponse(const nsTArray<ObjectStoreCursorResponse>& aResponse);
 
@@ -805,17 +786,17 @@ private:
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) override;
 
   virtual bool
   RecvResponse(const CursorResponse& aResponse) override;
 
   // Force callers to use SendContinueInternal.
   bool
-  SendContinue(const CursorRequestParams& aParams, const Key& aKey) = delete;
+  SendContinue(const CursorRequestParams& aParams) = delete;
 
   bool
   SendDeleteMe() = delete;
 };
 
 class BackgroundUtilsChild final
   : public PBackgroundIndexedDBUtilsChild
 {
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -8478,17 +8478,17 @@ private:
   // IPDL methods.
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) override;
 
   virtual bool
   RecvDeleteMe() override;
 
   virtual bool
-  RecvContinue(const CursorRequestParams& aParams, const Key& key) override;
+  RecvContinue(const CursorRequestParams& aParams) override;
 
   bool
   IsLocaleAware() const {
     return !mLocale.IsEmpty();
   }
 };
 
 class Cursor::CursorOpBase
@@ -8573,26 +8573,23 @@ private:
 };
 
 class Cursor::ContinueOp final
   : public Cursor::CursorOpBase
 {
   friend class Cursor;
 
   const CursorRequestParams mParams;
-  const Key mKey;
 
 private:
   // Only created by Cursor.
   ContinueOp(Cursor* aCursor,
-             const CursorRequestParams& aParams,
-             const Key& aKey)
+             const CursorRequestParams& aParams)
     : CursorOpBase(aCursor)
     , mParams(aParams)
-    , mKey(aKey)
   {
     MOZ_ASSERT(aParams.type() != CursorRequestParams::T__None);
   }
 
   // Reference counted.
   ~ContinueOp()
   { }
 
@@ -16319,17 +16316,17 @@ Cursor::RecvDeleteMe()
     ASSERT_UNLESS_FUZZING();
     return false;
   }
 
   return PBackgroundIDBCursorParent::Send__delete__(this);
 }
 
 bool
-Cursor::RecvContinue(const CursorRequestParams& aParams, const Key& aKey)
+Cursor::RecvContinue(const CursorRequestParams& aParams)
 {
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(aParams.type() != CursorRequestParams::T__None);
   MOZ_ASSERT(!mActorDestroyed);
   MOZ_ASSERT(mObjectStoreMetadata);
   MOZ_ASSERT_IF(mType == OpenCursorParams::TIndexOpenCursorParams ||
                   mType == OpenCursorParams::TIndexOpenKeyCursorParams,
                 mIndexMetadata);
@@ -16353,17 +16350,17 @@ Cursor::RecvContinue(const CursorRequest
     return false;
   }
 
   if (NS_WARN_IF(mTransaction->mCommitOrAbortReceived)) {
     ASSERT_UNLESS_FUZZING();
     return false;
   }
 
-  RefPtr<ContinueOp> continueOp = new ContinueOp(this, aParams, aKey);
+  RefPtr<ContinueOp> continueOp = new ContinueOp(this, aParams);
   if (NS_WARN_IF(!continueOp->Init(mTransaction))) {
     continueOp->Cleanup();
     return false;
   }
 
   continueOp->DispatchToConnectionPool();
   mCurrentlyRunningOp = continueOp;
 
@@ -27838,33 +27835,16 @@ ContinueOp::DoDatabaseWork(DatabaseConne
     }
   }
 
   rv = PopulateResponseFromStatement(stmt, true);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  uint32_t extraCount = 1;
-  for (uint32_t i = 0; i < extraCount; i++) {
-    rv = stmt->ExecuteStep(&hasResult);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
-
-    if (!hasResult) {
-      break;
-    }
-
-    rv = PopulateResponseFromStatement(stmt, false);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
-  }
-
   return NS_OK;
 }
 
 nsresult
 Cursor::
 ContinueOp::SendSuccessResult()
 {
   AssertIsOnOwningThread();
--- a/dom/indexedDB/IDBCursor.cpp
+++ b/dom/indexedDB/IDBCursor.cpp
@@ -505,17 +505,17 @@ IDBCursor::Continue(JSContext* aCx,
                  IDB_LOG_STRINGIFY(mTransaction->Database()),
                  IDB_LOG_STRINGIFY(mTransaction),
                  IDB_LOG_STRINGIFY(mSourceIndex->ObjectStore()),
                  IDB_LOG_STRINGIFY(mSourceIndex),
                  IDB_LOG_STRINGIFY(mDirection),
                  IDB_LOG_STRINGIFY(key));
   }
 
-  mBackgroundActor->SendContinueInternal(ContinueParams(key), mKey);
+  mBackgroundActor->SendContinueInternal(ContinueParams(key));
 
   mContinueCalled = true;
 }
 
 void
 IDBCursor::Advance(uint32_t aCount, ErrorResult &aRv)
 {
   AssertIsOnOwningThread();
@@ -563,17 +563,17 @@ IDBCursor::Advance(uint32_t aCount, Erro
                  IDB_LOG_STRINGIFY(mTransaction->Database()),
                  IDB_LOG_STRINGIFY(mTransaction),
                  IDB_LOG_STRINGIFY(mSourceIndex->ObjectStore()),
                  IDB_LOG_STRINGIFY(mSourceIndex),
                  IDB_LOG_STRINGIFY(mDirection),
                  aCount);
   }
 
-  mBackgroundActor->SendContinueInternal(AdvanceParams(aCount), mKey);
+  mBackgroundActor->SendContinueInternal(AdvanceParams(aCount));
 
   mContinueCalled = true;
 }
 
 already_AddRefed<IDBRequest>
 IDBCursor::Update(JSContext* aCx, JS::Handle<JS::Value> aValue,
                   ErrorResult& aRv)
 {
@@ -598,18 +598,16 @@ IDBCursor::Update(JSContext* aCx, JS::Ha
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
   MOZ_ASSERT(mType == Type_ObjectStore || mType == Type_Index);
   MOZ_ASSERT(!mKey.IsUnset());
   MOZ_ASSERT_IF(mType == Type_Index, !mPrimaryKey.IsUnset());
 
-  mBackgroundActor->InvalidateCachedResponses();
-
   IDBObjectStore* objectStore;
   if (mType == Type_ObjectStore) {
     objectStore = mSourceObjectStore;
   } else {
     objectStore = mSourceIndex->ObjectStore();
   }
 
   MOZ_ASSERT(objectStore);
@@ -717,18 +715,16 @@ IDBCursor::Delete(JSContext* aCx, ErrorR
       mContinueCalled) {
     aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
   MOZ_ASSERT(mType == Type_ObjectStore || mType == Type_Index);
   MOZ_ASSERT(!mKey.IsUnset());
 
-  mBackgroundActor->InvalidateCachedResponses();
-
   IDBObjectStore* objectStore;
   if (mType == Type_ObjectStore) {
     objectStore = mSourceObjectStore;
   } else {
     objectStore = mSourceIndex->ObjectStore();
   }
 
   MOZ_ASSERT(objectStore);
--- a/dom/indexedDB/IDBCursor.h
+++ b/dom/indexedDB/IDBCursor.h
@@ -130,18 +130,16 @@ public:
   GetParentObject() const;
 
   void
   GetSource(OwningIDBObjectStoreOrIDBIndex& aSource) const;
 
   IDBCursorDirection
   GetDirection() const;
 
-  bool IsContinueCalled() const { return mContinueCalled; }
-
   void
   GetKey(JSContext* aCx,
          JS::MutableHandle<JS::Value> aResult,
          ErrorResult& aRv);
 
   void
   GetPrimaryKey(JSContext* aCx,
                 JS::MutableHandle<JS::Value> aResult,
--- a/dom/indexedDB/PBackgroundIDBCursor.ipdl
+++ b/dom/indexedDB/PBackgroundIDBCursor.ipdl
@@ -75,17 +75,17 @@ union CursorResponse
 
 protocol PBackgroundIDBCursor
 {
   manager PBackgroundIDBTransaction or PBackgroundIDBVersionChangeTransaction;
 
 parent:
   async DeleteMe();
 
-  async Continue(CursorRequestParams params, Key key);
+  async Continue(CursorRequestParams params);
 
 child:
   async __delete__();
 
   async Response(CursorResponse response);
 };
 
 } // namespace indexedDB