Bug 1264489 - Pre: assert DB access is on background thread in debug builds r=mcomella
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 07 Jun 2016 08:57:19 -0700
changeset 301238 61442f7ad442445cf5492949fb8771176e12cc50
parent 301237 ded915ec401f6690c95486a68ac2546806aa3227
child 301239 97074800423c429ca7ae01ca5db8c2e61b0fee17
push id78263
push usercbook@mozilla.com
push dateThu, 09 Jun 2016 10:13:31 +0000
treeherdermozilla-inbound@3d132a280ca0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1264489
milestone50.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 1264489 - Pre: assert DB access is on background thread in debug builds r=mcomella It's possible there are more UI-thread DB accesses lurking. To avoid maintenance burden we should therefore enable this assert only in debug builds - releases will be unaffected, but we can still notice incorrect DB access during development. MozReview-Commit-ID: Kgzf1L3WjIE
mobile/android/base/java/org/mozilla/gecko/db/AbstractPerProfileDatabaseProvider.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/AbstractPerProfileDatabaseProvider.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/AbstractPerProfileDatabaseProvider.java
@@ -1,15 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.db;
 
+import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.annotation.RobocopTarget;
+import org.mozilla.gecko.util.ThreadUtils;
 
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.net.Uri;
 
 /**
  * The base class for ContentProviders that wish to use a different DB
  * for each profile.
@@ -30,16 +32,20 @@ public abstract class AbstractPerProfile
      * passed URI. If the URI does not contain a profile param, the default profile
      * is used.
      *
      * @param uri content URI optionally indicating the profile of the user
      * @return    instance of a readable SQLiteDatabase
      */
     @Override
     protected SQLiteDatabase getReadableDatabase(Uri uri) {
+        if (!AppConstants.MOZILLA_OFFICIAL) {
+            ThreadUtils.assertNotOnUiThread();
+        }
+
         String profile = null;
         if (uri != null) {
             profile = uri.getQueryParameter(BrowserContract.PARAM_PROFILE);
         }
 
         return getDatabases().getDatabaseHelperForProfile(profile, isTest(uri)).getReadableDatabase();
     }
 
@@ -48,16 +54,20 @@ public abstract class AbstractPerProfile
      * passed URI. If the URI does not contain a profile param, the default profile
      * is used
      *
      * @param uri content URI optionally indicating the profile of the user
      * @return    instance of a writable SQLiteDatabase
      */
     @Override
     protected SQLiteDatabase getWritableDatabase(Uri uri) {
+        if (!AppConstants.MOZILLA_OFFICIAL) {
+            ThreadUtils.assertNotOnUiThread();
+        }
+
         String profile = null;
         if (uri != null) {
             profile = uri.getQueryParameter(BrowserContract.PARAM_PROFILE);
         }
 
         return getDatabases().getDatabaseHelperForProfile(profile, isTest(uri)).getWritableDatabase();
     }