| OLD | NEW |
| 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.ntp; | 5 package org.chromium.chrome.browser.ntp; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.SharedPreferences; | 8 import android.content.SharedPreferences; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.preference.PreferenceManager; | 10 import android.preference.PreferenceManager; |
| 11 | 11 |
| 12 import org.chromium.base.ObserverList; | |
| 13 import org.chromium.base.ThreadUtils; | 12 import org.chromium.base.ThreadUtils; |
| 14 import org.chromium.chrome.browser.UrlConstants; | 13 import org.chromium.chrome.browser.UrlConstants; |
| 15 import org.chromium.chrome.browser.favicon.FaviconHelper; | 14 import org.chromium.chrome.browser.favicon.FaviconHelper; |
| 16 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | 15 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; |
| 17 import org.chromium.chrome.browser.firstrun.ProfileDataCache; | |
| 18 import org.chromium.chrome.browser.invalidation.InvalidationController; | 16 import org.chromium.chrome.browser.invalidation.InvalidationController; |
| 19 import org.chromium.chrome.browser.metrics.StartupMetrics; | 17 import org.chromium.chrome.browser.metrics.StartupMetrics; |
| 20 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession; | 18 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSession; |
| 21 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionCallba
ck; | 19 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionCallba
ck; |
| 22 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionTab; | 20 import org.chromium.chrome.browser.ntp.ForeignSessionHelper.ForeignSessionTab; |
| 23 import org.chromium.chrome.browser.ntp.RecentTabsPromoView.SyncPromoModel; | |
| 24 import org.chromium.chrome.browser.ntp.RecentlyClosedBridge.RecentlyClosedCallba
ck; | 21 import org.chromium.chrome.browser.ntp.RecentlyClosedBridge.RecentlyClosedCallba
ck; |
| 25 import org.chromium.chrome.browser.ntp.RecentlyClosedBridge.RecentlyClosedTab; | 22 import org.chromium.chrome.browser.ntp.RecentlyClosedBridge.RecentlyClosedTab; |
| 26 import org.chromium.chrome.browser.profiles.Profile; | 23 import org.chromium.chrome.browser.profiles.Profile; |
| 27 import org.chromium.chrome.browser.signin.SigninAccessPoint; | |
| 28 import org.chromium.chrome.browser.signin.SigninManager; | 24 import org.chromium.chrome.browser.signin.SigninManager; |
| 29 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; | 25 import org.chromium.chrome.browser.signin.SigninManager.SignInStateObserver; |
| 30 import org.chromium.chrome.browser.sync.ProfileSyncService; | |
| 31 import org.chromium.chrome.browser.tab.Tab; | 26 import org.chromium.chrome.browser.tab.Tab; |
| 32 import org.chromium.content_public.browser.LoadUrlParams; | 27 import org.chromium.content_public.browser.LoadUrlParams; |
| 33 import org.chromium.sync.AndroidSyncSettings; | 28 import org.chromium.sync.AndroidSyncSettings; |
| 34 import org.chromium.sync.AndroidSyncSettings.AndroidSyncSettingsObserver; | 29 import org.chromium.sync.AndroidSyncSettings.AndroidSyncSettingsObserver; |
| 35 import org.chromium.sync.signin.ChromeSigninController; | 30 import org.chromium.sync.signin.ChromeSigninController; |
| 36 | 31 |
| 37 import java.util.Collections; | 32 import java.util.Collections; |
| 38 import java.util.List; | 33 import java.util.List; |
| 39 | 34 |
| 40 /** | 35 /** |
| 41 * Provides the domain logic and data for RecentTabsPage and RecentTabsRowAdapte
r. | 36 * Provides the domain logic and data for RecentTabsPage and RecentTabsRowAdapte
r. |
| 42 */ | 37 */ |
| 43 public class RecentTabsManager implements AndroidSyncSettingsObserver, SignInSta
teObserver, | 38 public class RecentTabsManager implements AndroidSyncSettingsObserver, SignInSta
teObserver { |
| 44 SyncPromoModel { | |
| 45 | 39 |
| 46 /** | 40 /** |
| 47 * Implement this to receive updates when the page contents change. | 41 * Implement this to receive updates when the page contents change. |
| 48 */ | 42 */ |
| 49 interface UpdatedCallback { | 43 interface UpdatedCallback { |
| 50 /** | 44 /** |
| 51 * Called when the list of recently closed tabs or foreign sessions chan
ges. | 45 * Called when the list of recently closed tabs or foreign sessions chan
ges. |
| 52 */ | 46 */ |
| 53 void onUpdated(); | 47 void onUpdated(); |
| 54 } | 48 } |
| 55 | 49 |
| 56 private static final int RECENTLY_CLOSED_MAX_TAB_COUNT = 5; | 50 private static final int RECENTLY_CLOSED_MAX_TAB_COUNT = 5; |
| 57 private static final String PREF_SIGNIN_PROMO_DECLINED = | 51 private static final String PREF_SIGNIN_PROMO_DECLINED = |
| 58 "recent_tabs_signin_promo_declined"; | 52 "recent_tabs_signin_promo_declined"; |
| 59 | 53 |
| 60 private final Profile mProfile; | 54 private final Profile mProfile; |
| 61 private final Tab mTab; | 55 private final Tab mTab; |
| 62 private final Context mContext; | 56 private final Context mContext; |
| 63 private final ObserverList<AndroidSyncSettingsObserver> mObservers = | |
| 64 new ObserverList<AndroidSyncSettingsObserver>(); | |
| 65 | 57 |
| 66 private FaviconHelper mFaviconHelper; | 58 private FaviconHelper mFaviconHelper; |
| 67 private ForeignSessionHelper mForeignSessionHelper; | 59 private ForeignSessionHelper mForeignSessionHelper; |
| 68 private List<ForeignSession> mForeignSessions; | 60 private List<ForeignSession> mForeignSessions; |
| 69 private List<RecentlyClosedTab> mRecentlyClosedTabs; | 61 private List<RecentlyClosedTab> mRecentlyClosedTabs; |
| 70 private NewTabPagePrefs mNewTabPagePrefs; | 62 private NewTabPagePrefs mNewTabPagePrefs; |
| 71 private RecentlyClosedBridge mRecentlyClosedBridge; | 63 private RecentlyClosedBridge mRecentlyClosedBridge; |
| 72 private SigninManager mSignInManager; | 64 private SigninManager mSignInManager; |
| 73 private UpdatedCallback mUpdatedCallback; | 65 private UpdatedCallback mUpdatedCallback; |
| 74 private ProfileDataCache mProfileDataCache; | |
| 75 private boolean mIsDestroyed; | 66 private boolean mIsDestroyed; |
| 76 | 67 |
| 77 /** | 68 /** |
| 78 * Create an RecentTabsManager to be used with RecentTabsPage and RecentTabs
RowAdapter. | 69 * Create an RecentTabsManager to be used with RecentTabsPage and RecentTabs
RowAdapter. |
| 79 * | 70 * |
| 80 * @param tab The Tab that is showing this recent tabs page. | 71 * @param tab The Tab that is showing this recent tabs page. |
| 81 * @param profile Profile that is associated with the current session. | 72 * @param profile Profile that is associated with the current session. |
| 82 * @param context the Android context this manager will work in. | 73 * @param context the Android context this manager will work in. |
| 83 */ | 74 */ |
| 84 public RecentTabsManager(Tab tab, Profile profile, Context context) { | 75 public RecentTabsManager(Tab tab, Profile profile, Context context) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 mRecentlyClosedBridge = null; | 108 mRecentlyClosedBridge = null; |
| 118 | 109 |
| 119 mForeignSessionHelper.destroy(); | 110 mForeignSessionHelper.destroy(); |
| 120 mForeignSessionHelper = null; | 111 mForeignSessionHelper = null; |
| 121 | 112 |
| 122 mUpdatedCallback = null; | 113 mUpdatedCallback = null; |
| 123 | 114 |
| 124 mNewTabPagePrefs.destroy(); | 115 mNewTabPagePrefs.destroy(); |
| 125 mNewTabPagePrefs = null; | 116 mNewTabPagePrefs = null; |
| 126 | 117 |
| 127 if (mProfileDataCache != null) { | |
| 128 mProfileDataCache.destroy(); | |
| 129 mProfileDataCache = null; | |
| 130 } | |
| 131 | |
| 132 InvalidationController.get(mContext).onRecentTabsPageClosed(); | 118 InvalidationController.get(mContext).onRecentTabsPageClosed(); |
| 133 } | 119 } |
| 134 | 120 |
| 135 /** | 121 /** |
| 136 * Returns true if destroy() has been called. | 122 * Returns true if destroy() has been called. |
| 137 */ | 123 */ |
| 138 public boolean isDestroyed() { | 124 public boolean isDestroyed() { |
| 139 return mIsDestroyed; | 125 return mIsDestroyed; |
| 140 } | 126 } |
| 141 | 127 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 440 |
| 455 // AndroidSyncSettingsObserver | 441 // AndroidSyncSettingsObserver |
| 456 @Override | 442 @Override |
| 457 public void androidSyncSettingsChanged() { | 443 public void androidSyncSettingsChanged() { |
| 458 ThreadUtils.runOnUiThread(new Runnable() { | 444 ThreadUtils.runOnUiThread(new Runnable() { |
| 459 @Override | 445 @Override |
| 460 public void run() { | 446 public void run() { |
| 461 if (mIsDestroyed) return; | 447 if (mIsDestroyed) return; |
| 462 updateForeignSessions(); | 448 updateForeignSessions(); |
| 463 postUpdate(); | 449 postUpdate(); |
| 464 for (AndroidSyncSettingsObserver observer : mObservers) { | |
| 465 observer.androidSyncSettingsChanged(); | |
| 466 } | |
| 467 } | 450 } |
| 468 }); | 451 }); |
| 469 } | 452 } |
| 470 | 453 |
| 471 // SyncPromoModel | |
| 472 @Override | |
| 473 public boolean isSyncEnabled() { | |
| 474 return AndroidSyncSettings.isSyncEnabled(mContext); | |
| 475 } | |
| 476 | |
| 477 @Override | |
| 478 public boolean isSignedIn() { | 454 public boolean isSignedIn() { |
| 479 return ChromeSigninController.get(mContext).isSignedIn(); | 455 return ChromeSigninController.get(mContext).isSignedIn(); |
| 480 } | 456 } |
| 481 | |
| 482 @Override | |
| 483 public void enableSync() { | |
| 484 ProfileSyncService syncService = ProfileSyncService.get(); | |
| 485 if (syncService != null) { | |
| 486 syncService.requestStart(); | |
| 487 } | |
| 488 } | |
| 489 | |
| 490 @Override | |
| 491 public void registerForSyncUpdates(AndroidSyncSettingsObserver changeListene
r) { | |
| 492 mObservers.addObserver(changeListener); | |
| 493 } | |
| 494 | |
| 495 @Override | |
| 496 public void unregisterForSyncUpdates(AndroidSyncSettingsObserver changeListe
ner) { | |
| 497 mObservers.removeObserver(changeListener); | |
| 498 } | |
| 499 | |
| 500 @Override | |
| 501 public ProfileDataCache getProfileDataCache() { | |
| 502 if (mProfileDataCache == null) { | |
| 503 mProfileDataCache = new ProfileDataCache(mContext, Profile.getLastUs
edProfile()); | |
| 504 } | |
| 505 return mProfileDataCache; | |
| 506 } | |
| 507 | |
| 508 @Override | |
| 509 public int getAccessPoint() { | |
| 510 return SigninAccessPoint.RECENT_TABS; | |
| 511 } | |
| 512 } | 457 } |
| OLD | NEW |