diff --git a/dom/storage/DOMStorageCache.cpp b/dom/storage/DOMStorageCache.cpp index c2f049569b2..4c84ac0dcbb 100644 --- a/dom/storage/DOMStorageCache.cpp +++ b/dom/storage/DOMStorageCache.cpp @@ -564,9 +564,16 @@ DOMStorageCache::Clear(const DOMStorage* aStorage) void DOMStorageCache::CloneFrom(const DOMStorageCache* aThat) { - mLoaded = aThat->mLoaded; + // This will never be called on anything else than SessionStorage. + // This means mData will never be touched on any other thread than + // the main thread and it never went through the loading process. + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(!mPersistent); + MOZ_ASSERT(!(bool)aThat->mLoaded); + + mLoaded = false; mInitialized = aThat->mInitialized; - mPersistent = aThat->mPersistent; + mPersistent = false; mSessionOnlyDataSetActive = aThat->mSessionOnlyDataSetActive; for (uint32_t i = 0; i < kDataSetCount; ++i) { diff --git a/dom/storage/DOMStorageCache.h b/dom/storage/DOMStorageCache.h index 3ee3ce1e5c7..2bd4737f45b 100644 --- a/dom/storage/DOMStorageCache.h +++ b/dom/storage/DOMStorageCache.h @@ -15,6 +15,7 @@ #include "nsHashKeys.h" #include "mozilla/Monitor.h" #include "mozilla/Telemetry.h" +#include "mozilla/Atomics.h" #include "nsAutoPtr.h" namespace mozilla { @@ -220,8 +221,9 @@ private: // Flag that is initially false. When the cache is about to work with // the database (i.e. it is persistent) this flags is set to true after // all keys and coresponding values are loaded from the database. - // This flag never goes from true back to false. - bool mLoaded; + // This flag never goes from true back to false. Since this flag is + // critical for mData hashtable synchronization, it's made atomic. + Atomic mLoaded; // Result of load from the database. Valid after mLoaded flag has been set. nsresult mLoadResult;