Ejemplo n.º 1
0
 @VisibleForTesting
 protected boolean isSyncAllowed() {
   SigninManager signinManager = SigninManager.get(mActivity.getApplicationContext());
   return FeatureUtilities.canAllowSync(mActivity)
       && !signinManager.isSigninDisabledByPolicy()
       && signinManager.isSigninSupported();
 }
  /**
   * Determine whether the sync promo needs to be displayed.
   *
   * @return Whether sync promo should be displayed.
   */
  public boolean shouldDisplaySyncPromo() {
    if (SigninManager.get(mContext).isSigninDisabledByPolicy()) {
      return false;
    }

    if (ContextUtils.getAppSharedPreferences().getBoolean(PREF_SIGNIN_PROMO_DECLINED, false)) {
      return false;
    }

    return !AndroidSyncSettings.isSyncEnabled(mContext) || mForeignSessions.isEmpty();
  }
  /**
   * Create an RecentTabsManager to be used with RecentTabsPage and RecentTabsRowAdapter.
   *
   * @param tab The Tab that is showing this recent tabs page.
   * @param profile Profile that is associated with the current session.
   * @param context the Android context this manager will work in.
   */
  public RecentTabsManager(Tab tab, Profile profile, Context context) {
    mProfile = profile;
    mTab = tab;
    mForeignSessionHelper = buildForeignSessionHelper(mProfile);
    mNewTabPagePrefs = buildNewTabPagePrefs(mProfile);
    mFaviconHelper = buildFaviconHelper();
    mRecentlyClosedBridge = buildRecentlyClosedBridge(mProfile);
    mSignInManager = SigninManager.get(context);
    mContext = context;

    updateRecentlyClosedTabs();
    registerForForeignSessionUpdates();
    updateForeignSessions();
    mForeignSessionHelper.triggerSessionSync();
    registerForSignInAndSyncNotifications();

    InvalidationController.get(mContext).onRecentTabsPageOpened();
  }
  /**
   * Should be called when this object is no longer needed. Performs necessary listener tear down.
   */
  public void destroy() {
    mIsDestroyed = true;
    AndroidSyncSettings.unregisterObserver(mContext, this);

    mSignInManager.removeSignInStateObserver(this);
    mSignInManager = null;

    mFaviconHelper.destroy();
    mFaviconHelper = null;

    mRecentlyClosedBridge.destroy();
    mRecentlyClosedBridge = null;

    mForeignSessionHelper.destroy();
    mForeignSessionHelper = null;

    mUpdatedCallback = null;

    mNewTabPagePrefs.destroy();
    mNewTabPagePrefs = null;

    InvalidationController.get(mContext).onRecentTabsPageClosed();
  }
 private void registerForSignInAndSyncNotifications() {
   AndroidSyncSettings.registerObserver(mContext, this);
   mSignInManager.addSignInStateObserver(this);
 }