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

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

Issue 2599743002: Trigger the Snippets Scheduler when Resuming Activities (Closed)
Patch Set: Two separate signals instead of boolean value. 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 unified diff | Download patch
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.ActivityManager; 10 import android.app.ActivityManager;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 import org.chromium.chrome.browser.incognito.IncognitoNotificationManager; 73 import org.chromium.chrome.browser.incognito.IncognitoNotificationManager;
74 import org.chromium.chrome.browser.infobar.DataReductionPromoInfoBar; 74 import org.chromium.chrome.browser.infobar.DataReductionPromoInfoBar;
75 import org.chromium.chrome.browser.locale.LocaleManager; 75 import org.chromium.chrome.browser.locale.LocaleManager;
76 import org.chromium.chrome.browser.metrics.ActivityStopMetrics; 76 import org.chromium.chrome.browser.metrics.ActivityStopMetrics;
77 import org.chromium.chrome.browser.metrics.LaunchMetrics; 77 import org.chromium.chrome.browser.metrics.LaunchMetrics;
78 import org.chromium.chrome.browser.metrics.StartupMetrics; 78 import org.chromium.chrome.browser.metrics.StartupMetrics;
79 import org.chromium.chrome.browser.metrics.UmaUtils; 79 import org.chromium.chrome.browser.metrics.UmaUtils;
80 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; 80 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils;
81 import org.chromium.chrome.browser.ntp.NativePageAssassin; 81 import org.chromium.chrome.browser.ntp.NativePageAssassin;
82 import org.chromium.chrome.browser.ntp.NewTabPageUma; 82 import org.chromium.chrome.browser.ntp.NewTabPageUma;
83 import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
84 import org.chromium.chrome.browser.ntp.snippets.SnippetsConfig;
83 import org.chromium.chrome.browser.omaha.OmahaClient; 85 import org.chromium.chrome.browser.omaha.OmahaClient;
84 import org.chromium.chrome.browser.omnibox.AutocompleteController; 86 import org.chromium.chrome.browser.omnibox.AutocompleteController;
85 import org.chromium.chrome.browser.partnercustomizations.HomepageManager; 87 import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
86 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza tions; 88 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza tions;
87 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 89 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
88 import org.chromium.chrome.browser.preferences.PrefServiceBridge; 90 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
89 import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoS creen; 91 import org.chromium.chrome.browser.preferences.datareduction.DataReductionPromoS creen;
90 import org.chromium.chrome.browser.signin.SigninPromoUtil; 92 import org.chromium.chrome.browser.signin.SigninPromoUtil;
91 import org.chromium.chrome.browser.snackbar.undo.UndoBarController; 93 import org.chromium.chrome.browser.snackbar.undo.UndoBarController;
92 import org.chromium.chrome.browser.tab.BrowserControlsVisibilityDelegate; 94 import org.chromium.chrome.browser.tab.BrowserControlsVisibilityDelegate;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 private boolean mCreatedTabOnStartup; 224 private boolean mCreatedTabOnStartup;
223 225
224 // Whether or not chrome was launched with an intent to open a tab. 226 // Whether or not chrome was launched with an intent to open a tab.
225 private boolean mIntentWithEffect; 227 private boolean mIntentWithEffect;
226 228
227 // Time at which an intent was received and handled. 229 // Time at which an intent was received and handled.
228 private long mIntentHandlingTimeMs; 230 private long mIntentHandlingTimeMs;
229 231
230 private VrShellDelegate mVrShellDelegate; 232 private VrShellDelegate mVrShellDelegate;
231 233
234 private ApplicationStatus.ActivityStateListener mSnippetsSchedulerListener;
235
232 private class TabbedAssistStatusHandler extends AssistStatusHandler { 236 private class TabbedAssistStatusHandler extends AssistStatusHandler {
233 public TabbedAssistStatusHandler(Activity activity) { 237 public TabbedAssistStatusHandler(Activity activity) {
234 super(activity); 238 super(activity);
235 } 239 }
236 240
237 @Override 241 @Override
238 public boolean isAssistSupported() { 242 public boolean isAssistSupported() {
239 // If we are in the tab switcher and any incognito tabs are present, disable assist. 243 // If we are in the tab switcher and any incognito tabs are present, disable assist.
240 if (isInOverviewMode() && mTabModelSelectorImpl != null 244 if (isInOverviewMode() && mTabModelSelectorImpl != null
241 && mTabModelSelectorImpl.getModel(true).getCount() > 0) { 245 && mTabModelSelectorImpl.getModel(true).getCount() > 0) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 401
398 // Check for incognito tabs to handle the case where Chrome was swip ed away in the 402 // Check for incognito tabs to handle the case where Chrome was swip ed away in the
399 // background. 403 // background.
400 int incognitoCount = TabWindowManager.getInstance().getIncognitoTabC ount(); 404 int incognitoCount = TabWindowManager.getInstance().getIncognitoTabC ount();
401 if (incognitoCount == 0) IncognitoNotificationManager.dismissIncogni toNotification(); 405 if (incognitoCount == 0) IncognitoNotificationManager.dismissIncogni toNotification();
402 406
403 // LocaleManager can only function after the native library is loade d. 407 // LocaleManager can only function after the native library is loade d.
404 mLocaleManager = LocaleManager.getInstance(); 408 mLocaleManager = LocaleManager.getInstance();
405 mLocaleManager.showSearchEnginePromoIfNeeded(this); 409 mLocaleManager.showSearchEnginePromoIfNeeded(this);
406 410
411 if (SnippetsConfig.isEnabled()) {
412 // The SnippetsBridge propagates the state changes so the schedu ler can post
413 // deferred tasks to refresh outdated snippets.
414 mSnippetsSchedulerListener = SnippetsBridge.makeActivityStateLis tener();
415 ApplicationStatus.registerStateListenerForActivity(
416 mSnippetsSchedulerListener, this);
417 }
418
407 super.finishNativeInitialization(); 419 super.finishNativeInitialization();
408 } finally { 420 } finally {
409 TraceEvent.end("ChromeTabbedActivity.finishNativeInitialization"); 421 TraceEvent.end("ChromeTabbedActivity.finishNativeInitialization");
410 } 422 }
411 } 423 }
412 424
413 @Override 425 @Override
414 public void onResumeWithNative() { 426 public void onResumeWithNative() {
415 super.onResumeWithNative(); 427 super.onResumeWithNative();
416 428
417 CookiesFetcher.restoreCookies(this); 429 CookiesFetcher.restoreCookies(this);
418 StartupMetrics.getInstance().recordHistogram(false); 430 StartupMetrics.getInstance().recordHistogram(false);
419 431
420 if (FeatureUtilities.isTabModelMergingEnabled()) { 432 if (FeatureUtilities.isTabModelMergingEnabled()) {
421 boolean inMultiWindowMode = MultiWindowUtils.getInstance().isInMulti WindowMode(this); 433 boolean inMultiWindowMode = MultiWindowUtils.getInstance().isInMulti WindowMode(this);
422 // Merge tabs if the activity is not in multi-window mode and mMerge TabsOnResume is true 434 // Merge tabs if the activity is not in multi-window mode and mMerge TabsOnResume is true
423 // or unset because the activity is just starting or was destroyed. 435 // or unset because the activity is just starting or was destroyed.
424 if (!inMultiWindowMode && (mMergeTabsOnResume == null || mMergeTabsO nResume)) { 436 if (!inMultiWindowMode && (mMergeTabsOnResume == null || mMergeTabsO nResume)) {
425 maybeMergeTabs(); 437 maybeMergeTabs();
426 } 438 }
427 mMergeTabsOnResume = false; 439 mMergeTabsOnResume = false;
428 } 440 }
429 mVrShellDelegate.maybeResumeVR(); 441 mVrShellDelegate.maybeResumeVR();
430 442
431 mLocaleManager.setSnackbarManager(getSnackbarManager()); 443 mLocaleManager.setSnackbarManager(getSnackbarManager());
432 mLocaleManager.startObservingPhoneChanges(); 444 mLocaleManager.startObservingPhoneChanges();
445
446 // Without any interaction, this start was cold and the listener will ig nore it.
Michael van Ouwerkerk 2017/01/04 14:32:17 Without user interaction, it is the start of the a
fhorschig 2017/01/04 15:04:44 Good lead, added a check and a warm alternative ca
447 if (SnippetsConfig.isEnabled() && getLastUserInteractionTime() == 0) {
448 SnippetsBridge.notifySchedulerAboutColdStart();
449 }
433 } 450 }
434 451
435 @Override 452 @Override
436 public void onPauseWithNative() { 453 public void onPauseWithNative() {
437 mTabModelSelectorImpl.commitAllTabClosures(); 454 mTabModelSelectorImpl.commitAllTabClosures();
438 CookiesFetcher.persistCookies(this); 455 CookiesFetcher.persistCookies(this);
439 mVrShellDelegate.maybePauseVR(); 456 mVrShellDelegate.maybePauseVR();
440 457
441 mLocaleManager.setSnackbarManager(null); 458 mLocaleManager.setSnackbarManager(null);
442 mLocaleManager.stopObservingPhoneChanges(); 459 mLocaleManager.stopObservingPhoneChanges();
(...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 1454
1438 if (mUndoBarPopupController != null) { 1455 if (mUndoBarPopupController != null) {
1439 mUndoBarPopupController.destroy(); 1456 mUndoBarPopupController.destroy();
1440 mUndoBarPopupController = null; 1457 mUndoBarPopupController = null;
1441 } 1458 }
1442 1459
1443 if (mVrShellDelegate != null) { 1460 if (mVrShellDelegate != null) {
1444 mVrShellDelegate.destroyVrShell(); 1461 mVrShellDelegate.destroyVrShell();
1445 } 1462 }
1446 1463
1464 if (mSnippetsSchedulerListener != null) {
1465 ApplicationStatus.unregisterActivityStateListener(mSnippetsScheduler Listener);
1466 mSnippetsSchedulerListener = null;
1467 }
1468
1447 super.onDestroyInternal(); 1469 super.onDestroyInternal();
1448 } 1470 }
1449 1471
1450 @Override 1472 @Override
1451 public void onTrimMemory(int level) { 1473 public void onTrimMemory(int level) {
1452 super.onTrimMemory(level); 1474 super.onTrimMemory(level);
1453 // The conditions are expressed using ranges to capture intermediate lev els possibly added 1475 // The conditions are expressed using ranges to capture intermediate lev els possibly added
1454 // to the API in the future. 1476 // to the API in the future.
1455 if ((level >= TRIM_MEMORY_RUNNING_LOW && level < TRIM_MEMORY_UI_HIDDEN) 1477 if ((level >= TRIM_MEMORY_RUNNING_LOW && level < TRIM_MEMORY_UI_HIDDEN)
1456 || level >= TRIM_MEMORY_MODERATE) { 1478 || level >= TRIM_MEMORY_MODERATE) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 1725
1704 ActivityManager manager = (ActivityManager) getSystemService(Context.ACT IVITY_SERVICE); 1726 ActivityManager manager = (ActivityManager) getSystemService(Context.ACT IVITY_SERVICE);
1705 for (AppTask task : manager.getAppTasks()) { 1727 for (AppTask task : manager.getAppTasks()) {
1706 RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task); 1728 RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
1707 if (info == null) continue; 1729 if (info == null) continue;
1708 if (info.id == sMergedInstanceTaskId) return true; 1730 if (info.id == sMergedInstanceTaskId) return true;
1709 } 1731 }
1710 return false; 1732 return false;
1711 } 1733 }
1712 } 1734 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698