Bug 1258470 - Part 9b: Rework some GeckoProfile bits, removing Distribution and default bookmark support. draft
authorNick Alexander <nalexander@mozilla.com>
Tue, 21 Jun 2016 11:08:23 -0700
changeset 381002 e679437f8ea93eec6c3031daccf4d17ddbd95bec
parent 381001 51ea5855379e2b5c914052702d79570b9a5a2b98
child 381003 9297f5de4fddd4d85f31b8a1dccc6be3be0a9496
push id21383
push usernalexander@mozilla.com
push dateFri, 24 Jun 2016 00:16:43 +0000
bugs1258470
milestone50.0a1
Bug 1258470 - Part 9b: Rework some GeckoProfile bits, removing Distribution and default bookmark support. This needs a hook into the App in some way. MozReview-Commit-ID: 7h7SApZjMv9
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -888,32 +888,32 @@ public class BrowserApp extends GeckoApp
             // in the firstrun pane being shown.
             return;
         }
         final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
 
         try {
             final SharedPreferences prefs = GeckoSharedPrefs.forProfile(this);
 
-            if (prefs.getBoolean(FirstrunAnimationContainer.PREF_FIRSTRUN_ENABLED, false)) {
+            if (prefs.getBoolean(GeckoProfile.PREF_FIRSTRUN_ENABLED, false)) {
                 if (!Intent.ACTION_VIEW.equals(intent.getAction())) {
                     showFirstrunPager();
 
                     if (HardwareUtils.isTablet()) {
                         mTabStrip.setOnTabChangedListener(new TabStripInterface.OnTabAddedOrRemovedListener() {
                             @Override
                             public void onTabChanged() {
                                 hideFirstrunPager(TelemetryContract.Method.BUTTON);
                                 mTabStrip.setOnTabChangedListener(null);
                             }
                         });
                     }
                 }
                 // Don't bother trying again to show the v1 minimal first run.
-                prefs.edit().putBoolean(FirstrunAnimationContainer.PREF_FIRSTRUN_ENABLED, false).apply();
+                prefs.edit().putBoolean(GeckoProfile.PREF_FIRSTRUN_ENABLED, false).apply();
             }
         } finally {
             StrictMode.setThreadPolicy(savedPolicy);
         }
     }
 
     private Class<?> getMediaPlayerManager() {
         if (AppConstants.MOZ_MEDIA_PLAYER) {
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoProfile.java
@@ -1,35 +1,30 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * 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;
 
 import android.app.Activity;
-import android.content.ContentResolver;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.support.annotation.WorkerThread;
 import android.text.TextUtils;
 import android.util.Log;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
 import org.mozilla.gecko.GeckoProfileDirectories.NoSuchProfileException;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.db.BrowserDB;
-import org.mozilla.gecko.db.LocalBrowserDB;
 import org.mozilla.gecko.db.StubBrowserDB;
-import org.mozilla.gecko.distribution.Distribution;
-import org.mozilla.gecko.firstrun.FirstrunAnimationContainer;
-import org.mozilla.gecko.preferences.DistroSharedPrefsImport;
 import org.mozilla.gecko.util.FileUtils;
 import org.mozilla.gecko.util.INIParser;
 import org.mozilla.gecko.util.INISection;
 import org.mozilla.gecko.util.IntentUtils;
 
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -68,16 +63,18 @@ public final class GeckoProfile {
     }
 
     public static final String DEFAULT_PROFILE = "default";
     // Profile is using a custom directory outside of the Mozilla directory.
     public static final String CUSTOM_PROFILE = "";
     public static final String GUEST_PROFILE_DIR = "guest";
     public static final String GUEST_MODE_PREF = "guestMode";
 
+    public static final String PREF_FIRSTRUN_ENABLED = "startpane_enabled";
+
     // Session store
     private static final String SESSION_FILE = "sessionstore.js";
     private static final String SESSION_FILE_BACKUP = "sessionstore.bak";
     private static final long MAX_BACKUP_FILE_AGE = 1000 * 3600 * 24; // 24 hours
 
     private boolean mOldSessionDataProcessed = false;
 
     private static final ConcurrentHashMap<String, GeckoProfile> sProfileCache =
@@ -924,17 +921,18 @@ public final class GeckoProfile {
 
         if (!isDefaultSet) {
             // only set as default if this is the first profile we're creating
             profileSection.setProperty("Default", 1);
 
             // We have no intention of stopping this session. The FIRSTRUN session
             // ends when the browsing session/activity has ended. All events
             // during firstrun will be tagged as FIRSTRUN.
-            Telemetry.startUISession(TelemetryContract.Session.FIRSTRUN);
+            // TODO: local broadcast to tell App that things are happening?
+            // Telemetry.startUISession(TelemetryContract.Session.FIRSTRUN);
         }
 
         parser.addSection(profileSection);
         parser.write();
 
         enqueueInitialization(profileDir);
 
         // Write out profile creation time, mirroring the logic in nsToolkitProfileService.
@@ -953,88 +951,26 @@ public final class GeckoProfile {
 
         // Create the client ID file before Gecko starts (we assume this method
         // is called before Gecko starts). If we let Gecko start, the JS telemetry
         // code may try to write to the file at the same time Java does.
         persistClientId(generateNewClientId());
 
         // Initialize pref flag for displaying the start pane for a new profile.
         final SharedPreferences prefs = GeckoSharedPrefs.forProfile(mApplicationContext);
-        prefs.edit().putBoolean(FirstrunAnimationContainer.PREF_FIRSTRUN_ENABLED, true).apply();
+        prefs.edit().putBoolean(PREF_FIRSTRUN_ENABLED, true).apply();
 
         return profileDir;
     }
 
     /**
      * This method is called once, immediately before creation of the profile
      * directory completes.
      *
      * It queues up work to be done in the background to prepare the profile,
      * such as adding default bookmarks.
      *
      * This is public for use *from tests only*!
      */
     @RobocopTarget
     public void enqueueInitialization(final File profileDir) {
-        Log.i(LOGTAG, "Enqueuing profile init.");
-        final Context context = mApplicationContext;
-
-        // Add everything when we're done loading the distribution.
-        final Distribution distribution = Distribution.getInstance(context);
-        distribution.addOnDistributionReadyCallback(new Distribution.ReadyCallback() {
-            @Override
-            public void distributionNotFound() {
-                this.distributionFound(null);
-            }
-
-            @Override
-            public void distributionFound(Distribution distribution) {
-                Log.d(LOGTAG, "Running post-distribution task: bookmarks.");
-
-                final ContentResolver cr = context.getContentResolver();
-
-                // Because we are running in the background, we want to synchronize on the
-                // GeckoProfile instance so that we don't race with main thread operations
-                // such as locking/unlocking/removing the profile.
-                synchronized (GeckoProfile.this) {
-                    // Skip initialization if the profile directory has been removed.
-                    if (!profileDir.exists()) {
-                        return;
-                    }
-
-                    // We pass the number of added bookmarks to ensure that the
-                    // indices of the distribution and default bookmarks are
-                    // contiguous. Because there are always at least as many
-                    // bookmarks as there are favicons, we can also guarantee that
-                    // the favicon IDs won't overlap.
-                    final LocalBrowserDB db = new LocalBrowserDB(getName());
-                    final int offset = distribution == null ? 0 : db.addDistributionBookmarks(cr, distribution, 0);
-                    db.addDefaultBookmarks(context, cr, offset);
-
-                    Log.d(LOGTAG, "Running post-distribution task: android preferences.");
-                    DistroSharedPrefsImport.importPreferences(context, distribution);
-                }
-            }
-
-            @Override
-            public void distributionArrivedLate(Distribution distribution) {
-                Log.d(LOGTAG, "Running late distribution task: bookmarks.");
-                // Recover as best we can.
-                synchronized (GeckoProfile.this) {
-                    // Skip initialization if the profile directory has been removed.
-                    if (!profileDir.exists()) {
-                        return;
-                    }
-
-                    final LocalBrowserDB db = new LocalBrowserDB(getName());
-                    // We assume we've been called very soon after startup, and so our offset
-                    // into "Mobile Bookmarks" is the number of bookmarks in the DB.
-                    final ContentResolver cr = context.getContentResolver();
-                    final int offset = db.getCount(cr, "bookmarks");
-                    db.addDistributionBookmarks(cr, distribution, offset);
-
-                    Log.d(LOGTAG, "Running late distribution task: android preferences.");
-                    DistroSharedPrefsImport.importPreferences(context, distribution);
-                }
-            }
-        });
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java
+++ b/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunAnimationContainer.java
@@ -19,17 +19,16 @@ import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.util.Experiments;
 
 /**
  * A container for the pager and the entire first run experience.
  * This is used for animation purposes.
  */
 public class FirstrunAnimationContainer extends LinearLayout {
-    public static final String PREF_FIRSTRUN_ENABLED = "startpane_enabled";
 
     public static interface OnFinishListener {
         public void onFinish();
     }
 
     private FirstrunPager pager;
     private boolean visible;
     private OnFinishListener onFinishListener;