[Bookmarks Bar] Update naming of utils methods for clarity This CL has no functional changes. We update some naming of utils methods to make it clearer when we add a new parallel preference in upcoming CLs. Bug: 440359932 Change-Id: I2685a35508ecb2e131f4c076da25a64713a703b9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6872471 Auto-Submit: Mark Schillaci <mschillaci@google.com> Commit-Queue: Mark Schillaci <mschillaci@google.com> Reviewed-by: Eleanor Lee <eleanorlee@google.com> Reviewed-by: Calder Kitagawa <ckitagawa@chromium.org> Cr-Commit-Position: refs/heads/main@{#1505887}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/appearance/settings/AppearanceSettingsFragment.java b/chrome/android/java/src/org/chromium/chrome/browser/appearance/settings/AppearanceSettingsFragment.java index 165af63..8aa952d8 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/appearance/settings/AppearanceSettingsFragment.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/appearance/settings/AppearanceSettingsFragment.java
@@ -107,7 +107,8 @@ ((ChromeSwitchPreference) findPreference(PREF_BOOKMARK_BAR)) .setOnPreferenceChangeListener( (pref, newValue) -> { - BookmarkBarUtils.setSettingEnabled(getProfile(), (boolean) newValue); + BookmarkBarUtils.setUserPrefsShowBookmarksBar( + getProfile(), (boolean) newValue); return true; }); } @@ -144,7 +145,7 @@ private void updateBookmarkBarPref() { if (BookmarkBarUtils.isDeviceBookmarkBarCompatible(getContext())) { ((ChromeSwitchPreference) findPreference(PREF_BOOKMARK_BAR)) - .setChecked(BookmarkBarUtils.isSettingEnabled(getProfile())); + .setChecked(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(getProfile())); } }
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabbed_mode/TabbedRootUiCoordinator.java b/chrome/android/java/src/org/chromium/chrome/browser/tabbed_mode/TabbedRootUiCoordinator.java index f34d738b..367028eb 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tabbed_mode/TabbedRootUiCoordinator.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tabbed_mode/TabbedRootUiCoordinator.java
@@ -1899,7 +1899,7 @@ return true; } else if (id == R.id.toggle_bookmark_bar) { if (BookmarkBarUtils.isActivityStateBookmarkBarCompatible(mActivity)) { - BookmarkBarUtils.toggleSettingEnabled(mProfileSupplier.get()); + BookmarkBarUtils.toggleUserPrefsShowBookmarksBar(mProfileSupplier.get()); return true; } }
diff --git a/chrome/browser/bookmarks/android/java/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarUtils.java b/chrome/browser/bookmarks/android/java/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarUtils.java index b75118be..1071ab5 100644 --- a/chrome/browser/bookmarks/android/java/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarUtils.java +++ b/chrome/browser/bookmarks/android/java/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarUtils.java
@@ -111,55 +111,6 @@ } /** - * Returns true if the Bookmark Bar currently visible. The feature is visible when it is allowed - * in the given context and the user setting for the given profile is enabled. - * - * @param context The context in which compatibility should be assessed. - * @param profile The profile for which the user setting should be assessed. - * @return Whether the Bookmark Bar is currently visible. - */ - public static boolean isBookmarkBarVisible(Context context, @Nullable Profile profile) { - if (sBookmarkBarVisibleForTesting != null) { - return sBookmarkBarVisibleForTesting; - } - return isActivityStateBookmarkBarCompatible(context) && isSettingEnabled(profile); - } - - /** - * Returns whether the bookmark bar user setting is currently enabled. - * - * @param profile The profile for which the user setting should be assessed. - * @return Whether the user setting is currently enabled. - */ - public static boolean isSettingEnabled(@Nullable Profile profile) { - if (sSettingEnabledForTesting != null) { - return sSettingEnabledForTesting; - } - return profile != null ? getPrefService(profile).getBoolean(Pref.SHOW_BOOKMARK_BAR) : false; - } - - /** - * Sets whether the bookmark bar user setting is currently enabled. - * - * @param profile The profile for which the user setting should be set. - * @param enabled Whether the user setting should be set to enabled/disabled. - */ - public static void setSettingEnabled(Profile profile, boolean enabled) { - getPrefService(profile).setBoolean(Pref.SHOW_BOOKMARK_BAR, enabled); - } - - /** - * Toggles whether the bookmark bar user setting is currently enabled. - * - * @param profile The profile for which the user setting should be toggled. - */ - public static void toggleSettingEnabled(Profile profile) { - final var prefService = getPrefService(profile); - prefService.setBoolean( - Pref.SHOW_BOOKMARK_BAR, !prefService.getBoolean(Pref.SHOW_BOOKMARK_BAR)); - } - - /** * Returns true if the current activity window is compatible with the Bookmark Bar. The Bookmark * Bar is disabled for narrow windows, so the window size needs to be of sufficient width for * the Bookmark Bar to be displayed. The current requirement is a width >= 412dp, see {@link @@ -176,6 +127,61 @@ } /** + * Returns true if the Bookmark Bar currently visible. The feature is visible when it is allowed + * in the given context, and the show bookmark bar UserPref is enabled for the current user. + * + * @param context The context in which compatibility should be assessed. + * @param profile The profile for which the user UserPref should be assessed. + * @return Whether the Bookmark Bar is currently visible. + */ + public static boolean isBookmarkBarVisible(Context context, @Nullable Profile profile) { + if (sBookmarkBarVisibleForTesting != null) { + return sBookmarkBarVisibleForTesting; + } + + if (!isActivityStateBookmarkBarCompatible(context)) { + return false; + } + + return isUserPrefsShowBookmarksBarEnabled(profile); + } + + /** + * Returns whether the bookmark bar should be shown based on the current user's UserPrefs. Note: + * This is synced across devices for the user's profile. + * + * @param profile The profile for which the UserPref should be assessed. + * @return The user's current preference for showing the bookmark bar. + */ + public static boolean isUserPrefsShowBookmarksBarEnabled(@Nullable Profile profile) { + if (sSettingEnabledForTesting != null) { + return sSettingEnabledForTesting; + } + return profile != null ? getPrefService(profile).getBoolean(Pref.SHOW_BOOKMARK_BAR) : false; + } + + /** + * Sets whether the bookmark bar user setting is currently enabled. + * + * @param profile The profile for which the user setting should be set. + * @param enabled Whether the user setting should be set to enabled/disabled. + */ + public static void setUserPrefsShowBookmarksBar(Profile profile, boolean enabled) { + getPrefService(profile).setBoolean(Pref.SHOW_BOOKMARK_BAR, enabled); + } + + /** + * Toggles the value of the show bookmarks bar UserPref for the current user. + * + * @param profile The profile for which the UserPref should be toggled. + */ + public static void toggleUserPrefsShowBookmarksBar(Profile profile) { + final var prefService = getPrefService(profile); + prefService.setBoolean( + Pref.SHOW_BOOKMARK_BAR, !prefService.getBoolean(Pref.SHOW_BOOKMARK_BAR)); + } + + /** * Creates a list item to render in the bookmark bar for the specified bookmark item. * * @param clickCallback The callback to invoke on list item click events.
diff --git a/chrome/browser/bookmarks/android/javatests/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarTest.java b/chrome/browser/bookmarks/android/javatests/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarTest.java index e26f4a13b..f004a7b 100644 --- a/chrome/browser/bookmarks/android/javatests/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarTest.java +++ b/chrome/browser/bookmarks/android/javatests/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarTest.java
@@ -401,7 +401,7 @@ private void setBookmarkBarSetting(boolean enabled) { final var activity = mCtaTestRule.getActivity(); final var profile = activity.getProfileProviderSupplier().get().getOriginalProfile(); - BookmarkBarUtils.setSettingEnabled(profile, enabled); + BookmarkBarUtils.setUserPrefsShowBookmarksBar(profile, enabled); } private void waitForBookmarkBarVisibility(boolean visible) {
diff --git a/chrome/browser/bookmarks/android/junit/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarUtilsTest.java b/chrome/browser/bookmarks/android/junit/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarUtilsTest.java index 8197ef4..b234e6e 100644 --- a/chrome/browser/bookmarks/android/junit/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarUtilsTest.java +++ b/chrome/browser/bookmarks/android/junit/src/org/chromium/chrome/browser/bookmarks/bar/BookmarkBarUtilsTest.java
@@ -230,40 +230,40 @@ @Test @SmallTest - public void testIsSettingEnabled() { + public void testIsUserPrefsShowBookmarksBarEnabled() { mSetting.set(false); - assertFalse(BookmarkBarUtils.isSettingEnabled(mProfile)); - assertFalse(BookmarkBarUtils.isSettingEnabled(null)); + assertFalse(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(mProfile)); + assertFalse(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(null)); mSetting.set(true); - assertTrue(BookmarkBarUtils.isSettingEnabled(mProfile)); - assertFalse(BookmarkBarUtils.isSettingEnabled(null)); + assertTrue(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(mProfile)); + assertFalse(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(null)); } @Test @SmallTest - public void testSetSettingEnabled() { + public void testSetUserPrefsShowBookmarksBar() { mSetting.set(false); - assertFalse(BookmarkBarUtils.isSettingEnabled(mProfile)); + assertFalse(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(mProfile)); - BookmarkBarUtils.setSettingEnabled(mProfile, true); - assertTrue(BookmarkBarUtils.isSettingEnabled(mProfile)); + BookmarkBarUtils.setUserPrefsShowBookmarksBar(mProfile, true); + assertTrue(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(mProfile)); - BookmarkBarUtils.setSettingEnabled(mProfile, false); - assertFalse(BookmarkBarUtils.isSettingEnabled(mProfile)); + BookmarkBarUtils.setUserPrefsShowBookmarksBar(mProfile, false); + assertFalse(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(mProfile)); } @Test @SmallTest - public void testToggleSettingEnabled() { + public void testToggleUserPrefsShowBookmarksBar() { mSetting.set(false); - assertFalse(BookmarkBarUtils.isSettingEnabled(mProfile)); + assertFalse(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(mProfile)); - BookmarkBarUtils.toggleSettingEnabled(mProfile); - assertTrue(BookmarkBarUtils.isSettingEnabled(mProfile)); + BookmarkBarUtils.toggleUserPrefsShowBookmarksBar(mProfile); + assertTrue(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(mProfile)); - BookmarkBarUtils.toggleSettingEnabled(mProfile); - assertFalse(BookmarkBarUtils.isSettingEnabled(mProfile)); + BookmarkBarUtils.toggleUserPrefsShowBookmarksBar(mProfile); + assertFalse(BookmarkBarUtils.isUserPrefsShowBookmarksBarEnabled(mProfile)); } @Test