Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/init/NativeInitializationController.java

Issue 2627093009: Fetch Finch seed during restore (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/init/NativeInitializationController.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/init/NativeInitializationController.java b/chrome/android/java/src/org/chromium/chrome/browser/init/NativeInitializationController.java
index a4835818eea5efe4527de6b06626dd528e699f7c..d17948cb8896bd4e9beb9cf873b2a2a2b78ea2c2 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/init/NativeInitializationController.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/init/NativeInitializationController.java
@@ -4,13 +4,10 @@
package org.chromium.chrome.browser.init;
-import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.content.IntentFilter;
import android.os.Handler;
import android.os.Looper;
-import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import org.chromium.base.ContextUtils;
@@ -18,10 +15,7 @@ import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.library_loader.ProcessInitException;
-import org.chromium.chrome.browser.ChromeVersionInfo;
import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer;
-import org.chromium.components.variations.firstrun.VariationsSeedService;
-import org.chromium.content.browser.ChildProcessLauncher;
import java.util.ArrayList;
import java.util.List;
@@ -35,6 +29,7 @@ import java.util.List;
class NativeInitializationController {
private static final String TAG = "NativeInitializationController";
+
Alexei Svitkine (slow) 2017/01/12 16:06:28 Nit: Remove empty line.
aberent 2017/01/12 17:31:50 Done.
private final ChromeActivityNativeDelegate mActivityDelegate;
private final Handler mHandler;
@@ -43,9 +38,8 @@ class NativeInitializationController {
private List<Intent> mPendingNewIntents;
private List<ActivityResult> mPendingActivityResults;
- private boolean mLibraryLoaded;
+ private boolean mBackgroundTasksComplete;
private boolean mHasDoneFirstDraw;
- private boolean mWaitingForVariationsFetch;
private boolean mHasSignaledLibraryLoaded;
private boolean mInitializationComplete;
@@ -75,14 +69,6 @@ class NativeInitializationController {
mActivityDelegate = activityDelegate;
}
- private static boolean shouldFetchVariationsSeedBeforeFRE() {
- // For now, only do the fetching on official canary and dev builds, as there is a concern
- // about the extra latency this adds.
- // TODO(asvitkine): Revise this logic based on histogram data.
- return ChromeVersionInfo.isOfficialBuild()
- && (ChromeVersionInfo.isCanaryBuild() || ChromeVersionInfo.isDevBuild());
- }
-
/**
* Start loading the native library in the background. This kicks off the native initialization
* process.
@@ -93,77 +79,36 @@ class NativeInitializationController {
public void startBackgroundTasks(final boolean allocateChildConnection) {
ThreadUtils.assertOnUiThread();
- // TODO(asvitkine): Consider moving this logic to a singleton, like
- // ChromeBrowserInitializer.
- if (shouldFetchVariationsSeedBeforeFRE()) {
Alexei Svitkine (slow) 2017/01/12 16:06:28 You need to rebase as this was updated on TOT.
aberent 2017/01/12 17:31:50 Done.
- Context context = ContextUtils.getApplicationContext();
- Intent initialIntent = mActivityDelegate.getInitialIntent();
- if (FirstRunFlowSequencer.checkIfFirstRunIsNecessary(context, initialIntent, false)
- != null) {
- mWaitingForVariationsFetch = true;
- IntentFilter filter = new IntentFilter(VariationsSeedService.COMPLETE_BROADCAST);
- final LocalBroadcastManager manager = LocalBroadcastManager.getInstance(context);
- manager.registerReceiver(
- new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- // This check is needed because onReceive() can be called multiple
- // times even after having unregistered below if two broadcasts
- // arrive in rapid succession.
- if (!mWaitingForVariationsFetch) return;
- mWaitingForVariationsFetch = false;
- manager.unregisterReceiver(this);
- signalNativeLibraryLoadedIfReady();
- }
- },
- filter);
- context.startService(new Intent(context, VariationsSeedService.class));
+ Context context = ContextUtils.getApplicationContext();
+ Intent initialIntent = mActivityDelegate.getInitialIntent();
Alexei Svitkine (slow) 2017/01/12 16:06:28 Nit: Inline these two into the call below since th
aberent 2017/01/12 17:31:50 Done.
+ boolean initVariationSeed = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(context,
Alexei Svitkine (slow) 2017/01/12 16:06:28 Nit: I'd call this var fetchVariationsSeed.
aberent 2017/01/12 17:31:50 Done.
+ initialIntent, false) != null;
+
+ mBackgroundTasksComplete = false;
+ new AsyncInitTaskRunner() {
+
+ @Override
+ public void onSuccess() {
+ ThreadUtils.assertOnUiThread();
+
+ mBackgroundTasksComplete = true;
+ signalNativeLibraryLoadedIfReady();
}
- }
- // TODO(yusufo) : Investigate using an AsyncTask for this.
- new Thread() {
@Override
- public void run() {
- try {
- LibraryLoader libraryLoader =
- LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER);
- libraryLoader.ensureInitialized();
- // The prefetch is done after the library load for two reasons:
- // - It is easier to know the library location after it has
- // been loaded.
- // - Testing has shown that this gives the best compromise,
- // by avoiding performance regression on any tested
- // device, and providing performance improvement on
- // some. Doing it earlier delays UI inflation and more
- // generally startup on some devices, most likely by
- // competing for IO.
- // For experimental results, see http://crbug.com/460438.
- libraryLoader.asyncPrefetchLibrariesToMemory();
- } catch (ProcessInitException e) {
- Log.e(TAG, "Unable to load native library.", e);
- mActivityDelegate.onStartupFailure();
- return;
- }
- if (allocateChildConnection) {
- ChildProcessLauncher.warmUp(ContextUtils.getApplicationContext());
- }
- ThreadUtils.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mLibraryLoaded = true;
- signalNativeLibraryLoadedIfReady();
- }
- });
+ public void onFailure() {
+ mActivityDelegate.onStartupFailure();
}
- }.start();
+
+ }.startBackgroundTasks(allocateChildConnection, initVariationSeed);
+
}
private void signalNativeLibraryLoadedIfReady() {
ThreadUtils.assertOnUiThread();
// Called on UI thread when any of the booleans below have changed.
- if (mHasDoneFirstDraw && mLibraryLoaded && !mWaitingForVariationsFetch) {
+ if (mHasDoneFirstDraw && mBackgroundTasksComplete) {
// This block should only be hit once.
assert !mHasSignaledLibraryLoaded;
mHasSignaledLibraryLoaded = true;

Powered by Google App Engine
This is Rietveld 408576698