Commit fdceab6e authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Chromium LUCI CQ

[Android] Refactor IdentityManager.Observer API override in

FeedSurfaceMediator and ChromeBackupWatcher

Replace IdentityManager.Observer.(onPrimaryAccountSet/Cleared) calls
with onPrimaryAccountChanged call.

Bug: 1158855
Change-Id: Ic9233c925b36188c7c52e183c52bed9044d86cc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2603575
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarAlice Wang <aliceywang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840609}
parent f108536b
...@@ -47,8 +47,8 @@ import org.chromium.components.browser_ui.widget.listmenu.ListMenuItemProperties ...@@ -47,8 +47,8 @@ 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.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.identitymanager.IdentityManager; import org.chromium.components.signin.identitymanager.IdentityManager;
import org.chromium.components.signin.identitymanager.PrimaryAccountChangeEvent;
import org.chromium.components.signin.metrics.SigninAccessPoint; import org.chromium.components.signin.metrics.SigninAccessPoint;
import org.chromium.components.user_prefs.UserPrefs; import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
...@@ -639,15 +639,10 @@ public class FeedSurfaceMediator ...@@ -639,15 +639,10 @@ public class FeedSurfaceMediator
mCoordinator.updateHeaderViews(false, null, null); mCoordinator.updateHeaderViews(false, null, null);
} }
// IdentityManager.Delegate interface. // IdentityManager.Observer interface.
@Override @Override
public void onPrimaryAccountSet(CoreAccountInfo account) { public void onPrimaryAccountChanged(PrimaryAccountChangeEvent eventDetails) {
updateSectionHeader();
}
@Override
public void onPrimaryAccountCleared(CoreAccountInfo account) {
updateSectionHeader(); updateSectionHeader();
} }
......
...@@ -17,8 +17,8 @@ import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; ...@@ -17,8 +17,8 @@ import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
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.profiles.Profile;
import org.chromium.chrome.browser.signin.services.IdentityServicesProvider; import org.chromium.chrome.browser.signin.services.IdentityServicesProvider;
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.signin.identitymanager.PrimaryAccountChangeEvent;
/** /**
* Class for watching for changes to the Android preferences that are backed up using Android * Class for watching for changes to the Android preferences that are backed up using Android
...@@ -60,18 +60,12 @@ public class ChromeBackupWatcher { ...@@ -60,18 +60,12 @@ public class ChromeBackupWatcher {
// Update the backup if the sign-in status changes. // Update the backup if the sign-in status changes.
IdentityManager identityManager = IdentityServicesProvider.get().getIdentityManager( IdentityManager identityManager = IdentityServicesProvider.get().getIdentityManager(
Profile.getLastUsedRegularProfile()); Profile.getLastUsedRegularProfile());
identityManager.addObserver( identityManager.addObserver(new IdentityManager.Observer() {
new IdentityManager.Observer() { @Override
@Override public void onPrimaryAccountChanged(PrimaryAccountChangeEvent eventDetails) {
public void onPrimaryAccountSet(CoreAccountInfo account) { onBackupPrefsChanged();
onBackupPrefsChanged(); }
} });
@Override
public void onPrimaryAccountCleared(CoreAccountInfo account) {
onBackupPrefsChanged();
}
});
} }
@CalledByNative @CalledByNative
......
...@@ -36,10 +36,14 @@ public class PrimaryAccountChangeEvent { ...@@ -36,10 +36,14 @@ public class PrimaryAccountChangeEvent {
private final @Type int mEventTypeForConsentLevelNotRequired; private final @Type int mEventTypeForConsentLevelNotRequired;
@CalledByNative @CalledByNative
public PrimaryAccountChangeEvent( private PrimaryAccountChangeEvent(
@Type int eventTypeForConsentLevelNotRequired, @Type int eventTypeForConsentLevelSync) { @Type int eventTypeForConsentLevelNotRequired, @Type int eventTypeForConsentLevelSync) {
mEventTypeForConsentLevelNotRequired = eventTypeForConsentLevelNotRequired; mEventTypeForConsentLevelNotRequired = eventTypeForConsentLevelNotRequired;
mEventTypeForConsentLevelSync = eventTypeForConsentLevelSync; mEventTypeForConsentLevelSync = eventTypeForConsentLevelSync;
assert mEventTypeForConsentLevelNotRequired != Type.NONE
|| mEventTypeForConsentLevelSync
!= Type.NONE
: "PrimaryAccountChangeEvent should not be fired for no-change events";
} }
/** /**
......
...@@ -103,9 +103,16 @@ base::android::ScopedJavaLocalRef<jobject> ...@@ -103,9 +103,16 @@ base::android::ScopedJavaLocalRef<jobject>
ConvertToJavaPrimaryAccountChangeEvent( ConvertToJavaPrimaryAccountChangeEvent(
JNIEnv* env, JNIEnv* env,
const PrimaryAccountChangeEvent& event_details) { const PrimaryAccountChangeEvent& event_details) {
PrimaryAccountChangeEvent::Type event_type_not_required =
event_details.GetEventTypeFor(ConsentLevel::kNotRequired);
PrimaryAccountChangeEvent::Type event_type_sync =
event_details.GetEventTypeFor(ConsentLevel::kSync);
// Should not fire events if there is no change in primary accounts for any
// consent level.
DCHECK(event_type_not_required != PrimaryAccountChangeEvent::Type::kNone ||
event_type_sync != PrimaryAccountChangeEvent::Type::kNone);
return Java_PrimaryAccountChangeEvent_Constructor( return Java_PrimaryAccountChangeEvent_Constructor(
env, jint(event_details.GetEventTypeFor(ConsentLevel::kNotRequired)), env, jint(event_type_not_required), jint(event_type_sync));
jint(event_details.GetEventTypeFor(ConsentLevel::kSync)));
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
......
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