/**
   * 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();
  }
    private BookmarkNode loadBookmarkFolder(long folderId) {
      if (ThreadUtils.runningOnUiThread()) {
        Log.e(TAG, "Trying to load bookmark folder from the UI thread.");
        return null;
      }

      // If the current folder id doesn't exist (it was deleted) try the current parent.
      // If this fails too then fallback to Mobile Bookmarks.
      if (!ChromeBrowserProviderClient.bookmarkNodeExists(mContext, folderId)) {
        folderId =
            mCurrentFolder != null
                ? getFolderId(mCurrentFolder.parent())
                : ChromeBrowserProviderClient.INVALID_BOOKMARK_ID;
        if (!ChromeBrowserProviderClient.bookmarkNodeExists(mContext, folderId)) {
          folderId = ChromeBrowserProviderClient.INVALID_BOOKMARK_ID;
        }
      }

      // Need to verify this always because the package data might be cleared while the
      // widget is in the Mobile Bookmarks folder with sync enabled. In that case the
      // hierarchy up folder would still work (we can't update the widget) but the parent
      // folders should not be accessible because sync has been reset when clearing data.
      if (folderId != ChromeBrowserProviderClient.INVALID_BOOKMARK_ID
          && !AndroidSyncSettings.isSyncEnabled(mContext)
          && !ChromeBrowserProviderClient.isBookmarkInMobileBookmarksBranch(mContext, folderId)) {
        folderId = ChromeBrowserProviderClient.INVALID_BOOKMARK_ID;
      }

      // Use the Mobile Bookmarks folder by default.
      if (folderId < 0 || folderId == ChromeBrowserProviderClient.INVALID_BOOKMARK_ID) {
        folderId = ChromeBrowserProviderClient.getMobileBookmarksFolderId(mContext);
        if (folderId == ChromeBrowserProviderClient.INVALID_BOOKMARK_ID) return null;
      }

      return ChromeBrowserProviderClient.getBookmarkNode(
          mContext,
          folderId,
          ChromeBrowserProviderClient.GET_PARENT
              | ChromeBrowserProviderClient.GET_CHILDREN
              | ChromeBrowserProviderClient.GET_FAVICONS
              | ChromeBrowserProviderClient.GET_THUMBNAILS);
    }
  /**
   * 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);
 }