Commit df448087 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Android: Update many Chrome uses of PrefServiceBridge to PrefService

Bug: 1071603
Change-Id: Idaa3ecd17791bf5ab0edb5074b07978e30e85706
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248669
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779432}
parent 36e4fe60
......@@ -390,6 +390,7 @@ android_library("chrome_java") {
"//components/payments/mojom:mojom_java",
"//components/permissions/android:java",
"//components/policy/android:policy_java",
"//components/prefs/android:java",
"//components/query_tiles:java",
"//components/safe_browsing/android:safe_browsing_java",
"//components/schema_org/common:mojom_java",
......@@ -404,6 +405,7 @@ android_library("chrome_java") {
"//components/sync/android:sync_java",
"//components/sync/protocol:protocol_java",
"//components/url_formatter/android:url_formatter_java",
"//components/user_prefs/android:java",
"//components/variations/android:variations_java",
"//components/version_info/android:version_constants_java",
"//components/viz/common:common_java",
......@@ -790,6 +792,7 @@ junit_binary("chrome_junit_tests") {
"//components/page_info/android:java",
"//components/payments/content/android:java",
"//components/payments/mojom:mojom_java",
"//components/prefs/android:java",
"//components/schema_org/common:mojom_java",
"//components/search_engines/android:java",
"//components/security_state/content/android:java",
......@@ -1001,6 +1004,7 @@ android_library("chrome_test_java") {
"//components/permissions/android:java",
"//components/policy/android:policy_java",
"//components/policy/android:policy_java_test_support",
"//components/prefs/android:java",
"//components/query_tiles:public_java",
"//components/query_tiles:test_support_java",
"//components/safe_browsing/android:safe_browsing_java",
......@@ -1017,6 +1021,7 @@ android_library("chrome_test_java") {
"//components/sync/android:sync_javatests",
"//components/sync/protocol:protocol_java",
"//components/url_formatter/android:url_formatter_java",
"//components/user_prefs/android:java",
"//content/public/android:content_java",
"//content/public/test/android:content_java_test_support",
"//media/base/android:java_switches",
......
......@@ -30,12 +30,14 @@ include_rules = [
"+components/page_info/android/java",
"+components/permissions/android/nfc",
"+components/policy",
"+components/prefs/android",
"+components/query_tiles",
"+components/security_interstitials/content/android",
"+components/signin/core/browser/android",
"+components/signin/public/android",
"+components/spellcheck/browser",
"+components/subresource_filter/android",
"+components/user_prefs/android",
"+components/viz/common/java",
"+components/webrtc/android",
"+jni",
......
......@@ -24,8 +24,9 @@ import org.chromium.chrome.browser.feed.library.common.time.SystemClockImpl;
import org.chromium.chrome.browser.feed.tooltip.BasicTooltipSupportedApi;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefChangeRegistrar;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
/** Holds singleton {@link ProcessScope} and some of the scope's host implementations. */
public class FeedProcessScopeFactory {
......@@ -130,8 +131,7 @@ public class FeedProcessScopeFactory {
// subscriber to this pref change event might check in with this method, and we cannot
// assume who will be called first. See https://crbug.com/896468.
if (!sEverDisabledForPolicy) {
sEverDisabledForPolicy =
!PrefServiceBridge.getInstance().getBoolean(Pref.ENABLE_SNIPPETS);
sEverDisabledForPolicy = !getPrefService().getBoolean(Pref.ENABLE_SNIPPETS);
}
return !sEverDisabledForPolicy;
}
......@@ -141,8 +141,7 @@ public class FeedProcessScopeFactory {
&& sFeedAppLifecycle == null && sFeedLoggingBridge == null;
if (!isFeedProcessEnabled()) return;
sArticlesVisibleDuringSession =
PrefServiceBridge.getInstance().getBoolean(Pref.ARTICLES_LIST_VISIBLE);
sArticlesVisibleDuringSession = getPrefService().getBoolean(Pref.ARTICLES_LIST_VISIBLE);
sPrefChangeRegistrar = new PrefChangeRegistrar();
sPrefChangeRegistrar.addObserver(
Pref.ENABLE_SNIPPETS, FeedProcessScopeFactory::articlesEnabledPrefChange);
......@@ -271,7 +270,7 @@ public class FeedProcessScopeFactory {
static boolean areArticlesVisibleDuringSession() {
// Skip the native call if sArticlesVisibleDuringSession is already true to reduce overhead.
if (!sArticlesVisibleDuringSession
&& PrefServiceBridge.getInstance().getBoolean(Pref.ARTICLES_LIST_VISIBLE)) {
&& getPrefService().getBoolean(Pref.ARTICLES_LIST_VISIBLE)) {
sArticlesVisibleDuringSession = true;
}
......@@ -280,7 +279,7 @@ public class FeedProcessScopeFactory {
private static void articlesEnabledPrefChange() {
// Cannot assume this is called because of an actual change. May be going from true to true.
if (!PrefServiceBridge.getInstance().getBoolean(Pref.ENABLE_SNIPPETS)) {
if (!getPrefService().getBoolean(Pref.ENABLE_SNIPPETS)) {
// There have been quite a few crashes/bugs that happen when code does not correctly
// handle the scenario where Feed suddenly becomes disabled and the above getters start
// returning nulls. Having this log a warning helps diagnose this pattern from the
......@@ -291,6 +290,10 @@ public class FeedProcessScopeFactory {
}
}
private static PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
/** Clears out all static state. */
private static void destroy() {
if (sPrefChangeRegistrar != null) {
......
......@@ -30,7 +30,7 @@ import org.chromium.chrome.browser.ntp.cards.promo.HomepagePromoController.Homep
import org.chromium.chrome.browser.ntp.snippets.SectionHeader;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefChangeRegistrar;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceFactory;
import org.chromium.chrome.browser.signin.IdentityServicesProvider;
import org.chromium.chrome.browser.signin.PersonalizedSigninPromoView;
......@@ -40,9 +40,11 @@ import org.chromium.chrome.browser.suggestions.SuggestionsMetrics;
import org.chromium.components.browser_ui.widget.listmenu.ListMenu;
import org.chromium.components.browser_ui.widget.listmenu.ListMenuItemProperties;
import org.chromium.components.feature_engagement.Tracker;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.search_engines.TemplateUrlService.TemplateUrlServiceObserver;
import org.chromium.components.signin.base.CoreAccountInfo;
import org.chromium.components.signin.identitymanager.IdentityManager;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.ui.modelutil.MVCListAdapter.ModelList;
import org.chromium.ui.modelutil.PropertyModel;
......@@ -180,8 +182,7 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate,
};
stream.addOnContentChangedListener(mStreamContentChangedListener);
boolean suggestionsVisible =
PrefServiceBridge.getInstance().getBoolean(Pref.ARTICLES_LIST_VISIBLE);
boolean suggestionsVisible = getPrefService().getBoolean(Pref.ARTICLES_LIST_VISIBLE);
if (mHasHeader) {
mSectionHeader = new SectionHeader(getSectionHeaderText(suggestionsVisible),
......@@ -288,8 +289,7 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate,
/** Update whether the section header should be expanded and its text contents. */
private void updateSectionHeader() {
boolean suggestionsVisible =
PrefServiceBridge.getInstance().getBoolean(Pref.ARTICLES_LIST_VISIBLE);
boolean suggestionsVisible = getPrefService().getBoolean(Pref.ARTICLES_LIST_VISIBLE);
if (mSectionHeader.isExpanded() != suggestionsVisible) mSectionHeader.toggleHeader();
mSectionHeader.setHeaderText(getSectionHeaderText(mSectionHeader.isExpanded()));
......@@ -310,8 +310,7 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate,
* expand icon on the section header view.
*/
private void onSectionHeaderToggled() {
PrefServiceBridge.getInstance().setBoolean(
Pref.ARTICLES_LIST_VISIBLE, mSectionHeader.isExpanded());
getPrefService().setBoolean(Pref.ARTICLES_LIST_VISIBLE, mSectionHeader.isExpanded());
mCoordinator.getStream().setStreamContentVisibility(mSectionHeader.isExpanded());
// TODO(huayinz): Update the section header view through a ModelChangeProcessor.
mCoordinator.getSectionHeaderView().updateVisuals();
......@@ -393,6 +392,10 @@ class FeedSurfaceMediator implements NewTabPageLayout.ScrollDelegate,
return mTouchEnabled;
}
private PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
// TouchEnabledDelegate interface.
@Override
......
......@@ -12,22 +12,26 @@ import androidx.annotation.VisibleForTesting;
import org.chromium.chrome.browser.feed.shared.stream.Stream;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabHidingType;
import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.chrome.browser.tab.TabSelectionType;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.NavigationController;
import org.chromium.content_public.browser.NavigationEntry;
/**
* Manages the lifecycle of a {@link Stream} associated with a Tab in an Activity.
*/
public final class NtpStreamLifecycleManager extends StreamLifecycleManager {
public class NtpStreamLifecycleManager extends StreamLifecycleManager {
/** Key for the Stream instance state that may be stored in a navigation entry. */
private static final String STREAM_SAVED_INSTANCE_STATE_KEY = "StreamSavedInstanceState";
private static PrefService sPrefServiceForTesting;
/** The {@link Tab} that {@link #mStream} is attached to. */
private final Tab mTab;
......@@ -84,16 +88,14 @@ public final class NtpStreamLifecycleManager extends StreamLifecycleManager {
protected boolean canShow() {
// We don't call Stream#onShow to prevent feed services from being warmed up if the user
// has opted out from article suggestions during the previous session.
return super.canShow()
&& PrefServiceBridge.getInstance().getBoolean(Pref.ARTICLES_LIST_VISIBLE)
return super.canShow() && getPrefService().getBoolean(Pref.ARTICLES_LIST_VISIBLE)
&& !mTab.isHidden();
}
/** @return Whether the {@link Stream} can be activated. */
@Override
protected boolean canActivate() {
return super.canActivate()
&& PrefServiceBridge.getInstance().getBoolean(Pref.ARTICLES_LIST_VISIBLE)
return super.canActivate() && getPrefService().getBoolean(Pref.ARTICLES_LIST_VISIBLE)
&& mTab.isUserInteractable();
}
......@@ -147,4 +149,14 @@ public final class NtpStreamLifecycleManager extends StreamLifecycleManager {
TabObserver getTabObserverForTesting() {
return mTabObserver;
}
private PrefService getPrefService() {
if (sPrefServiceForTesting != null) return sPrefServiceForTesting;
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
@VisibleForTesting
static void setPrefServiceForTesting(PrefService prefServiceForTesting) {
sPrefServiceForTesting = prefServiceForTesting;
}
}
......@@ -60,8 +60,8 @@ import org.chromium.chrome.browser.ntp.cards.SignInPromo;
import org.chromium.chrome.browser.ntp.snippets.SectionHeader;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.suggestions.SiteSuggestion;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
......@@ -75,7 +75,9 @@ import org.chromium.chrome.test.util.browser.signin.AccountManagerTestRule;
import org.chromium.chrome.test.util.browser.suggestions.SuggestionsDependenciesRule;
import org.chromium.chrome.test.util.browser.suggestions.mostvisited.FakeMostVisitedSites;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.signin.test.util.FakeAccountManagerFacade;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
......@@ -410,7 +412,7 @@ public class FeedNewTabPageTest {
public void testFeedDisabledByPolicy() throws Exception {
openNewTabPage();
final boolean pref = TestThreadUtils.runOnUiThreadBlocking(
() -> PrefServiceBridge.getInstance().getBoolean(Pref.ENABLE_SNIPPETS));
() -> getPrefService().getBoolean(Pref.ENABLE_SNIPPETS));
// Policy is disabled. Verify the NTP root view contains only the Stream view as child.
ViewGroup rootView = (ViewGroup) mNtp.getView();
......@@ -424,7 +426,7 @@ public class FeedNewTabPageTest {
// Simulate that policy is enabled. Verify the NTP root view contains only the view for
// policy as child.
TestThreadUtils.runOnUiThreadBlocking(
() -> PrefServiceBridge.getInstance().setBoolean(Pref.ENABLE_SNIPPETS, false));
() -> getPrefService().setBoolean(Pref.ENABLE_SNIPPETS, false));
Assert.assertNotNull(mNtp.getCoordinatorForTesting().getScrollViewForPolicy());
Assert.assertNull(mNtp.getCoordinatorForTesting().getStreamForTesting());
Assert.assertEquals(1, rootView.getChildCount());
......@@ -446,7 +448,7 @@ public class FeedNewTabPageTest {
// Simulate that policy is disabled. Verify the NTP root view is the view for policy. We
// don't re-enable the Feed until the next restart.
TestThreadUtils.runOnUiThreadBlocking(
() -> PrefServiceBridge.getInstance().setBoolean(Pref.ENABLE_SNIPPETS, true));
() -> getPrefService().setBoolean(Pref.ENABLE_SNIPPETS, true));
Assert.assertNotNull(ntp2.getCoordinatorForTesting().getScrollViewForPolicy());
Assert.assertNull(ntp2.getCoordinatorForTesting().getStream());
Assert.assertEquals(1, rootView2.getChildCount());
......@@ -463,7 +465,7 @@ public class FeedNewTabPageTest {
// Reset state.
TestThreadUtils.runOnUiThreadBlocking(
() -> PrefServiceBridge.getInstance().setBoolean(Pref.ENABLE_SNIPPETS, pref));
() -> getPrefService().setBoolean(Pref.ENABLE_SNIPPETS, pref));
}
/**
......@@ -483,6 +485,10 @@ public class FeedNewTabPageTest {
private boolean getPreferenceForArticleSectionHeader() throws Exception {
return TestThreadUtils.runOnUiThreadBlocking(
() -> PrefServiceBridge.getInstance().getBoolean(Pref.ARTICLES_LIST_VISIBLE));
() -> getPrefService().getBoolean(Pref.ARTICLES_LIST_VISIBLE));
}
private PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
}
......@@ -16,7 +16,9 @@ import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.autofill.settings.AutofillEditorBase;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList;
......@@ -1001,14 +1003,14 @@ public class PersonalDataManager {
* @return Whether the Autofill feature for Profiles (addresses) is enabled.
*/
public static boolean isAutofillProfileEnabled() {
return PrefServiceBridge.getInstance().getBoolean(Pref.AUTOFILL_PROFILE_ENABLED);
return getPrefService().getBoolean(Pref.AUTOFILL_PROFILE_ENABLED);
}
/**
* @return Whether the Autofill feature for Credit Cards is enabled.
*/
public static boolean isAutofillCreditCardEnabled() {
return PrefServiceBridge.getInstance().getBoolean(Pref.AUTOFILL_CREDIT_CARD_ENABLED);
return getPrefService().getBoolean(Pref.AUTOFILL_CREDIT_CARD_ENABLED);
}
/**
......@@ -1016,7 +1018,7 @@ public class PersonalDataManager {
* @param enable True to disable profile Autofill, false otherwise.
*/
public static void setAutofillProfileEnabled(boolean enable) {
PrefServiceBridge.getInstance().setBoolean(Pref.AUTOFILL_PROFILE_ENABLED, enable);
getPrefService().setBoolean(Pref.AUTOFILL_PROFILE_ENABLED, enable);
}
/**
......@@ -1024,15 +1026,14 @@ public class PersonalDataManager {
* @param enable True to disable credit card Autofill, false otherwise.
*/
public static void setAutofillCreditCardEnabled(boolean enable) {
PrefServiceBridge.getInstance().setBoolean(Pref.AUTOFILL_CREDIT_CARD_ENABLED, enable);
getPrefService().setBoolean(Pref.AUTOFILL_CREDIT_CARD_ENABLED, enable);
}
/**
* @return Whether the Autofill feature for FIDO authentication is enabled.
*/
public static boolean isAutofillCreditCardFidoAuthEnabled() {
return PrefServiceBridge.getInstance().getBoolean(
Pref.AUTOFILL_CREDIT_CARD_FIDO_AUTH_ENABLED);
return getPrefService().getBoolean(Pref.AUTOFILL_CREDIT_CARD_FIDO_AUTH_ENABLED);
}
/**
......@@ -1042,8 +1043,7 @@ public class PersonalDataManager {
* @param enable True to enable credit card FIDO authentication, false otherwise.
*/
public static void setAutofillCreditCardFidoAuthEnabled(boolean enable) {
PrefServiceBridge.getInstance().setBoolean(
Pref.AUTOFILL_CREDIT_CARD_FIDO_AUTH_ENABLED, enable);
getPrefService().setBoolean(Pref.AUTOFILL_CREDIT_CARD_FIDO_AUTH_ENABLED, enable);
}
/**
......@@ -1099,6 +1099,10 @@ public class PersonalDataManager {
return DateUtils.SECOND_IN_MILLIS * sRequestTimeoutSeconds;
}
private static PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
@NativeMethods
interface Natives {
long init(PersonalDataManager caller);
......
......@@ -39,7 +39,6 @@ import org.chromium.chrome.browser.fullscreen.FullscreenOptions;
import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection;
import org.chromium.chrome.browser.infobar.InfoBarContainer;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.SadTab;
import org.chromium.chrome.browser.tab.Tab;
......@@ -59,6 +58,8 @@ import org.chromium.components.feature_engagement.FeatureConstants;
import org.chromium.components.feature_engagement.Tracker;
import org.chromium.components.feature_engagement.TriggerState;
import org.chromium.components.navigation_interception.NavigationParams;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.NavigationEntry;
......@@ -1776,7 +1777,7 @@ public class ContextualSearchManager
* @return Whether the Contextual Search feature was disabled by the user explicitly.
*/
public static boolean isContextualSearchDisabled() {
return PrefServiceBridge.getInstance()
return getPrefService()
.getString(Pref.CONTEXTUAL_SEARCH_ENABLED)
.equals(CONTEXTUAL_SEARCH_DISABLED);
}
......@@ -1785,7 +1786,7 @@ public class ContextualSearchManager
* @return Whether the Contextual Search feature is disabled by policy.
*/
public static boolean isContextualSearchDisabledByPolicy() {
return PrefServiceBridge.getInstance().isManagedPreference(Pref.CONTEXTUAL_SEARCH_ENABLED)
return getPrefService().isManagedPreference(Pref.CONTEXTUAL_SEARCH_ENABLED)
&& isContextualSearchDisabled();
}
......@@ -1794,17 +1795,21 @@ public class ContextualSearchManager
* user).
*/
public static boolean isContextualSearchUninitialized() {
return PrefServiceBridge.getInstance().getString(Pref.CONTEXTUAL_SEARCH_ENABLED).isEmpty();
return getPrefService().getString(Pref.CONTEXTUAL_SEARCH_ENABLED).isEmpty();
}
/**
* @param enabled Whether Contextual Search should be enabled.
*/
public static void setContextualSearchState(boolean enabled) {
PrefServiceBridge.getInstance().setString(Pref.CONTEXTUAL_SEARCH_ENABLED,
getPrefService().setString(Pref.CONTEXTUAL_SEARCH_ENABLED,
enabled ? CONTEXTUAL_SEARCH_ENABLED : CONTEXTUAL_SEARCH_DISABLED);
}
private static PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
// ============================================================================================
// Test helpers
// ============================================================================================
......
......@@ -20,13 +20,15 @@ import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.favicon.FaviconHelper.DefaultFaviconHelper;
import org.chromium.chrome.browser.ui.favicon.FaviconUtils;
import org.chromium.chrome.browser.ui.favicon.IconType;
import org.chromium.chrome.browser.ui.favicon.LargeIconBridge.LargeIconCallback;
import org.chromium.components.browser_ui.widget.RoundedIconGenerator;
import org.chromium.components.browser_ui.widget.selectable_list.SelectableItemView;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
/**
* The SelectableItemView for items displayed in the browsing history UI.
......@@ -155,9 +157,7 @@ public class HistoryItemView extends SelectableItemView<HistoryItem> implements
*/
public void setRemoveButtonVisible(boolean visible) {
mRemoveButtonVisible = visible;
if (!PrefServiceBridge.getInstance().getBoolean(Pref.ALLOW_DELETING_BROWSER_HISTORY)) {
return;
}
if (!getPrefService().getBoolean(Pref.ALLOW_DELETING_BROWSER_HISTORY)) return;
mRemoveButton.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
}
......@@ -185,7 +185,7 @@ public class HistoryItemView extends SelectableItemView<HistoryItem> implements
private void updateRemoveButtonVisibility() {
int removeButtonVisibility =
!PrefServiceBridge.getInstance().getBoolean(Pref.ALLOW_DELETING_BROWSER_HISTORY)
!getPrefService().getBoolean(Pref.ALLOW_DELETING_BROWSER_HISTORY)
? View.GONE
: mRemoveButtonVisible ? View.VISIBLE : View.INVISIBLE;
mRemoveButton.setVisibility(removeButtonVisibility);
......@@ -199,4 +199,8 @@ public class HistoryItemView extends SelectableItemView<HistoryItem> implements
View getRemoveButtonForTests() {
return mRemoveButton;
}
private PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
}
......@@ -13,12 +13,14 @@ import androidx.preference.PreferenceFragmentCompat;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.ChromeManagedPreferenceDelegate;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
/**
* Settings fragment that displays information about Chrome languages, which allow users to
......@@ -43,15 +45,14 @@ public class LanguageSettings
ChromeSwitchPreference translateSwitch =
(ChromeSwitchPreference) findPreference(TRANSLATE_SWITCH_KEY);
boolean isTranslateEnabled =
PrefServiceBridge.getInstance().getBoolean(Pref.OFFER_TRANSLATE_ENABLED);
boolean isTranslateEnabled = getPrefService().getBoolean(Pref.OFFER_TRANSLATE_ENABLED);
translateSwitch.setChecked(isTranslateEnabled);
translateSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enabled = (boolean) newValue;
PrefServiceBridge.getInstance().setBoolean(Pref.OFFER_TRANSLATE_ENABLED, enabled);
getPrefService().setBoolean(Pref.OFFER_TRANSLATE_ENABLED, enabled);
mLanguageListPref.notifyPrefChanged();
LanguagesManager.recordAction(enabled ? LanguagesManager.LanguageSettingsActionType
.ENABLE_TRANSLATE_GLOBALLY
......@@ -61,8 +62,7 @@ public class LanguageSettings
}
});
translateSwitch.setManagedPreferenceDelegate((ChromeManagedPreferenceDelegate) preference
-> PrefServiceBridge.getInstance().isManagedPreference(
Pref.OFFER_TRANSLATE_ENABLED));
-> getPrefService().isManagedPreference(Pref.OFFER_TRANSLATE_ENABLED));
LanguagesManager.recordImpression(LanguagesManager.LanguageSettingsPageType.PAGE_MAIN);
}
......@@ -91,4 +91,8 @@ public class LanguageSettings
getActivity(), AddLanguageFragment.class.getName());
startActivityForResult(intent, REQUEST_CODE_ADD_LANGUAGES);
}
private PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
}
......@@ -29,7 +29,9 @@ import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateInteractionS
import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateState;
import org.chromium.chrome.browser.omaha.UpdateStatusProvider.UpdateStatus;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.UiThreadTaskTraits;
/**
......@@ -218,7 +220,7 @@ public class UpdateMenuItemHelper {
UpdateStatusProvider.getInstance().startIntentUpdate(
activity, UpdateInteractionSource.FROM_MENU, false /* newTask */);
recordItemClickedHistogram(ITEM_CLICKED_INTENT_LAUNCHED);
PrefServiceBridge.getInstance().setBoolean(Pref.CLICKED_UPDATE_MENU_ITEM, true);
getPrefService().setBoolean(Pref.CLICKED_UPDATE_MENU_ITEM, true);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "Failed to launch Activity for: %s", mStatus.updateUrl);
recordItemClickedHistogram(ITEM_CLICKED_INTENT_FAILED);
......@@ -247,7 +249,7 @@ public class UpdateMenuItemHelper {
// If the update menu item is showing because it was forced on through about://flags
// then mLatestVersion may be null.
if (mStatus.latestVersion != null) {
PrefServiceBridge.getInstance().setString(
getPrefService().setString(
Pref.LATEST_VERSION_WHEN_CLICKED_UPDATE_MENU_ITEM, mStatus.latestVersion);
}
......@@ -292,7 +294,7 @@ public class UpdateMenuItemHelper {
// The badge is hidden if the update menu item has been clicked until there is an
// even newer version of Chrome available.
showBadge |= !TextUtils.equals(
PrefServiceBridge.getInstance().getString(
getPrefService().getString(
Pref.LATEST_VERSION_WHEN_CLICKED_UPDATE_MENU_ITEM),
mStatus.latestUnsupportedVersion);
......@@ -345,7 +347,7 @@ public class UpdateMenuItemHelper {
// The badge is hidden if the update menu item has been clicked until there is an
// even newer version of Chrome available.
showBadge |= !TextUtils.equals(
PrefServiceBridge.getInstance().getString(
getPrefService().getString(
Pref.LATEST_VERSION_WHEN_CLICKED_UPDATE_MENU_ITEM),
mStatus.latestUnsupportedVersion);
......@@ -412,15 +414,19 @@ public class UpdateMenuItemHelper {
private void recordUpdateHistogram() {
assert mStatus != null;
if (PrefServiceBridge.getInstance().getBoolean(Pref.CLICKED_UPDATE_MENU_ITEM)) {
if (getPrefService().getBoolean(Pref.CLICKED_UPDATE_MENU_ITEM)) {
RecordHistogram.recordEnumeratedHistogram(
"GoogleUpdate.MenuItem.ActionTakenAfterItemClicked",
mStatus.updateState == UpdateState.UPDATE_AVAILABLE ? NOT_UPDATED : UPDATED,
UPDATED_BOUNDARY);
PrefServiceBridge.getInstance().setBoolean(Pref.CLICKED_UPDATE_MENU_ITEM, false);
getPrefService().setBoolean(Pref.CLICKED_UPDATE_MENU_ITEM, false);
}
}
private static PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
@VisibleForTesting
boolean getMenuDismissedRunnableExecutedForTests() {
return mMenuDismissedRunnableExecuted;
......
......@@ -31,7 +31,6 @@ import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.help.HelpAndFeedback;
import org.chromium.chrome.browser.password_manager.PasswordManagerLauncher;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.ChromeManagedPreferenceDelegate;
import org.chromium.chrome.browser.settings.SettingsLauncher;
......@@ -42,6 +41,8 @@ import org.chromium.components.browser_ui.settings.ChromeBasePreference;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
import org.chromium.components.browser_ui.settings.SearchUtils;
import org.chromium.components.browser_ui.settings.TextMessagePreference;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.ui.text.SpanApplier;
import java.util.Locale;
......@@ -427,14 +428,12 @@ public class PasswordSettings
mSavePasswordsSwitch.setSummaryOn(R.string.text_on);
mSavePasswordsSwitch.setSummaryOff(R.string.text_off);
mSavePasswordsSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
PrefServiceBridge.getInstance().setBoolean(
Pref.CREDENTIALS_ENABLE_SERVICE, (boolean) newValue);
getPrefService().setBoolean(Pref.CREDENTIALS_ENABLE_SERVICE, (boolean) newValue);
return true;
});
mSavePasswordsSwitch.setManagedPreferenceDelegate(
(ChromeManagedPreferenceDelegate) preference
-> PrefServiceBridge.getInstance().isManagedPreference(
Pref.CREDENTIALS_ENABLE_SERVICE));
-> getPrefService().isManagedPreference(Pref.CREDENTIALS_ENABLE_SERVICE));
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
getPreferenceScreen().addPreference(mSavePasswordsSwitch);
......@@ -445,7 +444,7 @@ public class PasswordSettings
// (e.g. the switch will say "On" when save passwords is really turned off), so
// .setChecked() should be called after .addPreference()
mSavePasswordsSwitch.setChecked(
PrefServiceBridge.getInstance().getBoolean(Pref.CREDENTIALS_ENABLE_SERVICE));
getPrefService().getBoolean(Pref.CREDENTIALS_ENABLE_SERVICE));
}
private void createAutoSignInCheckbox() {
......@@ -455,16 +454,14 @@ public class PasswordSettings
mAutoSignInSwitch.setOrder(ORDER_AUTO_SIGNIN_CHECKBOX);
mAutoSignInSwitch.setSummary(R.string.passwords_auto_signin_description);
mAutoSignInSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
PrefServiceBridge.getInstance().setBoolean(
Pref.CREDENTIALS_ENABLE_AUTOSIGNIN, (boolean) newValue);
getPrefService().setBoolean(Pref.CREDENTIALS_ENABLE_AUTOSIGNIN, (boolean) newValue);
return true;
});
mAutoSignInSwitch.setManagedPreferenceDelegate((ChromeManagedPreferenceDelegate) preference
-> PrefServiceBridge.getInstance().isManagedPreference(
Pref.CREDENTIALS_ENABLE_AUTOSIGNIN));
-> getPrefService().isManagedPreference(Pref.CREDENTIALS_ENABLE_AUTOSIGNIN));
getPreferenceScreen().addPreference(mAutoSignInSwitch);
mAutoSignInSwitch.setChecked(
PrefServiceBridge.getInstance().getBoolean(Pref.CREDENTIALS_ENABLE_AUTOSIGNIN));
getPrefService().getBoolean(Pref.CREDENTIALS_ENABLE_AUTOSIGNIN));
}
private void displayManageAccountLink() {
......@@ -514,6 +511,10 @@ public class PasswordSettings
return getPreferenceManager().getContext();
}
private PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
@VisibleForTesting
Menu getMenuForTesting() {
return mMenu;
......
......@@ -36,9 +36,9 @@ import org.chromium.base.ApplicationStatus;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.browser.feed.shared.stream.Stream;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.tab.TabHidingType;
import org.chromium.chrome.browser.tab.TabImpl;
import org.chromium.components.prefs.PrefService;
/**
* Unit tests for {@link StreamLifecycleManager}.
......@@ -53,7 +53,7 @@ public class NtpStreamLifecycleManagerTest {
@Mock
private Stream mStream;
@Mock
private PrefServiceBridge mPrefServiceBridge;
private PrefService mPrefService;
private NtpStreamLifecycleManager mNtpStreamLifecycleManager;
......@@ -61,10 +61,10 @@ public class NtpStreamLifecycleManagerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
// Initialize a test instance for PrefServiceBridge.
when(mPrefServiceBridge.getBoolean(anyString())).thenReturn(true);
doNothing().when(mPrefServiceBridge).setBoolean(anyString(), anyBoolean());
PrefServiceBridge.setInstanceForTesting(mPrefServiceBridge);
// Initialize a test instance for PrefService.
when(mPrefService.getBoolean(anyString())).thenReturn(true);
doNothing().when(mPrefService).setBoolean(anyString(), anyBoolean());
NtpStreamLifecycleManager.setPrefServiceForTesting(mPrefService);
ApplicationStatus.onStateChangeForTesting(mActivity, ActivityState.CREATED);
mNtpStreamLifecycleManager = new NtpStreamLifecycleManager(mStream, mActivity, mTab);
......@@ -73,7 +73,7 @@ public class NtpStreamLifecycleManagerTest {
@After
public void tearDown() {
PrefServiceBridge.setInstanceForTesting(null);
NtpStreamLifecycleManager.setPrefServiceForTesting(null);
}
@Test
......@@ -104,7 +104,7 @@ public class NtpStreamLifecycleManagerTest {
@SmallTest
public void testShow_ArticlesNotVisible() {
// Verify that onShow is not called when articles are set hidden by the user.
when(mPrefServiceBridge.getBoolean(Pref.ARTICLES_LIST_VISIBLE)).thenReturn(false);
when(mPrefService.getBoolean(Pref.ARTICLES_LIST_VISIBLE)).thenReturn(false);
ApplicationStatus.onStateChangeForTesting(mActivity, ActivityState.STARTED);
when((mTab).isHidden()).thenReturn(false);
when(mTab.isUserInteractable()).thenReturn(true);
......@@ -112,7 +112,7 @@ public class NtpStreamLifecycleManagerTest {
verify(mStream, times(0)).onShow();
// Verify that onShow is called when articles are set shown by the user.
when(mPrefServiceBridge.getBoolean(Pref.ARTICLES_LIST_VISIBLE)).thenReturn(true);
when(mPrefService.getBoolean(Pref.ARTICLES_LIST_VISIBLE)).thenReturn(true);
mNtpStreamLifecycleManager.getTabObserverForTesting().onShown(mTab, FROM_NEW);
verify(mStream, times(1)).onShow();
......
......@@ -64,6 +64,8 @@ android_library("java") {
"//components/feature_engagement:feature_engagement_java",
"//components/feed/core/shared_prefs:feed_shared_prefs",
"//components/offline_items_collection/core:core_java",
"//components/prefs/android:java",
"//components/user_prefs/android:java",
"//content/public/android:content_java",
"//third_party/android_deps:androidx_core_core_java",
"//third_party/android_deps:androidx_fragment_fragment_java",
......
......@@ -19,7 +19,9 @@ import org.chromium.chrome.browser.download.dialogs.DownloadLocationDialogContro
import org.chromium.chrome.browser.download.dialogs.DownloadLocationDialogCoordinator;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.prefs.PrefService;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager;
......@@ -219,14 +221,14 @@ public class DownloadDialogBridge implements DownloadLocationDialogController,
*/
@DownloadPromptStatus
public static int getPromptForDownloadAndroid() {
return PrefServiceBridge.getInstance().getInteger(Pref.PROMPT_FOR_DOWNLOAD_ANDROID);
return getPrefService().getInteger(Pref.PROMPT_FOR_DOWNLOAD_ANDROID);
}
/**
* @param status New status to update the prompt for download preference.
*/
public static void setPromptForDownloadAndroid(@DownloadPromptStatus int status) {
PrefServiceBridge.getInstance().setInteger(Pref.PROMPT_FOR_DOWNLOAD_ANDROID, status);
getPrefService().setInteger(Pref.PROMPT_FOR_DOWNLOAD_ANDROID, status);
}
/**
......@@ -234,7 +236,7 @@ public class DownloadDialogBridge implements DownloadLocationDialogController,
*/
@DownloadLaterPromptStatus
public static int getDownloadLaterPromptStatus() {
return PrefServiceBridge.getInstance().getInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS);
return getPrefService().getInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS);
}
/**
......@@ -242,7 +244,11 @@ public class DownloadDialogBridge implements DownloadLocationDialogController,
* @param status New status to update the download later prmopt status.
*/
public static void setDownloadLaterPromptStatus(@DownloadLaterPromptStatus int status) {
PrefServiceBridge.getInstance().setInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS, status);
getPrefService().setInteger(Pref.DOWNLOAD_LATER_PROMPT_STATUS, status);
}
private static PrefService getPrefService() {
return UserPrefs.get(Profile.getLastUsedRegularProfile());
}
@NativeMethods
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment