Bug 910808 - Remove call to retrieve preference while not on the main thread. r=khuey
authorDave Hylands <dhylands@mozilla.com>
Tue, 03 Sep 2013 16:10:38 -0700
changeset 146081 667cca91930339524d1440261687af2a8c1b8db3
parent 145994 d3c0933d379d3a19dffa3d55c65b970544870c3a
child 146082 a67532a34e35d9d9edab54db9b0f760a94c1fb5f
push id25239
push userphilringnalda@gmail.com
push dateSun, 08 Sep 2013 15:34:22 +0000
treeherdermozilla-central@c7cc85e13f7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs910808
milestone26.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 910808 - Remove call to retrieve preference while not on the main thread. r=khuey
dom/devicestorage/nsDeviceStorage.cpp
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -69,17 +69,17 @@ using namespace mozilla::dom::devicestor
 
 #include "nsDirectoryServiceDefs.h"
 
 StaticAutoPtr<DeviceStorageUsedSpaceCache>
   DeviceStorageUsedSpaceCache::sDeviceStorageUsedSpaceCache;
 
 DeviceStorageUsedSpaceCache::DeviceStorageUsedSpaceCache()
 {
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
 
   mIOThread = new LazyIdleThread(
     DEFAULT_THREAD_TIMEOUT_MS,
     NS_LITERAL_CSTRING("DeviceStorageUsedSpaceCache I/O"));
 
 }
 
 DeviceStorageUsedSpaceCache::~DeviceStorageUsedSpaceCache()
@@ -88,17 +88,17 @@ DeviceStorageUsedSpaceCache::~DeviceStor
 
 DeviceStorageUsedSpaceCache*
 DeviceStorageUsedSpaceCache::CreateOrGet()
 {
   if (sDeviceStorageUsedSpaceCache) {
     return sDeviceStorageUsedSpaceCache;
   }
 
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
 
   sDeviceStorageUsedSpaceCache = new DeviceStorageUsedSpaceCache();
   ClearOnShutdown(&sDeviceStorageUsedSpaceCache);
   return sDeviceStorageUsedSpaceCache;
 }
 
 TemporaryRef<DeviceStorageUsedSpaceCache::CacheEntry>
 DeviceStorageUsedSpaceCache::GetCacheEntry(const nsAString& aStorageName)
@@ -203,18 +203,17 @@ DeviceStorageTypeChecker::~DeviceStorage
 
 DeviceStorageTypeChecker*
 DeviceStorageTypeChecker::CreateOrGet()
 {
   if (sDeviceStorageTypeChecker) {
     return sDeviceStorageTypeChecker;
   }
 
-  NS_ASSERTION(NS_IsMainThread(),
-               "This can only be created on the main thread!");
+  MOZ_ASSERT(NS_IsMainThread());
 
   nsCOMPtr<nsIStringBundleService> stringService
     = mozilla::services::GetStringBundleService();
   if (!stringService) {
     return nullptr;
   }
 
   nsCOMPtr<nsIStringBundle> filterBundle;
@@ -468,17 +467,17 @@ public:
     , mType(aType)
   {
   }
 
   ~IOEventComplete() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(NS_IsMainThread());
     nsString data;
     CopyASCIItoUTF16(mType, data);
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
 
     obs->NotifyObservers(mFile, "file-watcher-notify", data.get());
 
     DeviceStorageUsedSpaceCache* usedSpaceCache
       = DeviceStorageUsedSpaceCache::CreateOrGet();
@@ -580,17 +579,17 @@ DeviceStorageFile::Init()
 // here. Directories which depend on the root directory of a volume
 // should be calculated in DeviceStorageFile::GetRootDirectoryForType.
 static void
 InitDirs()
 {
   if (sDirs) {
     return;
   }
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
   sDirs = new GlobalDirs;
   ClearOnShutdown(&sDirs);
 
   nsCOMPtr<nsIProperties> dirService
     = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
   NS_ASSERTION(dirService, "Must have directory service");
 
 #if !defined(MOZ_WIDGET_GONK)
@@ -760,17 +759,17 @@ DeviceStorageFile::GetRootDirectoryForTy
   }
 
   // crash reports directory.
   else if (aStorageType.EqualsLiteral(DEVICESTORAGE_CRASHES)) {
     f = sDirs->crashes;
   }
 
   // in testing, we default all device storage types to a temp directory
-  if (f && mozilla::Preferences::GetBool("device.storage.testing", false)) {
+  if (f && sDirs->temp) {
     f = sDirs->temp;
   }
 
   if (f) {
     f->Clone(aFile);
   }
 }
 
@@ -993,17 +992,17 @@ DeviceStorageFile::Write(InfallibleTArra
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 nsresult
 DeviceStorageFile::Remove()
 {
-  NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(!NS_IsMainThread());
 
   if (!mFile) {
     return NS_ERROR_FAILURE;
   }
 
   bool check;
   nsresult rv = mFile->Exists(&check);
   if (NS_FAILED(rv)) {
@@ -1022,17 +1021,17 @@ DeviceStorageFile::Remove()
   nsCOMPtr<IOEventComplete> iocomplete = new IOEventComplete(this, "deleted");
   NS_DispatchToMainThread(iocomplete);
   return NS_OK;
 }
 
 nsresult
 DeviceStorageFile::CalculateMimeType()
 {
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
 
   nsAutoCString mimeType;
   nsCOMPtr<nsIMIMEService> mimeService =
     do_GetService(NS_MIMESERVICE_CONTRACTID);
   if (mimeService) {
     nsresult rv = mimeService->GetTypeFromFile(mFile, mimeType);
     if (NS_FAILED(rv)) {
       mimeType.Truncate();
@@ -1042,17 +1041,17 @@ DeviceStorageFile::CalculateMimeType()
 
   mMimeType = NS_ConvertUTF8toUTF16(mimeType);
   return NS_OK;
 }
 
 nsresult
 DeviceStorageFile::CalculateSizeAndModifiedDate()
 {
-  NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(!NS_IsMainThread());
 
   int64_t fileSize;
   nsresult rv = mFile->GetFileSize(&fileSize);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mLength = fileSize;
 
   PRTime modDate;
@@ -1338,16 +1337,18 @@ UnregisterForSDCardChanges(nsIObserver* 
   obs->RemoveObserver(aObserver, NS_VOLUME_STATE_CHANGED);
 #endif
 }
 
 void
 nsDOMDeviceStorage::SetRootDirectoryForType(const nsAString& aStorageType,
                                             const nsAString& aStorageName)
 {
+  MOZ_ASSERT(NS_IsMainThread());
+
   nsCOMPtr<nsIFile> f;
   DeviceStorageFile::GetRootDirectoryForType(aStorageType,
                                              aStorageName,
                                              getter_AddRefs(f));
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   obs->AddObserver(this, "file-watcher-update", false);
   obs->AddObserver(this, "disk-space-watcher", false);
   mRootDirectory = f;
@@ -1382,17 +1383,17 @@ InterfaceToJsval(nsPIDOMWindow* aWindow,
   }
 
   return someJsVal;
 }
 
 JS::Value
 nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile)
 {
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
   NS_ASSERTION(aWindow, "Null Window");
 
   if (!aFile) {
     return JSVAL_NULL;
   }
 
   if (aFile->mEditable) {
     // TODO - needs janv's file handle support.
@@ -1412,17 +1413,17 @@ nsIFileToJsval(nsPIDOMWindow* aWindow, D
   nsCOMPtr<nsIDOMBlob> blob = new nsDOMFileFile(fullPath, aFile->mMimeType,
                                                 aFile->mLength, aFile->mFile,
                                                 aFile->mLastModifiedDate);
   return InterfaceToJsval(aWindow, blob, &NS_GET_IID(nsIDOMBlob));
 }
 
 JS::Value StringToJsval(nsPIDOMWindow* aWindow, nsAString& aString)
 {
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
   NS_ASSERTION(aWindow, "Null Window");
 
   nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aWindow);
   if (!sgo) {
     return JSVAL_NULL;
   }
 
   nsIScriptContext *scriptContext = sgo->GetScriptContext();
@@ -1505,17 +1506,17 @@ public:
   {
     CopyASCIItoUTF16(aMessage, mError);
   }
 
   ~PostErrorEvent() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(NS_IsMainThread());
     mRequest->FireError(mError);
     mRequest = nullptr;
     return NS_OK;
   }
 
 private:
   nsRefPtr<DOMRequest> mRequest;
   nsString mError;
@@ -1529,17 +1530,17 @@ ContinueCursorEvent::ContinueCursorEvent
 ContinueCursorEvent::ContinueCursorEvent(DOMRequest* aRequest)
   : mRequest(aRequest)
 {
 }
 
 already_AddRefed<DeviceStorageFile>
 ContinueCursorEvent::GetNextFile()
 {
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
 
   nsDOMDeviceStorageCursor* cursor
     = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
   nsString cursorStorageType;
   cursor->GetStorageType(cursorStorageType);
 
   DeviceStorageTypeChecker* typeChecker
     = DeviceStorageTypeChecker::CreateOrGet();
@@ -1624,17 +1625,17 @@ public:
     : mFile(aFile)
     , mRequest(aRequest)
   {
   }
 
   ~InitCursorEvent() {}
 
   NS_IMETHOD Run() {
-    NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(!NS_IsMainThread());
 
     if (mFile->mFile) {
       bool check;
       mFile->mFile->IsDirectory(&check);
       if (!check) {
         nsCOMPtr<PostErrorEvent> event =
           new PostErrorEvent(mRequest.forget(),
                              POST_ERROR_EVENT_FILE_NOT_ENUMERABLE);
@@ -1818,17 +1819,17 @@ public:
     , mRequest(aRequest)
   {
   }
 
   ~PostAvailableResultEvent() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(NS_IsMainThread());
 
     nsString state = NS_LITERAL_STRING("unavailable");
     if (mFile) {
       mFile->GetStatus(state);
     }
 
     AutoJSContext cx;
     JS::Rooted<JS::Value> result(cx,
@@ -1863,17 +1864,17 @@ public:
     : mValue(aValue)
     , mRequest(aRequest)
   {}
 
   ~PostResultEvent() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(NS_IsMainThread());
 
     AutoJSContext cx;
     JS::Rooted<JS::Value> result(cx, JSVAL_NULL);
     nsPIDOMWindow* window = mRequest->GetOwner();
 
     if (mFile) {
       result = nsIFileToJsval(window, mFile);
     } else if (mPath.Length()) {
@@ -1905,17 +1906,17 @@ public:
     , mFile(aFile)
     , mRequest(aRequest)
   {}
 
   ~WriteFileEvent() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(!NS_IsMainThread());
 
     nsCOMPtr<nsIInputStream> stream;
     mBlob->GetInternalStream(getter_AddRefs(stream));
 
     bool check = false;
     mFile->mFile->Exists(&check);
     if (check) {
       nsCOMPtr<PostErrorEvent> event =
@@ -1959,17 +1960,17 @@ public:
   {
     mFile->CalculateMimeType();
   }
 
   ~ReadFileEvent() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(!NS_IsMainThread());
 
     nsRefPtr<nsRunnable> r;
     if (!mFile->mEditable) {
       bool check = false;
       mFile->mFile->Exists(&check);
       if (!check) {
         r = new PostErrorEvent(mRequest.forget(),
                                POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
@@ -2003,17 +2004,17 @@ public:
     : mFile(aFile)
     , mRequest(aRequest)
   {}
 
   ~DeleteFileEvent() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(!NS_IsMainThread());
     mFile->Remove();
 
     nsRefPtr<nsRunnable> r;
     bool check = false;
     mFile->mFile->Exists(&check);
     if (check) {
       r = new PostErrorEvent(mRequest.forget(),
                              POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
@@ -2040,17 +2041,17 @@ public:
     : mFile(aFile)
     , mRequest(aRequest)
   {}
 
   ~UsedSpaceFileEvent() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(!NS_IsMainThread());
 
     uint64_t picturesUsage = 0, videosUsage = 0, musicUsage = 0, totalUsage = 0;
     mFile->AccumDiskUsage(&picturesUsage, &videosUsage,
                           &musicUsage, &totalUsage);
     nsCOMPtr<nsIRunnable> r;
     if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_PICTURES)) {
       r = new PostResultEvent(mRequest.forget(), picturesUsage);
     }
@@ -2079,17 +2080,17 @@ public:
     : mFile(aFile)
     , mRequest(aRequest)
   {}
 
   ~FreeSpaceFileEvent() {}
 
   NS_IMETHOD Run()
   {
-    NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
+    MOZ_ASSERT(!NS_IsMainThread());
 
     int64_t freeSpace = 0;
     if (mFile) {
       mFile->GetDiskFreeSpace(&freeSpace);
     }
 
     nsCOMPtr<nsIRunnable> r;
     r = new PostResultEvent(mRequest.forget(),
@@ -2137,16 +2138,17 @@ public:
       , mRequest(aRequest)
       , mBlob(aBlob) {}
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DeviceStorageRequest,
                                            nsIContentPermissionRequest)
 
   NS_IMETHOD Run() {
+    MOZ_ASSERT(NS_IsMainThread());
 
     if (mozilla::Preferences::GetBool("device.storage.prompt.testing", false)) {
       Allow();
       return NS_OK;
     }
 
     if (XRE_GetProcessType() == GeckoProcessType_Content) {
 
@@ -2543,17 +2545,17 @@ nsDOMDeviceStorage::Init(nsPIDOMWindow* 
 
 nsDOMDeviceStorage::~nsDOMDeviceStorage()
 {
 }
 
 void
 nsDOMDeviceStorage::Shutdown()
 {
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
 
   if (!mStorageName.IsEmpty()) {
     UnregisterForSDCardChanges(this);
   }
 
   nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   obs->RemoveObserver(this, "file-watcher-update");
   obs->RemoveObserver(this, "disk-space-watcher");
@@ -3134,16 +3136,18 @@ nsDOMDeviceStorage::EnumerateEditable(co
 }
 
 
 already_AddRefed<DOMCursor>
 nsDOMDeviceStorage::EnumerateInternal(const nsAString& aPath,
                                       const EnumerationParameters& aOptions,
                                       bool aEditable, ErrorResult& aRv)
 {
+  MOZ_ASSERT(NS_IsMainThread());
+
   nsCOMPtr<nsPIDOMWindow> win = GetOwner();
   if (!win) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
     return nullptr;
   }
 
   PRTime since = 0;
   if (aOptions.mSince.WasPassed() && !aOptions.mSince.Value().IsUndefined()) {
@@ -3229,17 +3233,17 @@ nsDOMDeviceStorage::DispatchMountChangeE
 }
 #endif
 
 NS_IMETHODIMP
 nsDOMDeviceStorage::Observe(nsISupports *aSubject,
                             const char *aTopic,
                             const PRUnichar *aData)
 {
-  NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
+  MOZ_ASSERT(NS_IsMainThread());
 
   if (!strcmp(aTopic, "file-watcher-update")) {
 
     DeviceStorageFile* file = static_cast<DeviceStorageFile*>(aSubject);
     Notify(NS_ConvertUTF16toUTF8(aData).get(), file);
     return NS_OK;
   }
   if (!strcmp(aTopic, "disk-space-watcher")) {