| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Handler; | 8 import android.os.Handler; |
| 9 | 9 |
| 10 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 // Helper constants for {@link #executeEnqueuedCallbacks(int, boolean)}. | 55 // Helper constants for {@link #executeEnqueuedCallbacks(int, boolean)}. |
| 56 @VisibleForTesting | 56 @VisibleForTesting |
| 57 static final int STARTUP_SUCCESS = -1; | 57 static final int STARTUP_SUCCESS = -1; |
| 58 @VisibleForTesting | 58 @VisibleForTesting |
| 59 static final int STARTUP_FAILURE = 1; | 59 static final int STARTUP_FAILURE = 1; |
| 60 | 60 |
| 61 private static BrowserStartupController sInstance; | 61 private static BrowserStartupController sInstance; |
| 62 | 62 |
| 63 private static boolean sBrowserMayStartAsynchronously = false; | 63 private static boolean sBrowserMayStartAsynchronously = false; |
| 64 private static boolean sShouldStartGpuProcessOnBrowserStartup = true; |
| 64 | 65 |
| 65 private static void setAsynchronousStartup(boolean enable) { | 66 private static void setAsynchronousStartup(boolean enable) { |
| 66 sBrowserMayStartAsynchronously = enable; | 67 sBrowserMayStartAsynchronously = enable; |
| 67 } | 68 } |
| 68 | 69 |
| 70 private static void setShouldStartGpuProcessOnBrowserStartup(boolean enable)
{ |
| 71 sShouldStartGpuProcessOnBrowserStartup = enable; |
| 72 } |
| 73 |
| 69 @VisibleForTesting | 74 @VisibleForTesting |
| 70 @CalledByNative | 75 @CalledByNative |
| 71 static boolean browserMayStartAsynchonously() { | 76 static boolean browserMayStartAsynchonously() { |
| 72 return sBrowserMayStartAsynchronously; | 77 return sBrowserMayStartAsynchronously; |
| 73 } | 78 } |
| 74 | 79 |
| 75 @VisibleForTesting | 80 @VisibleForTesting |
| 76 @CalledByNative | 81 @CalledByNative |
| 77 static void browserStartupComplete(int result) { | 82 static void browserStartupComplete(int result) { |
| 78 if (sInstance != null) { | 83 if (sInstance != null) { |
| 79 sInstance.executeEnqueuedCallbacks(result, NOT_ALREADY_STARTED); | 84 sInstance.executeEnqueuedCallbacks(result, NOT_ALREADY_STARTED); |
| 80 } | 85 } |
| 81 } | 86 } |
| 82 | 87 |
| 88 @CalledByNative |
| 89 static boolean shouldStartGpuProcessOnBrowserStartup() { |
| 90 return sShouldStartGpuProcessOnBrowserStartup; |
| 91 } |
| 92 |
| 83 // A list of callbacks that should be called when the async startup of the b
rowser process is | 93 // A list of callbacks that should be called when the async startup of the b
rowser process is |
| 84 // complete. | 94 // complete. |
| 85 private final List<StartupCallback> mAsyncStartupCallbacks; | 95 private final List<StartupCallback> mAsyncStartupCallbacks; |
| 86 | 96 |
| 87 // The context is set on creation, but the reference is cleared after the br
owser process | 97 // The context is set on creation, but the reference is cleared after the br
owser process |
| 88 // initialization has been started, since it is not needed anymore. This is
to ensure the | 98 // initialization has been started, since it is not needed anymore. This is
to ensure the |
| 89 // context is not leaked. | 99 // context is not leaked. |
| 90 private final Context mContext; | 100 private final Context mContext; |
| 91 | 101 |
| 92 // Whether the async startup of the browser process has started. | 102 // Whether the async startup of the browser process has started. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 149 } |
| 140 return sInstance; | 150 return sInstance; |
| 141 } | 151 } |
| 142 | 152 |
| 143 /** | 153 /** |
| 144 * Start the browser process asynchronously. This will set up a queue of UI
thread tasks to | 154 * Start the browser process asynchronously. This will set up a queue of UI
thread tasks to |
| 145 * initialize the browser process. | 155 * initialize the browser process. |
| 146 * <p/> | 156 * <p/> |
| 147 * Note that this can only be called on the UI thread. | 157 * Note that this can only be called on the UI thread. |
| 148 * | 158 * |
| 159 * @param startGpuProcess Whether to start the GPU process if it is not star
ted. |
| 149 * @param callback the callback to be called when browser startup is complet
e. | 160 * @param callback the callback to be called when browser startup is complet
e. |
| 150 */ | 161 */ |
| 151 public void startBrowserProcessesAsync(final StartupCallback callback) | 162 public void startBrowserProcessesAsync(boolean startGpuProcess, final Startu
pCallback callback) |
| 152 throws ProcessInitException { | 163 throws ProcessInitException { |
| 153 assert ThreadUtils.runningOnUiThread() : "Tried to start the browser on
the wrong thread."; | 164 assert ThreadUtils.runningOnUiThread() : "Tried to start the browser on
the wrong thread."; |
| 154 if (mStartupDone) { | 165 if (mStartupDone) { |
| 155 // Browser process initialization has already been completed, so we
can immediately post | 166 // Browser process initialization has already been completed, so we
can immediately post |
| 156 // the callback. | 167 // the callback. |
| 157 postStartupCompleted(callback); | 168 postStartupCompleted(callback); |
| 158 return; | 169 return; |
| 159 } | 170 } |
| 160 | 171 |
| 161 // Browser process has not been fully started yet, so we defer executing
the callback. | 172 // Browser process has not been fully started yet, so we defer executing
the callback. |
| 162 mAsyncStartupCallbacks.add(callback); | 173 mAsyncStartupCallbacks.add(callback); |
| 163 | 174 |
| 164 if (!mHasStartedInitializingBrowserProcess) { | 175 if (!mHasStartedInitializingBrowserProcess) { |
| 165 // This is the first time we have been asked to start the browser pr
ocess. We set the | 176 // This is the first time we have been asked to start the browser pr
ocess. We set the |
| 166 // flag that indicates that we have kicked off starting the browser
process. | 177 // flag that indicates that we have kicked off starting the browser
process. |
| 167 mHasStartedInitializingBrowserProcess = true; | 178 mHasStartedInitializingBrowserProcess = true; |
| 168 | 179 |
| 169 setAsynchronousStartup(true); | 180 setAsynchronousStartup(true); |
| 181 setShouldStartGpuProcessOnBrowserStartup(startGpuProcess); |
| 170 prepareToStartBrowserProcess(false, new Runnable() { | 182 prepareToStartBrowserProcess(false, new Runnable() { |
| 171 @Override | 183 @Override |
| 172 public void run() { | 184 public void run() { |
| 173 ThreadUtils.assertOnUiThread(); | 185 ThreadUtils.assertOnUiThread(); |
| 174 if (contentStart() > 0) { | 186 if (contentStart() > 0) { |
| 175 // Failed. The callbacks may not have run, so run them. | 187 // Failed. The callbacks may not have run, so run them. |
| 176 enqueueCallbackExecution(STARTUP_FAILURE, NOT_ALREADY_ST
ARTED); | 188 enqueueCallbackExecution(STARTUP_FAILURE, NOT_ALREADY_ST
ARTED); |
| 177 } | 189 } |
| 178 } | 190 } |
| 179 }); | 191 }); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // Normally Main.java will have already loaded the library asynchronousl
y, we only need | 295 // Normally Main.java will have already loaded the library asynchronousl
y, we only need |
| 284 // to load it here if we arrived via another flow, e.g. bookmark access
& sync setup. | 296 // to load it here if we arrived via another flow, e.g. bookmark access
& sync setup. |
| 285 LibraryLoader.get(mLibraryProcessType).ensureInitialized(mContext); | 297 LibraryLoader.get(mLibraryProcessType).ensureInitialized(mContext); |
| 286 | 298 |
| 287 Runnable postResourceExtraction = new Runnable() { | 299 Runnable postResourceExtraction = new Runnable() { |
| 288 @Override | 300 @Override |
| 289 public void run() { | 301 public void run() { |
| 290 if (!mPostResourceExtractionTasksCompleted) { | 302 if (!mPostResourceExtractionTasksCompleted) { |
| 291 // TODO(yfriedman): Remove dependency on a command line flag
for this. | 303 // TODO(yfriedman): Remove dependency on a command line flag
for this. |
| 292 DeviceUtils.addDeviceSpecificUserAgentSwitch(mContext); | 304 DeviceUtils.addDeviceSpecificUserAgentSwitch(mContext); |
| 293 | |
| 294 nativeSetCommandLineFlags( | 305 nativeSetCommandLineFlags( |
| 295 singleProcess, nativeIsPluginEnabled() ? getPlugins(
) : null); | 306 singleProcess, nativeIsPluginEnabled() ? getPlugins(
) : null); |
| 296 mPostResourceExtractionTasksCompleted = true; | 307 mPostResourceExtractionTasksCompleted = true; |
| 297 } | 308 } |
| 298 | 309 |
| 299 if (completionCallback != null) completionCallback.run(); | 310 if (completionCallback != null) completionCallback.run(); |
| 300 } | 311 } |
| 301 }; | 312 }; |
| 302 | 313 |
| 303 if (completionCallback == null) { | 314 if (completionCallback == null) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 326 | 337 |
| 327 private static native void nativeSetCommandLineFlags( | 338 private static native void nativeSetCommandLineFlags( |
| 328 boolean singleProcess, String pluginDescriptor); | 339 boolean singleProcess, String pluginDescriptor); |
| 329 | 340 |
| 330 // Is this an official build of Chrome? Only native code knows for sure. Off
icial build | 341 // Is this an official build of Chrome? Only native code knows for sure. Off
icial build |
| 331 // knowledge is needed very early in process startup. | 342 // knowledge is needed very early in process startup. |
| 332 private static native boolean nativeIsOfficialBuild(); | 343 private static native boolean nativeIsOfficialBuild(); |
| 333 | 344 |
| 334 private static native boolean nativeIsPluginEnabled(); | 345 private static native boolean nativeIsPluginEnabled(); |
| 335 } | 346 } |
| OLD | NEW |