Bug 836493 - part 1: ensure that the initial reference to mozStorageService is obtained on the main thread; r=mak
authorNathan Froyd <froydnj@mozilla.com>
Fri, 08 Feb 2013 12:04:26 -0500
changeset 128373 5727d59ae2083b28abb660f12b790b63c9d0e113
parent 128372 138ea79ea71a0bc6d4ddecfca96cf7781d97e44b
child 128374 76913343f8a689c23d4336798ed04be80c9bcd3e
push id24528
push userryanvm@gmail.com
push dateThu, 11 Apr 2013 19:19:41 +0000
treeherdermozilla-central@7b8ed29c6bc0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs836493
milestone23.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 836493 - part 1: ensure that the initial reference to mozStorageService is obtained on the main thread; r=mak
storage/public/mozIStorageService.idl
storage/src/mozStorageService.cpp
storage/test/test_service_init_background_thread.cpp
--- a/storage/public/mozIStorageService.idl
+++ b/storage/public/mozIStorageService.idl
@@ -10,16 +10,19 @@ interface nsIFile;
 interface nsIFileURL;
 
 /**
  * The mozIStorageService interface is intended to be implemented by
  * a service that can create storage connections (mozIStorageConnection)
  * to either a well-known profile database or to a specific database file.
  *
  * This is the only way to open a database connection.
+ *
+ * @note The first reference to mozIStorageService must be made on the main
+ * thread.
  */
 [scriptable, uuid(12bfad34-cca3-40fb-8736-d8bf9db61a27)]
 interface mozIStorageService : nsISupports {
   /**
    * Get a connection to a named special database storage.
    *
    * @param aStorageKey a string key identifying the type of storage
    * requested.  Valid values include: "profile", "memory".
--- a/storage/src/mozStorageService.cpp
+++ b/storage/src/mozStorageService.cpp
@@ -337,16 +337,19 @@ Service::getSingleton()
       message.AppendASCII("The application has been updated, but your version "
                           "of SQLite is too old and the application cannot "
                           "run.");
       (void)ps->Alert(nullptr, title.get(), message.get());
     }
     ::PR_Abort();
   }
 
+  // The first reference to the storage service must be obtained on the
+  // main thread.
+  NS_ENSURE_TRUE(NS_IsMainThread(), nullptr);
   gService = new Service();
   if (gService) {
     NS_ADDREF(gService);
     if (NS_FAILED(gService->initialize()))
       NS_RELEASE(gService);
   }
 
   return gService;
--- a/storage/test/test_service_init_background_thread.cpp
+++ b/storage/test/test_service_init_background_thread.cpp
@@ -16,18 +16,20 @@
 ////////////////////////////////////////////////////////////////////////////////
 //// Helpers
 
 class ServiceInitializer : public nsRunnable
 {
 public:
   NS_IMETHOD Run()
   {
-    nsCOMPtr<mozIStorageService> service = getService();
-    do_check_true(service);
+    // Use an explicit do_GetService instead of getService so that the check in
+    // getService doesn't blow up.
+    nsCOMPtr<mozIStorageService> service = do_GetService("@mozilla.org/storage/service;1");
+    do_check_false(service);
     return NS_OK;
   }
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Test Functions
 
 void