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