Bug 992512 - Back patch v2 out, r=me
authorHonza Bambas <honzab.moz@firemni.cz>
Sat, 26 Apr 2014 21:55:20 +0200
changeset 180779 85e868943b6110a790aaf9141f066ff880251a81
parent 180778 a632ecfff394352044444b1f4a0b06e07946e654
child 180780 565704a273f5a59dec8039824d51104f467bcbd5
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersme
bugs992512
milestone31.0a1
Bug 992512 - Back patch v2 out, r=me
dom/src/storage/DOMStorageCache.cpp
dom/src/storage/DOMStorageCache.h
--- a/dom/src/storage/DOMStorageCache.cpp
+++ b/dom/src/storage/DOMStorageCache.cpp
@@ -18,17 +18,16 @@
 
 namespace mozilla {
 namespace dom {
 
 #define DOM_STORAGE_CACHE_KEEP_ALIVE_TIME_MS 20000
 
 // static
 DOMStorageDBBridge* DOMStorageCache::sDatabase = nullptr;
-bool DOMStorageCache::sDatabaseDown = false;
 
 namespace { // anon
 
 const uint32_t kDefaultSet = 0;
 const uint32_t kPrivateSet = 1;
 const uint32_t kSessionSet = 2;
 
 inline uint32_t
@@ -145,28 +144,16 @@ DOMStorageCache::Init(DOMStorageManager*
 inline bool
 DOMStorageCache::Persist(const DOMStorage* aStorage) const
 {
   return mPersistent &&
          !aStorage->IsSessionOnly() &&
          !aStorage->IsPrivate();
 }
 
-inline bool
-DOMStorageCache::PersistAndDatabaseUp(const DOMStorage* aStorage) const
-{
-  bool persist = Persist(aStorage);
-
-  MOZ_ASSERT(!persist || sDatabase,
-             "Writing to localStorage after the database has been shut down"
-             ", data lose!");
-
-  return persist && sDatabase;
-}
-
 namespace { // anon
 
 PLDHashOperator
 CloneSetData(const nsAString& aKey, const nsString aValue, void* aArg)
 {
   DOMStorageCache::Data* target = static_cast<DOMStorageCache::Data*>(aArg);
   target->mKeys.Put(aKey, aValue);
 
@@ -503,17 +490,17 @@ DOMStorageCache::SetItem(const DOMStorag
   }
 
   if (aValue == aOld && DOMStringIsNull(aValue) == DOMStringIsNull(aOld)) {
     return NS_SUCCESS_DOM_NO_OPERATION;
   }
 
   data.mKeys.Put(aKey, aValue);
 
-  if (PersistAndDatabaseUp(aStorage)) {
+  if (Persist(aStorage)) {
     if (DOMStringIsNull(aOld)) {
       return sDatabase->AsyncAddItem(this, aKey, aValue);
     }
 
     return sDatabase->AsyncUpdateItem(this, aKey, aValue);
   }
 
   return NS_OK;
@@ -538,17 +525,17 @@ DOMStorageCache::RemoveItem(const DOMSto
     return NS_SUCCESS_DOM_NO_OPERATION;
   }
 
   // Recalculate the cached data size
   const int64_t delta = -(static_cast<int64_t>(aOld.Length()));
   unused << ProcessUsageDelta(aStorage, delta);
   data.mKeys.Remove(aKey);
 
-  if (PersistAndDatabaseUp(aStorage)) {
+  if (Persist(aStorage)) {
     return sDatabase->AsyncRemoveItem(this, aKey);
   }
 
   return NS_OK;
 }
 
 nsresult
 DOMStorageCache::Clear(const DOMStorage* aStorage)
@@ -574,17 +561,17 @@ DOMStorageCache::Clear(const DOMStorage*
   Data& data = DataSet(aStorage);
   bool hadData = !!data.mKeys.Count();
 
   if (hadData) {
     unused << ProcessUsageDelta(aStorage, -data.mOriginQuotaUsage);
     data.mKeys.Clear();
   }
 
-  if (PersistAndDatabaseUp(aStorage) && (refresh || hadData)) {
+  if (Persist(aStorage) && (refresh || hadData)) {
     return sDatabase->AsyncClear(this);
   }
 
   return hadData ? NS_OK : NS_SUCCESS_DOM_NO_OPERATION;
 }
 
 void
 DOMStorageCache::CloneFrom(const DOMStorageCache* aThat)
@@ -753,20 +740,17 @@ DOMStorageUsage::CheckAndSetETLD1UsageDe
   return true;
 }
 
 
 // static
 DOMStorageDBBridge*
 DOMStorageCache::StartDatabase()
 {
-  if (sDatabase || sDatabaseDown) {
-    // When sDatabaseDown is at true, sDatabase is null.
-    // Checking sDatabaseDown flag here prevents reinitialization of
-    // the database after shutdown.
+  if (sDatabase) {
     return sDatabase;
   }
 
   if (XRE_GetProcessType() == GeckoProcessType_Default) {
     nsAutoPtr<DOMStorageDBThread> db(new DOMStorageDBThread());
 
     nsresult rv = db->Init();
     if (NS_FAILED(rv)) {
@@ -799,18 +783,16 @@ DOMStorageCache::GetDatabase()
 // static
 nsresult
 DOMStorageCache::StopDatabase()
 {
   if (!sDatabase) {
     return NS_OK;
   }
 
-  sDatabaseDown = true;
-
   nsresult rv = sDatabase->Shutdown();
   if (XRE_GetProcessType() == GeckoProcessType_Default) {
     delete sDatabase;
   } else {
     DOMStorageDBChild* child = static_cast<DOMStorageDBChild*>(sDatabase);
     NS_RELEASE(child);
   }
 
--- a/dom/src/storage/DOMStorageCache.h
+++ b/dom/src/storage/DOMStorageCache.h
@@ -154,23 +154,16 @@ private:
   void WaitForPreload(mozilla::Telemetry::ID aTelemetryID);
 
   // Helper to get one of the 3 data sets (regular, private, session)
   Data& DataSet(const DOMStorage* aStorage);
 
   // Whether the storage change is about to persist
   bool Persist(const DOMStorage* aStorage) const;
 
-  // Whether the storage change is about to persist and also the database
-  // is still up.  No need to use the database-is-up check before
-  // WaitForPreload() calls that also dereferences sDatabase since preload
-  // is either done before we've shut the DB down or when the DB could not
-  // start, preload has not even be started.
-  bool PersistAndDatabaseUp(const DOMStorage* aStorage) const;
-
   // Changes the quota usage on the given data set if it fits the quota.
   // If not, then false is returned and no change to the set must be done.
   bool ProcessUsageDelta(uint32_t aGetDataSetIndex, const int64_t aDelta);
   bool ProcessUsageDelta(const DOMStorage* aStorage, const int64_t aDelta);
 
 private:
   // When a cache is reponsible for its life time (in case of localStorage data
   // cache) we need to refer our manager since removal of the cache from the hash
@@ -227,19 +220,16 @@ private:
   bool mSessionOnlyDataSetActive : 1;
 
   // Whether we have already captured state of the cache preload on our first access.
   bool mPreloadTelemetryRecorded : 1;
 
   // DOMStorageDBThread on the parent or single process,
   // DOMStorageDBChild on the child process.
   static DOMStorageDBBridge* sDatabase;
-
-  // False until we shut the database down.
-  static bool sDatabaseDown;
 };
 
 // DOMStorageUsage
 // Infrastructure to manage and check eTLD+1 quota
 class DOMStorageUsageBridge
 {
 public:
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DOMStorageUsageBridge)