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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ChromeActivity.java

Issue 2203223002: Revert "Separate deferred startup into tasks." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.app.Activity; 9 import android.app.Activity;
10 import android.app.SearchManager; 10 import android.app.SearchManager;
11 import android.app.assist.AssistContent; 11 import android.app.assist.AssistContent;
12 import android.content.Context; 12 import android.content.Context;
13 import android.content.Intent; 13 import android.content.Intent;
14 import android.content.res.Configuration; 14 import android.content.res.Configuration;
15 import android.graphics.Bitmap; 15 import android.graphics.Bitmap;
16 import android.graphics.Color; 16 import android.graphics.Color;
17 import android.graphics.Rect; 17 import android.graphics.Rect;
18 import android.graphics.drawable.ColorDrawable; 18 import android.graphics.drawable.ColorDrawable;
19 import android.graphics.drawable.Drawable; 19 import android.graphics.drawable.Drawable;
20 import android.net.Uri; 20 import android.net.Uri;
21 import android.os.Build; 21 import android.os.Build;
22 import android.os.Bundle; 22 import android.os.Bundle;
23 import android.os.Looper;
24 import android.os.MessageQueue;
23 import android.os.SystemClock; 25 import android.os.SystemClock;
24 import android.support.v7.app.AlertDialog; 26 import android.support.v7.app.AlertDialog;
25 import android.util.DisplayMetrics; 27 import android.util.DisplayMetrics;
26 import android.view.Menu; 28 import android.view.Menu;
27 import android.view.MenuItem; 29 import android.view.MenuItem;
28 import android.view.View; 30 import android.view.View;
29 import android.view.ViewConfiguration; 31 import android.view.ViewConfiguration;
30 import android.view.ViewGroup; 32 import android.view.ViewGroup;
31 import android.view.ViewStub; 33 import android.view.ViewStub;
32 import android.view.Window; 34 import android.view.Window;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 */ 153 */
152 public AppMenuHandler get(Activity activity, AppMenuPropertiesDelegate d elegate, 154 public AppMenuHandler get(Activity activity, AppMenuPropertiesDelegate d elegate,
153 int menuResourceId); 155 int menuResourceId);
154 } 156 }
155 157
156 /** 158 /**
157 * No control container to inflate during initialization. 159 * No control container to inflate during initialization.
158 */ 160 */
159 static final int NO_CONTROL_CONTAINER = -1; 161 static final int NO_CONTROL_CONTAINER = -1;
160 162
163 /** Delay in ms after first page load finishes before we initiate deferred s tartup actions. */
164 private static final int DEFERRED_STARTUP_DELAY_MS = 1000;
165
161 private static final int RECORD_MULTI_WINDOW_SCREEN_WIDTH_DELAY_MS = 5000; 166 private static final int RECORD_MULTI_WINDOW_SCREEN_WIDTH_DELAY_MS = 5000;
162 167
163 /** 168 /**
164 * Timeout in ms for reading PartnerBrowserCustomizations provider. 169 * Timeout in ms for reading PartnerBrowserCustomizations provider.
165 */ 170 */
166 private static final int PARTNER_BROWSER_CUSTOMIZATIONS_TIMEOUT_MS = 10000; 171 private static final int PARTNER_BROWSER_CUSTOMIZATIONS_TIMEOUT_MS = 10000;
167 private static final String TAG = "ChromeActivity"; 172 private static final String TAG = "ChromeActivity";
168 private static final Rect EMPTY_RECT = new Rect(); 173 private static final Rect EMPTY_RECT = new Rect();
169 174
170 private TabModelSelector mTabModelSelector; 175 private TabModelSelector mTabModelSelector;
171 private TabModelSelectorTabObserver mTabModelSelectorTabObserver; 176 private TabModelSelectorTabObserver mTabModelSelectorTabObserver;
172 private TabCreatorManager.TabCreator mRegularTabCreator; 177 private TabCreatorManager.TabCreator mRegularTabCreator;
173 private TabCreatorManager.TabCreator mIncognitoTabCreator; 178 private TabCreatorManager.TabCreator mIncognitoTabCreator;
174 private TabContentManager mTabContentManager; 179 private TabContentManager mTabContentManager;
175 private UmaSessionStats mUmaSessionStats; 180 private UmaSessionStats mUmaSessionStats;
176 private ContextReporter mContextReporter; 181 private ContextReporter mContextReporter;
177 protected GSAServiceClient mGSAServiceClient; 182 protected GSAServiceClient mGSAServiceClient;
178 183
179 private boolean mPartnerBrowserRefreshNeeded; 184 private boolean mPartnerBrowserRefreshNeeded;
180 185
181 protected IntentHandler mIntentHandler; 186 protected IntentHandler mIntentHandler;
182 187
183 private boolean mDeferredStartupPosted; 188 /** Whether onDeferredStartup() has been run. */
189 private boolean mDeferredStartupNotified;
184 190
185 // The class cannot implement TouchExplorationStateChangeListener, 191 // The class cannot implement TouchExplorationStateChangeListener,
186 // because it is only available for Build.VERSION_CODES.KITKAT and later. 192 // because it is only available for Build.VERSION_CODES.KITKAT and later.
187 // We have to instantiate the TouchExplorationStateChangeListner object in t he code. 193 // We have to instantiate the TouchExplorationStateChangeListner object in t he code.
188 @SuppressLint("NewApi") 194 @SuppressLint("NewApi")
189 private TouchExplorationStateChangeListener mTouchExplorationStateChangeList ener; 195 private TouchExplorationStateChangeListener mTouchExplorationStateChangeList ener;
190 196
191 // Observes when sync becomes ready to create the mContextReporter. 197 // Observes when sync becomes ready to create the mContextReporter.
192 private ProfileSyncService.SyncStateChangedListener mSyncStateChangedListene r; 198 private ProfileSyncService.SyncStateChangedListener mSyncStateChangedListene r;
193 199
(...skipping 12 matching lines...) Expand all
206 // Time in ms that it took took us to inflate the initial layout 212 // Time in ms that it took took us to inflate the initial layout
207 private long mInflateInitialLayoutDurationMs; 213 private long mInflateInitialLayoutDurationMs;
208 214
209 private int mScreenWidthDp; 215 private int mScreenWidthDp;
210 private Runnable mRecordMultiWindowModeScreenWidthRunnable; 216 private Runnable mRecordMultiWindowModeScreenWidthRunnable;
211 217
212 private AssistStatusHandler mAssistStatusHandler; 218 private AssistStatusHandler mAssistStatusHandler;
213 219
214 // A set of views obscuring all tabs. When this set is nonempty, 220 // A set of views obscuring all tabs. When this set is nonempty,
215 // all tab content will be hidden from the accessibility tree. 221 // all tab content will be hidden from the accessibility tree.
216 private List<View> mViewsObscuringAllTabs = new ArrayList<>(); 222 private List<View> mViewsObscuringAllTabs = new ArrayList<View>();
217 223
218 private static AppMenuHandlerFactory sAppMenuHandlerFactory = new AppMenuHan dlerFactory() { 224 private static AppMenuHandlerFactory sAppMenuHandlerFactory = new AppMenuHan dlerFactory() {
219 @Override 225 @Override
220 public AppMenuHandler get( 226 public AppMenuHandler get(
221 Activity activity, AppMenuPropertiesDelegate delegate, int menuR esourceId) { 227 Activity activity, AppMenuPropertiesDelegate delegate, int menuR esourceId) {
222 return new AppMenuHandler(activity, delegate, menuResourceId); 228 return new AppMenuHandler(activity, delegate, menuResourceId);
223 } 229 }
224 }; 230 };
225 231
226 // See enableHardwareAcceleration() 232 // See enableHardwareAcceleration()
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 mIntentHandler.onNewIntent(this, intent); 682 mIntentHandler.onNewIntent(this, intent);
677 } 683 }
678 684
679 /** 685 /**
680 * @return Whether the given activity contains a CustomTab. 686 * @return Whether the given activity contains a CustomTab.
681 */ 687 */
682 public boolean isCustomTab() { 688 public boolean isCustomTab() {
683 return false; 689 return false;
684 } 690 }
685 691
686 /**
687 * Overriding methods should queue tasks on the DeferredStartupHandler befor e or after calling
688 * super depending on whether the tasks should run before or after these one s.
689 */
690 @Override 692 @Override
691 protected void onDeferredStartup() { 693 protected void onDeferredStartup() {
692 super.onDeferredStartup(); 694 super.onDeferredStartup();
693 initDeferredStartupForActivity(); 695 DeferredStartupHandler.getInstance().onDeferredStartupForApp();
694 DeferredStartupHandler.getInstance().initDeferredStartupForApp(); 696 onDeferredStartupForActivity();
695 DeferredStartupHandler.getInstance().queueDeferredTasksOnIdleHandler();
696 } 697 }
697 698
698 /** 699 /**
699 * All deferred startup tasks that require the activity rather than the app should go here. 700 * All deferred startup tasks that require the activity rather than the app should go here.
700 */ 701 */
701 private void initDeferredStartupForActivity() { 702 private void onDeferredStartupForActivity() {
702 DeferredStartupHandler.getInstance().addDeferredTask(new Runnable() { 703 BeamController.registerForBeam(this, new BeamProvider() {
703 @Override 704 @Override
704 public void run() { 705 public String getTabUrlForBeam() {
705 if (isActivityDestroyed()) return; 706 if (isOverlayVisible()) return null;
706 BeamController.registerForBeam(ChromeActivity.this, new BeamProv ider() { 707 if (getActivityTab() == null) return null;
707 @Override 708 return getActivityTab().getUrl();
708 public String getTabUrlForBeam() {
709 if (isOverlayVisible()) return null;
710 if (getActivityTab() == null) return null;
711 return getActivityTab().getUrl();
712 }
713 });
714
715 UpdateMenuItemHelper.getInstance().checkForUpdateOnBackgroundThr ead(
716 ChromeActivity.this);
717 } 709 }
718 }); 710 });
719 711
720 DeferredStartupHandler.getInstance().addDeferredTask(new Runnable() { 712 UpdateMenuItemHelper.getInstance().checkForUpdateOnBackgroundThread(this );
721 @Override
722 public void run() {
723 if (isActivityDestroyed()) return;
724 if (mToolbarManager != null) {
725 String simpleName = getClass().getSimpleName();
726 RecordHistogram.recordTimesHistogram(
727 "MobileStartup.ToolbarInflationTime." + simpleName,
728 mInflateInitialLayoutDurationMs, TimeUnit.MILLISECON DS);
729 mToolbarManager.onDeferredStartup(getOnCreateTimestampMs(), simpleName);
730 }
731 713
732 if (MultiWindowUtils.getInstance().isInMultiWindowMode(ChromeAct ivity.this)) { 714 if (mToolbarManager != null) {
733 onDeferredStartupForMultiWindowMode(); 715 String simpleName = getClass().getSimpleName();
734 } 716 RecordHistogram.recordTimesHistogram("MobileStartup.ToolbarInflation Time." + simpleName,
735 } 717 mInflateInitialLayoutDurationMs, TimeUnit.MILLISECONDS);
736 }); 718 mToolbarManager.onDeferredStartup(getOnCreateTimestampMs(), simpleNa me);
719 }
720
721 if (MultiWindowUtils.getInstance().isInMultiWindowMode(this)) {
722 onDeferredStartupForMultiWindowMode();
723 }
737 } 724 }
738 725
739 /** 726 /**
740 * Actions that may be run at some point after startup for Android N multi-w indow mode. Should 727 * Actions that may be run at some point after startup for Android N multi-w indow mode. Should
741 * be called from #onDeferredStartup() if the activity is in multi-window mo de. 728 * be called from #onDeferredStartup() if the activity is in multi-window mo de.
742 */ 729 */
743 protected void onDeferredStartupForMultiWindowMode() { 730 protected void onDeferredStartupForMultiWindowMode() {
744 // If the Activity was launched in multi-window mode, record a user acti on and the screen 731 // If the Activity was launched in multi-window mode, record a user acti on and the screen
745 // width. 732 // width.
746 recordMultiWindowModeChangedUserAction(true); 733 recordMultiWindowModeChangedUserAction(true);
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 1634
1648 private int displayArea() { 1635 private int displayArea() {
1649 if (getResources() != null && getResources().getDisplayMetrics() != null ) { 1636 if (getResources() != null && getResources().getDisplayMetrics() != null ) {
1650 DisplayMetrics metrics = getResources().getDisplayMetrics(); 1637 DisplayMetrics metrics = getResources().getDisplayMetrics();
1651 return metrics.heightPixels * metrics.widthPixels; 1638 return metrics.heightPixels * metrics.widthPixels;
1652 } 1639 }
1653 return -1; 1640 return -1;
1654 } 1641 }
1655 1642
1656 protected final void postDeferredStartupIfNeeded() { 1643 protected final void postDeferredStartupIfNeeded() {
1657 if (!mDeferredStartupPosted) { 1644 if (!mDeferredStartupNotified) {
1658 mDeferredStartupPosted = true;
1659 RecordHistogram.recordLongTimesHistogram( 1645 RecordHistogram.recordLongTimesHistogram(
1660 "UMA.Debug.EnableCrashUpload.PostDeferredStartUptime2", 1646 "UMA.Debug.EnableCrashUpload.PostDeferredStartUptime",
1661 SystemClock.uptimeMillis() - UmaUtils.getForegroundStartTime (), 1647 SystemClock.uptimeMillis() - UmaUtils.getMainEntryPointTime( ),
1662 TimeUnit.MILLISECONDS); 1648 TimeUnit.MILLISECONDS);
1663 onDeferredStartup(); 1649
1650 // We want to perform deferred startup tasks a short time after the first page
1651 // load completes, but only when the main thread Looper has become i dle.
1652 mHandler.postDelayed(new Runnable() {
1653 @Override
1654 public void run() {
1655 if (!mDeferredStartupNotified && !isActivityDestroyed()) {
1656 mDeferredStartupNotified = true;
1657 Looper.myQueue().addIdleHandler(new MessageQueue.IdleHan dler() {
1658 @Override
1659 public boolean queueIdle() {
1660 onDeferredStartup();
1661 return false; // Remove this idle handler.
1662 }
1663 });
1664 }
1665 }
1666 }, DEFERRED_STARTUP_DELAY_MS);
1664 } 1667 }
1665 } 1668 }
1666 1669
1667 /** 1670 /**
1668 * Determines whether the ContentView is currently visible and not hidden by an overlay 1671 * Determines whether the ContentView is currently visible and not hidden by an overlay
1669 * @return true if the ContentView is fully hidden by another view (i.e. the tab stack) 1672 * @return true if the ContentView is fully hidden by another view (i.e. the tab stack)
1670 */ 1673 */
1671 public boolean isOverlayVisible() { 1674 public boolean isOverlayVisible() {
1672 return false; 1675 return false;
1673 } 1676 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 "Android.MultiWindowMode.IsTabletScreenWidthBelow600", 1752 "Android.MultiWindowMode.IsTabletScreenWidthBelow600",
1750 mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP); 1753 mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP);
1751 1754
1752 if (mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) { 1755 if (mScreenWidthDp < DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP) {
1753 RecordHistogram.recordLinearCountHistogram( 1756 RecordHistogram.recordLinearCountHistogram(
1754 "Android.MultiWindowMode.TabletScreenWidth", mScreenWidthDp, 1, 1757 "Android.MultiWindowMode.TabletScreenWidth", mScreenWidthDp, 1,
1755 DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP, 50); 1758 DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP, 50);
1756 } 1759 }
1757 } 1760 }
1758 } 1761 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ChromeApplication.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698