Bug 1362231 - Remove GeckoInterface.getProfile; r=snorp
authorJim Chen <nchen@mozilla.com>
Mon, 15 May 2017 23:11:10 -0400
changeset 406666 c399da282963b7c78338935b00edd14ddb639195
parent 406665 dc96471117ab6243119c8593b5f562e413036f81
child 406667 d15e744f0008d62ce04fa776caebe429a88bf743
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1362231
milestone55.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 1362231 - Remove GeckoInterface.getProfile; r=snorp Since we only support one profile per process, replace all calls to GeckoInterface.getProfile() with calls to GeckoThread.getActiveProfile(). MozReview-Commit-ID: 9PZOoBZt7Er
mobile/android/base/java/org/mozilla/gecko/ANRReporter.java
mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
mobile/android/base/java/org/mozilla/gecko/restrictions/Restrictions.java
mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingDelegate.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testGeckoProfile.java
--- a/mobile/android/base/java/org/mozilla/gecko/ANRReporter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/ANRReporter.java
@@ -186,20 +186,17 @@ public final class ANRReporter extends B
             Log.w(LOGTAG, e);
         } catch (ClassCastException e) {
             Log.w(LOGTAG, e); // Bug 975436
         }
         return null;
     }
 
     private static File getPingFile() {
-        if (GeckoAppShell.getContext() == null) {
-            return null;
-        }
-        GeckoProfile profile = GeckoAppShell.getGeckoInterface().getProfile();
+        final GeckoProfile profile = GeckoThread.getActiveProfile();
         if (profile == null) {
             return null;
         }
         File profDir = profile.getDir();
         if (profDir == null) {
             return null;
         }
         File pingDir = new File(profDir, "saved-telemetry-pings");
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
@@ -2011,18 +2011,17 @@ public abstract class GeckoApp extends G
     public @NonNull EventDispatcher getAppEventDispatcher() {
         if (mLayerView == null) {
             throw new IllegalStateException("Must not call getAppEventDispatcher() until after onCreate()");
         }
 
         return mLayerView.getEventDispatcher();
     }
 
-    @Override
-    public GeckoProfile getProfile() {
+    protected static GeckoProfile getProfile() {
         return GeckoThread.getActiveProfile();
     }
 
     /**
      * Check whether we've crashed during the last browsing session.
      *
      * @return True if the crash reporter ran after the last session.
      */
--- a/mobile/android/base/java/org/mozilla/gecko/restrictions/Restrictions.java
+++ b/mobile/android/base/java/org/mozilla/gecko/restrictions/Restrictions.java
@@ -45,21 +45,16 @@ public class Restrictions {
         }
     }
 
     private static boolean isGuestProfile(Context context) {
         if (configuration != null) {
             return configuration instanceof GuestProfileConfiguration;
         }
 
-        GeckoAppShell.GeckoInterface geckoInterface = GeckoAppShell.getGeckoInterface();
-        if (geckoInterface != null) {
-            return geckoInterface.getProfile().inGuestMode();
-        }
-
         return GeckoProfile.get(context).inGuestMode();
     }
 
     @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
     public static boolean isRestrictedProfile(Context context) {
         if (configuration != null) {
             return configuration instanceof RestrictedProfileConfiguration;
         }
--- a/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/telemetry/TelemetryCorePingDelegate.java
@@ -10,16 +10,17 @@ import android.content.Context;
 import android.content.SharedPreferences;
 import android.support.annotation.Nullable;
 import android.support.annotation.WorkerThread;
 import android.util.Log;
 import org.mozilla.gecko.BrowserApp;
 import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.GeckoSharedPrefs;
+import org.mozilla.gecko.GeckoThread;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.adjust.AttributionHelperListener;
 import org.mozilla.gecko.telemetry.measurements.CampaignIdMeasurements;
 import org.mozilla.gecko.delegates.BrowserAppDelegateWithReference;
 import org.mozilla.gecko.distribution.DistributionStoreCallback;
 import org.mozilla.gecko.search.SearchEngineManager;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
@@ -40,17 +41,17 @@ public class TelemetryCorePingDelegate e
             "Gecko" + TelemetryCorePingDelegate.class.getSimpleName(), 0, 23);
 
     private boolean isOnResumeCalled = false;
     private TelemetryDispatcher telemetryDispatcher; // lazy
     private final SessionMeasurements sessionMeasurements = new SessionMeasurements();
 
     @Override
     public void onStart(final BrowserApp browserApp) {
-        TelemetryPreferences.initPreferenceObserver(browserApp, browserApp.getProfile().getName());
+        TelemetryPreferences.initPreferenceObserver(browserApp, GeckoThread.getActiveProfile().getName());
 
         // We don't upload in onCreate because that's only called when the Activity needs to be instantiated
         // and it's possible the system will never free the Activity from memory.
         //
         // We don't upload in onResume/onPause because that will be called each time the Activity is obscured,
         // including by our own Activities/dialogs, and there is no reason to upload each time we're unobscured.
         //
         // We're left with onStart/onStop and we upload in onStart because onStop is not guaranteed to be called
@@ -99,26 +100,26 @@ public class TelemetryCorePingDelegate e
         // onStart/onStop is ideal over onResume/onPause. However, onStop is not guaranteed to be called and
         // dealing with that possibility adds a lot of complexity that we don't want to handle at this point.
         sessionMeasurements.recordSessionEnd(browserApp);
     }
 
     @WorkerThread // via constructor
     private TelemetryDispatcher getTelemetryDispatcher(final BrowserApp browserApp) {
         if (telemetryDispatcher == null) {
-            final GeckoProfile profile = browserApp.getProfile();
+            final GeckoProfile profile = GeckoThread.getActiveProfile();
             final String profilePath = profile.getDir().getAbsolutePath();
             final String profileName = profile.getName();
             telemetryDispatcher = new TelemetryDispatcher(profilePath, profileName);
         }
         return telemetryDispatcher;
     }
 
     private SharedPreferences getSharedPreferences(final BrowserApp activity) {
-        return GeckoSharedPrefs.forProfileName(activity, activity.getProfile().getName());
+        return GeckoSharedPrefs.forProfileName(activity, GeckoThread.getActiveProfile().getName());
     }
 
     // via SearchEngineCallback - may be called from any thread.
     @Override
     public void execute(@Nullable final org.mozilla.gecko.search.SearchEngine engine) {
         // Don't waste resources queueing to the background thread if we don't have a reference.
         if (getBrowserApp() == null) {
             return;
@@ -132,17 +133,17 @@ public class TelemetryCorePingDelegate e
             @WorkerThread
             @Override
             public void run() {
                 final BrowserApp activity = getBrowserApp();
                 if (activity == null) {
                     return;
                 }
 
-                final GeckoProfile profile = activity.getProfile();
+                final GeckoProfile profile = GeckoThread.getActiveProfile();
                 if (!TelemetryUploadService.isUploadEnabledByProfileConfig(activity, profile)) {
                     Log.d(LOGTAG, "Core ping upload disabled by profile config. Returning.");
                     return;
                 }
 
                 final String clientID;
                 try {
                     clientID = profile.getClientId();
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/BaseGeckoInterface.java
@@ -10,39 +10,29 @@ import org.mozilla.geckoview.BuildConfig
 
 import android.app.Activity;
 import android.content.Context;
 import android.view.View;
 import android.widget.AbsoluteLayout;
 
 public class BaseGeckoInterface implements GeckoAppShell.GeckoInterface {
     private final Context mContext;
-    private GeckoProfile mProfile;
     private final EventDispatcher eventDispatcher;
 
     public BaseGeckoInterface(Context context) {
         mContext = context;
         eventDispatcher = new EventDispatcher();
     }
 
     @Override
     public EventDispatcher getAppEventDispatcher() {
         return eventDispatcher;
     }
 
     @Override
-    public GeckoProfile getProfile() {
-        // Fall back to default profile if we didn't load a specific one
-        if (mProfile == null) {
-            mProfile = GeckoProfile.get(mContext);
-        }
-        return mProfile;
-    }
-
-    @Override
     public Activity getActivity() {
         // By default, GeckoView consumers do not have a distinguished current foreground Activity.
         return null;
     }
 
     @Override
     public String getDefaultUAString() {
         return HardwareUtils.isTablet() ? BuildConfig.USER_AGENT_GECKOVIEW_TABLET :
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -1656,17 +1656,16 @@ public class GeckoAppShell
     public interface AppStateListener {
         public void onPause();
         public void onResume();
         public void onOrientationChanged();
     }
 
     public interface GeckoInterface {
         public @NonNull EventDispatcher getAppEventDispatcher();
-        public GeckoProfile getProfile();
         public Activity getActivity();
         public String getDefaultUAString();
 
         public void addPluginView(View view);
         public void removePluginView(final View view);
         public void enableOrientationListener();
         public void disableOrientationListener();
         public void addAppStateListener(AppStateListener listener);
@@ -2009,18 +2008,18 @@ public class GeckoAppShell
     }
 
     @WrapForJNI(calledFrom = "gecko")
     private static boolean unlockProfile() {
         // Try to kill any zombie Fennec's that might be running
         GeckoAppShell.killAnyZombies();
 
         // Then force unlock this profile
-        if (getGeckoInterface() != null) {
-            GeckoProfile profile = getGeckoInterface().getProfile();
+        final GeckoProfile profile = GeckoThread.getActiveProfile();
+        if (profile != null) {
             File lock = profile.getFile(".parentlock");
             return lock.exists() && lock.delete();
         }
         return false;
     }
 
     @WrapForJNI(calledFrom = "gecko")
     private static String getProxyForURI(String spec, String scheme, String host, int port) {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoThread.java
@@ -328,16 +328,17 @@ public class GeckoThread extends Thread 
             Log.w(LOGTAG, "STARTUP PERFORMANCE WARNING: un-official build: purging the " +
                           "startup (JavaScript) caches.");
             args.add("-purgecaches");
         }
 
         return args.toArray(new String[args.size()]);
     }
 
+    @RobocopTarget
     public static GeckoProfile getActiveProfile() {
         return INSTANCE.getProfile();
     }
 
     public synchronized GeckoProfile getProfile() {
         if (!mInitialized) {
             return null;
         }
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testGeckoProfile.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testGeckoProfile.java
@@ -3,20 +3,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.tests;
 
 import java.io.File;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
-import org.mozilla.gecko.GeckoApp;
 import org.mozilla.gecko.GeckoProfile;
 import org.mozilla.gecko.GeckoProfileDirectories;
 import org.mozilla.gecko.GeckoSharedPrefs;
+import org.mozilla.gecko.GeckoThread;
 import org.mozilla.gecko.util.INIParser;
 import org.mozilla.gecko.util.INISection;
 
 import android.content.Context;
 import android.text.TextUtils;
 
 /**
  * This patch tests GeckoProfile. It has unit tests for basic getting and removing of profiles, as well as
@@ -41,17 +41,18 @@ public class testGeckoProfile extends Pi
         checkGuestProfile();
     }
 
     // This getter just passes an activity. Passing null should throw.
     private void checkDefaultGetter() {
         // "Default" is a custom profile set up by the test harness.
         mAsserter.info("Test using the test profile", GeckoProfile.CUSTOM_PROFILE);
         GeckoProfile profile = GeckoProfile.get(getActivity());
-        verifyProfile(profile, GeckoProfile.CUSTOM_PROFILE, ((GeckoApp) getActivity()).getProfile().getDir(), true);
+        verifyProfile(profile, GeckoProfile.CUSTOM_PROFILE,
+                      GeckoThread.getActiveProfile().getDir(), true);
 
         try {
             profile = GeckoProfile.get(null);
             mAsserter.ok(false, "Passing a null context should throw", profile.toString());
         } catch(Exception ex) {
             mAsserter.ok(true, "Passing a null context should throw", ex.toString());
         }
     }
@@ -60,17 +61,17 @@ public class testGeckoProfile extends Pi
     private void checkNamedGetter(String name) {
         mAsserter.info("Test using a named profile", name);
         GeckoProfile profile = GeckoProfile.get(getActivity(), name);
         if (name != null) {
             verifyProfile(profile, name, findDir(name), false);
             removeProfile(profile, true);
         } else {
             // Passing in null for a profile name, should get you the default
-            File defaultProfile = ((GeckoApp) getActivity()).getProfile().getDir();
+            File defaultProfile = GeckoThread.getActiveProfile().getDir();
             verifyProfile(profile, GeckoProfile.CUSTOM_PROFILE, defaultProfile, true);
         }
     }
 
     // Test get(Context, String, String) methods
     private void checkNameAndPathGetter(String name, boolean createBefore) {
         if (name == null) {
             checkNameAndPathGetter(name, null, createBefore);
@@ -111,17 +112,17 @@ public class testGeckoProfile extends Pi
             f = null;
         }
 
         if (f != null && createBefore) {
             // For some tests we create explicitly beforehand
             f.mkdir();
         }
 
-        final File testProfileDir = ((GeckoApp) getActivity()).getProfile().getDir();
+        final File testProfileDir = GeckoThread.getActiveProfile().getDir();
         final String expectedName = name != null ? name : GeckoProfile.CUSTOM_PROFILE;
 
         final GeckoProfile profile;
         if (useFile) {
             profile = GeckoProfile.get(getActivity(), name, file);
         } else {
             profile = GeckoProfile.get(getActivity(), name, path);
         }
@@ -177,17 +178,17 @@ public class testGeckoProfile extends Pi
         // name and null path
         checkNameAndFileGetter(TEST_PROFILE_NAME + (index++), null, false);
         // null name and null path
         checkNameAndFileGetter(null, null, false);
     }
 
     // Tests of Guest profile methods
     private void checkGuestProfile() {
-        final File testProfileDir = ((GeckoApp) getActivity()).getProfile().getDir();
+        final File testProfileDir = GeckoThread.getActiveProfile().getDir();
 
         mAsserter.info("Test getting a guest profile", "");
         GeckoProfile profile = GeckoProfile.getGuestProfile(getActivity());
         verifyProfile(profile, GeckoProfile.CUSTOM_PROFILE, getActivity().getFileStreamPath("guest"), true);
         mAsserter.ok(profile.inGuestMode(), "Profile is in guest mode", profile.getName());
 
         final File dir = profile.getDir();
         mAsserter.info("Test deleting a guest profile", "");