| 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.chrome.browser; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.SharedPreferences; | 10 import android.content.SharedPreferences; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector; | 93 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector; |
| 94 import org.chromium.chrome.browser.tabmodel.document.StorageDelegate; | 94 import org.chromium.chrome.browser.tabmodel.document.StorageDelegate; |
| 95 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 95 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
| 96 import org.chromium.chrome.browser.util.FeatureUtilities; | 96 import org.chromium.chrome.browser.util.FeatureUtilities; |
| 97 import org.chromium.components.sync.signin.AccountManagerDelegate; | 97 import org.chromium.components.sync.signin.AccountManagerDelegate; |
| 98 import org.chromium.components.sync.signin.AccountManagerHelper; | 98 import org.chromium.components.sync.signin.AccountManagerHelper; |
| 99 import org.chromium.components.sync.signin.SystemAccountManagerDelegate; | 99 import org.chromium.components.sync.signin.SystemAccountManagerDelegate; |
| 100 import org.chromium.content.app.ContentApplication; | 100 import org.chromium.content.app.ContentApplication; |
| 101 import org.chromium.content.browser.ChildProcessCreationParams; | 101 import org.chromium.content.browser.ChildProcessCreationParams; |
| 102 import org.chromium.content.browser.ChildProcessLauncher; | 102 import org.chromium.content.browser.ChildProcessLauncher; |
| 103 import org.chromium.content.browser.ContentViewStatics; | |
| 104 import org.chromium.content.common.ContentSwitches; | 103 import org.chromium.content.common.ContentSwitches; |
| 105 import org.chromium.policy.AppRestrictionsProvider; | 104 import org.chromium.policy.AppRestrictionsProvider; |
| 106 import org.chromium.policy.CombinedPolicyProvider; | 105 import org.chromium.policy.CombinedPolicyProvider; |
| 107 import org.chromium.policy.CombinedPolicyProvider.PolicyChangeListener; | 106 import org.chromium.policy.CombinedPolicyProvider.PolicyChangeListener; |
| 108 import org.chromium.printing.PrintingController; | 107 import org.chromium.printing.PrintingController; |
| 109 import org.chromium.ui.UiUtils; | 108 import org.chromium.ui.UiUtils; |
| 110 import org.chromium.ui.base.ActivityWindowAndroid; | 109 import org.chromium.ui.base.ActivityWindowAndroid; |
| 111 import org.chromium.ui.base.ResourceBundle; | 110 import org.chromium.ui.base.ResourceBundle; |
| 112 | 111 |
| 113 import java.lang.ref.WeakReference; | 112 import java.lang.ref.WeakReference; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 124 private static final String PREF_BOOT_TIMESTAMP = | 123 private static final String PREF_BOOT_TIMESTAMP = |
| 125 "com.google.android.apps.chrome.ChromeMobileApplication.BOOT_TIMESTA
MP"; | 124 "com.google.android.apps.chrome.ChromeMobileApplication.BOOT_TIMESTA
MP"; |
| 126 private static final long BOOT_TIMESTAMP_MARGIN_MS = 1000; | 125 private static final long BOOT_TIMESTAMP_MARGIN_MS = 1000; |
| 127 private static final String PREF_LOCALE = "locale"; | 126 private static final String PREF_LOCALE = "locale"; |
| 128 private static final String DEV_TOOLS_SERVER_SOCKET_PREFIX = "chrome"; | 127 private static final String DEV_TOOLS_SERVER_SOCKET_PREFIX = "chrome"; |
| 129 private static final String SESSIONS_UUID_PREF_KEY = "chromium.sync.sessions
.id"; | 128 private static final String SESSIONS_UUID_PREF_KEY = "chromium.sync.sessions
.id"; |
| 130 | 129 |
| 131 private static boolean sIsFinishedCachingNativeFlags; | 130 private static boolean sIsFinishedCachingNativeFlags; |
| 132 private static DocumentTabModelSelector sDocumentTabModelSelector; | 131 private static DocumentTabModelSelector sDocumentTabModelSelector; |
| 133 | 132 |
| 134 /** | |
| 135 * This class allows pausing scripts & network connections when we | |
| 136 * go to the background and resume when we are back in foreground again. | |
| 137 * TODO(pliard): Get rid of this class once JavaScript timers toggling is do
ne directly on | |
| 138 * the native side by subscribing to the system monitor events. | |
| 139 */ | |
| 140 private static class BackgroundProcessing { | |
| 141 private class SuspendRunnable implements Runnable { | |
| 142 @Override | |
| 143 public void run() { | |
| 144 mSuspendRunnable = null; | |
| 145 assert !mWebKitTimersAreSuspended; | |
| 146 mWebKitTimersAreSuspended = true; | |
| 147 ContentViewStatics.setWebKitSharedTimersSuspended(true); | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 private static final int SUSPEND_TIMERS_AFTER_MS = 5 * 60 * 1000; | |
| 152 private final Handler mHandler = new Handler(); | |
| 153 private boolean mWebKitTimersAreSuspended = false; | |
| 154 private SuspendRunnable mSuspendRunnable; | |
| 155 | |
| 156 private void onDestroy() { | |
| 157 if (mSuspendRunnable != null) { | |
| 158 mHandler.removeCallbacks(mSuspendRunnable); | |
| 159 mSuspendRunnable = null; | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 private void suspendTimers() { | |
| 164 if (mSuspendRunnable == null) { | |
| 165 mSuspendRunnable = new SuspendRunnable(); | |
| 166 mHandler.postDelayed(mSuspendRunnable, SUSPEND_TIMERS_AFTER_MS); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 private void startTimers() { | |
| 171 if (mSuspendRunnable != null) { | |
| 172 mHandler.removeCallbacks(mSuspendRunnable); | |
| 173 mSuspendRunnable = null; | |
| 174 } else if (mWebKitTimersAreSuspended) { | |
| 175 ContentViewStatics.setWebKitSharedTimersSuspended(false); | |
| 176 mWebKitTimersAreSuspended = false; | |
| 177 } | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 private final BackgroundProcessing mBackgroundProcessing = new BackgroundPro
cessing(); | |
| 182 private final PowerBroadcastReceiver mPowerBroadcastReceiver = new PowerBroa
dcastReceiver(); | 133 private final PowerBroadcastReceiver mPowerBroadcastReceiver = new PowerBroa
dcastReceiver(); |
| 183 | 134 |
| 184 // Used to trigger variation changes (such as seed fetches) upon application
foregrounding. | 135 // Used to trigger variation changes (such as seed fetches) upon application
foregrounding. |
| 185 private VariationsSession mVariationsSession; | 136 private VariationsSession mVariationsSession; |
| 186 | 137 |
| 187 private DevToolsServer mDevToolsServer; | 138 private DevToolsServer mDevToolsServer; |
| 188 | 139 |
| 189 private boolean mIsStarted; | 140 private boolean mIsStarted; |
| 190 private boolean mInitializedSharedClasses; | 141 private boolean mInitializedSharedClasses; |
| 191 private boolean mIsProcessInitialized; | 142 private boolean mIsProcessInitialized; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 224 |
| 274 /** | 225 /** |
| 275 * Called when a top-level Chrome activity (ChromeTabbedActivity, Fullscreen
Activity) is | 226 * Called when a top-level Chrome activity (ChromeTabbedActivity, Fullscreen
Activity) is |
| 276 * started in foreground. It will not be called again when other Chrome acti
vities take over | 227 * started in foreground. It will not be called again when other Chrome acti
vities take over |
| 277 * (see onStart()), that is, when correct activity calls startActivity() for
another Chrome | 228 * (see onStart()), that is, when correct activity calls startActivity() for
another Chrome |
| 278 * activity. | 229 * activity. |
| 279 */ | 230 */ |
| 280 private void onForegroundSessionStart() { | 231 private void onForegroundSessionStart() { |
| 281 UmaUtils.recordForegroundStartTime(); | 232 UmaUtils.recordForegroundStartTime(); |
| 282 ChildProcessLauncher.onBroughtToForeground(); | 233 ChildProcessLauncher.onBroughtToForeground(); |
| 283 mBackgroundProcessing.startTimers(); | |
| 284 updatePasswordEchoState(); | 234 updatePasswordEchoState(); |
| 285 FontSizePrefs.getInstance(this).onSystemFontScaleChanged(); | 235 FontSizePrefs.getInstance(this).onSystemFontScaleChanged(); |
| 286 updateAcceptLanguages(); | 236 updateAcceptLanguages(); |
| 287 mVariationsSession.start(getApplicationContext()); | 237 mVariationsSession.start(getApplicationContext()); |
| 288 mPowerBroadcastReceiver.onForegroundSessionStart(); | 238 mPowerBroadcastReceiver.onForegroundSessionStart(); |
| 289 | 239 |
| 290 // Track the ratio of Chrome startups that are caused by notification cl
icks. | 240 // Track the ratio of Chrome startups that are caused by notification cl
icks. |
| 291 // TODO(johnme): Add other reasons (and switch to recordEnumeratedHistog
ram). | 241 // TODO(johnme): Add other reasons (and switch to recordEnumeratedHistog
ram). |
| 292 RecordHistogram.recordBooleanHistogram( | 242 RecordHistogram.recordBooleanHistogram( |
| 293 "Startup.BringToForegroundReason", | 243 "Startup.BringToForegroundReason", |
| 294 NotificationPlatformBridge.wasNotificationRecentlyClicked()); | 244 NotificationPlatformBridge.wasNotificationRecentlyClicked()); |
| 295 } | 245 } |
| 296 | 246 |
| 297 /** | 247 /** |
| 298 * Called when last of Chrome activities is stopped, ending the foreground s
ession. This will | 248 * Called when last of Chrome activities is stopped, ending the foreground s
ession. This will |
| 299 * not be called when a Chrome activity is stopped because another Chrome ac
tivity takes over. | 249 * not be called when a Chrome activity is stopped because another Chrome ac
tivity takes over. |
| 300 * This is ensured by ActivityStatus, which switches to track new activity w
hen its started and | 250 * This is ensured by ActivityStatus, which switches to track new activity w
hen its started and |
| 301 * will not report the old one being stopped (see createStateListener() belo
w). | 251 * will not report the old one being stopped (see createStateListener() belo
w). |
| 302 */ | 252 */ |
| 303 private void onForegroundSessionEnd() { | 253 private void onForegroundSessionEnd() { |
| 304 if (!mIsStarted) return; | 254 if (!mIsStarted) return; |
| 305 mBackgroundProcessing.suspendTimers(); | |
| 306 flushPersistentData(); | 255 flushPersistentData(); |
| 307 mIsStarted = false; | 256 mIsStarted = false; |
| 308 mPowerBroadcastReceiver.onForegroundSessionEnd(); | 257 mPowerBroadcastReceiver.onForegroundSessionEnd(); |
| 309 | 258 |
| 310 ChildProcessLauncher.onSentToBackground(); | 259 ChildProcessLauncher.onSentToBackground(); |
| 311 IntentHandler.clearPendingReferrer(); | 260 IntentHandler.clearPendingReferrer(); |
| 312 IntentHandler.clearPendingIncognitoUrl(); | 261 IntentHandler.clearPendingIncognitoUrl(); |
| 313 | 262 |
| 314 int totalTabCount = 0; | 263 int totalTabCount = 0; |
| 315 for (WeakReference<Activity> reference : ApplicationStatus.getRunningAct
ivities()) { | 264 for (WeakReference<Activity> reference : ApplicationStatus.getRunningAct
ivities()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 326 "Tab.TotalTabCount.BeforeLeavingApp", totalTabCount); | 275 "Tab.TotalTabCount.BeforeLeavingApp", totalTabCount); |
| 327 } | 276 } |
| 328 | 277 |
| 329 /** | 278 /** |
| 330 * Called after onForegroundSessionEnd() indicating that the activity whose
onStop() ended the | 279 * Called after onForegroundSessionEnd() indicating that the activity whose
onStop() ended the |
| 331 * last foreground session was destroyed. | 280 * last foreground session was destroyed. |
| 332 */ | 281 */ |
| 333 private void onForegroundActivityDestroyed() { | 282 private void onForegroundActivityDestroyed() { |
| 334 if (ApplicationStatus.isEveryActivityDestroyed()) { | 283 if (ApplicationStatus.isEveryActivityDestroyed()) { |
| 335 // These will all be re-initialized when a new Activity starts / upo
n next use. | 284 // These will all be re-initialized when a new Activity starts / upo
n next use. |
| 336 mBackgroundProcessing.onDestroy(); | |
| 337 PartnerBrowserCustomizations.destroy(); | 285 PartnerBrowserCustomizations.destroy(); |
| 338 ShareHelper.clearSharedImages(this); | 286 ShareHelper.clearSharedImages(this); |
| 339 } | 287 } |
| 340 } | 288 } |
| 341 | 289 |
| 342 private ApplicationStateListener createApplicationStateListener() { | 290 private ApplicationStateListener createApplicationStateListener() { |
| 343 return new ApplicationStateListener() { | 291 return new ApplicationStateListener() { |
| 344 @Override | 292 @Override |
| 345 public void onApplicationStateChange(int newState) { | 293 public void onApplicationStateChange(int newState) { |
| 346 if (newState == ApplicationState.HAS_STOPPED_ACTIVITIES) { | 294 if (newState == ApplicationState.HAS_STOPPED_ACTIVITIES) { |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 * Caches flags that are needed by Activities that launch before the native
library is loaded | 818 * Caches flags that are needed by Activities that launch before the native
library is loaded |
| 871 * and stores them in SharedPreferences. Because this function is called dur
ing launch after the | 819 * and stores them in SharedPreferences. Because this function is called dur
ing launch after the |
| 872 * library has loaded, they won't affect the next launch until Chrome is res
tarted. | 820 * library has loaded, they won't affect the next launch until Chrome is res
tarted. |
| 873 */ | 821 */ |
| 874 private void cacheNativeFlags() { | 822 private void cacheNativeFlags() { |
| 875 if (sIsFinishedCachingNativeFlags) return; | 823 if (sIsFinishedCachingNativeFlags) return; |
| 876 FeatureUtilities.cacheNativeFlags(this); | 824 FeatureUtilities.cacheNativeFlags(this); |
| 877 sIsFinishedCachingNativeFlags = true; | 825 sIsFinishedCachingNativeFlags = true; |
| 878 } | 826 } |
| 879 } | 827 } |
| OLD | NEW |