Commit 8cdfa676 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Convert PasswordStoreSigninNotifierImpl to IdentityManager

Add a new method OnPrimaryAccountSetWithPassword to
IdentityManager::Observer (with comments indicating
it only works for legacy sign-in workflow) and port
PasswordStoreSigninNotifierImpl to it.

Bug: 903870, 887438, 887441
Change-Id: Ic79cff4ffdd341aedb22ee2c8abd40d309ee6fa4
Reviewed-on: https://chromium-review.googlesource.com/c/1344089Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610029}
parent e4b6c3b2
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "components/signin/core/browser/signin_manager.h" #include "services/identity/public/cpp/identity_manager.h"
namespace password_manager { namespace password_manager {
...@@ -22,34 +22,32 @@ PasswordStoreSigninNotifierImpl::~PasswordStoreSigninNotifierImpl() {} ...@@ -22,34 +22,32 @@ PasswordStoreSigninNotifierImpl::~PasswordStoreSigninNotifierImpl() {}
void PasswordStoreSigninNotifierImpl::SubscribeToSigninEvents( void PasswordStoreSigninNotifierImpl::SubscribeToSigninEvents(
PasswordStore* store) { PasswordStore* store) {
set_store(store); set_store(store);
SigninManagerFactory::GetForProfile(profile_)->AddObserver(this); IdentityManagerFactory::GetForProfile(profile_)->AddObserver(this);
AccountTrackerServiceFactory::GetForProfile(profile_)->AddObserver(this); AccountTrackerServiceFactory::GetForProfile(profile_)->AddObserver(this);
} }
void PasswordStoreSigninNotifierImpl::UnsubscribeFromSigninEvents() { void PasswordStoreSigninNotifierImpl::UnsubscribeFromSigninEvents() {
SigninManagerFactory::GetForProfile(profile_)->RemoveObserver(this);
AccountTrackerServiceFactory::GetForProfile(profile_)->RemoveObserver(this); AccountTrackerServiceFactory::GetForProfile(profile_)->RemoveObserver(this);
IdentityManagerFactory::GetForProfile(profile_)->RemoveObserver(this);
} }
void PasswordStoreSigninNotifierImpl::GoogleSigninSucceededWithPassword( void PasswordStoreSigninNotifierImpl::OnPrimaryAccountSetWithPassword(
const std::string& account_id, const AccountInfo& account_info,
const std::string& username,
const std::string& password) { const std::string& password) {
NotifySignin(username, password); NotifySignin(account_info.email, password);
} }
void PasswordStoreSigninNotifierImpl::GoogleSignedOut( void PasswordStoreSigninNotifierImpl::OnPrimaryAccountCleared(
const std::string& account_id, const AccountInfo& account_info) {
const std::string& username) { NotifySignedOut(account_info.email, /* primary_account= */ true);
NotifySignedOut(username, /* primary_account= */ true);
} }
// AccountTrackerService::Observer implementations. // AccountTrackerService::Observer implementations.
void PasswordStoreSigninNotifierImpl::OnAccountRemoved( void PasswordStoreSigninNotifierImpl::OnAccountRemoved(
const AccountInfo& info) { const AccountInfo& info) {
// Only reacts to content area (non-primary) Gaia account sign-out event. // Only reacts to content area (non-primary) Gaia account sign-out event.
if (info.account_id != SigninManagerFactory::GetForProfile(profile_) if (info.account_id !=
->GetAuthenticatedAccountId()) { IdentityManagerFactory::GetForProfile(profile_)->GetPrimaryAccountId()) {
NotifySignedOut(info.email, /* primary_account= */ false); NotifySignedOut(info.email, /* primary_account= */ false);
} }
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "components/password_manager/core/browser/password_store_signin_notifier.h" #include "components/password_manager/core/browser/password_store_signin_notifier.h"
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/signin_manager_base.h" #include "services/identity/public/cpp/identity_manager.h"
class Profile; class Profile;
...@@ -17,9 +17,10 @@ namespace password_manager { ...@@ -17,9 +17,10 @@ namespace password_manager {
// Responsible for subscribing to Chrome sign-in events and passing them to // Responsible for subscribing to Chrome sign-in events and passing them to
// PasswordStore. // PasswordStore.
class PasswordStoreSigninNotifierImpl : public PasswordStoreSigninNotifier, class PasswordStoreSigninNotifierImpl
public SigninManagerBase::Observer, : public PasswordStoreSigninNotifier,
public AccountTrackerService::Observer { public identity::IdentityManager::Observer,
public AccountTrackerService::Observer {
public: public:
explicit PasswordStoreSigninNotifierImpl(Profile* profile); explicit PasswordStoreSigninNotifierImpl(Profile* profile);
~PasswordStoreSigninNotifierImpl() override; ~PasswordStoreSigninNotifierImpl() override;
...@@ -29,12 +30,9 @@ class PasswordStoreSigninNotifierImpl : public PasswordStoreSigninNotifier, ...@@ -29,12 +30,9 @@ class PasswordStoreSigninNotifierImpl : public PasswordStoreSigninNotifier,
void UnsubscribeFromSigninEvents() override; void UnsubscribeFromSigninEvents() override;
// SigninManagerBase::Observer implementations. // SigninManagerBase::Observer implementations.
void GoogleSigninSucceededWithPassword(const std::string& account_id, void OnPrimaryAccountSetWithPassword(const AccountInfo& account_info,
const std::string& username, const std::string& password) override;
const std::string& password) override; void OnPrimaryAccountCleared(const AccountInfo& account_info) override;
void GoogleSignedOut(const std::string& account_id,
const std::string& username) override;
// AccountTrackerService::Observer implementations. // AccountTrackerService::Observer implementations.
void OnAccountRemoved(const AccountInfo& info) override; void OnAccountRemoved(const AccountInfo& info) override;
......
...@@ -473,12 +473,11 @@ void SigninManager::OnSignedIn() { ...@@ -473,12 +473,11 @@ void SigninManager::OnSignedIn() {
} }
void SigninManager::FireGoogleSigninSucceeded() { void SigninManager::FireGoogleSigninSucceeded() {
std::string account_id = GetAuthenticatedAccountId(); const AccountInfo account_info = GetAuthenticatedAccountInfo();
std::string email = GetAuthenticatedAccountInfo().email;
for (auto& observer : observer_list_) { for (auto& observer : observer_list_) {
observer.GoogleSigninSucceeded(account_id, email); observer.GoogleSigninSucceeded(account_info.account_id, account_info.email);
observer.GoogleSigninSucceeded(GetAuthenticatedAccountInfo()); observer.GoogleSigninSucceeded(account_info);
observer.GoogleSigninSucceededWithPassword(account_id, email, password_); observer.GoogleSigninSucceededWithPassword(account_info, password_);
} }
} }
......
...@@ -44,10 +44,6 @@ class PrefService; ...@@ -44,10 +44,6 @@ class PrefService;
class SigninClient; class SigninClient;
class SigninErrorController; class SigninErrorController;
namespace password_manager {
class PasswordStoreSigninNotifierImpl;
}
class SigninManagerBase : public KeyedService { class SigninManagerBase : public KeyedService {
public: public:
class Observer { class Observer {
...@@ -59,6 +55,22 @@ class SigninManagerBase : public KeyedService { ...@@ -59,6 +55,22 @@ class SigninManagerBase : public KeyedService {
// This method is not called during a reauth. // This method is not called during a reauth.
virtual void GoogleSigninSucceeded(const AccountInfo& account_info) {} virtual void GoogleSigninSucceeded(const AccountInfo& account_info) {}
// Called when a user signs into Google services such as sync. Also passes
// the password of the Google account that was used to sign in.
// This method is not called during a reauth.
//
// Observers should override |GoogleSigninSucceeded| if they are not
// interested in the password thas was used during the sign-in.
//
// Note: The password is always empty on mobile as the user signs in to
// Chrome with accounts that were added to the device, so Chrome does not
// have access to the password.
// DEPRECATED: password will be empty if login is using DICE workflow; the
// method will be removed once all login is using the DICE workflow.
virtual void GoogleSigninSucceededWithPassword(
const AccountInfo& account_info,
const std::string& password) {}
// DEPRECATED: Use the above method instead. // DEPRECATED: Use the above method instead.
virtual void GoogleSigninSucceeded(const std::string& account_id, virtual void GoogleSigninSucceeded(const std::string& account_id,
const std::string& username) {} const std::string& username) {}
...@@ -74,29 +86,10 @@ class SigninManagerBase : public KeyedService { ...@@ -74,29 +86,10 @@ class SigninManagerBase : public KeyedService {
virtual ~Observer() {} virtual ~Observer() {}
private: private:
// Observers that can observer the password of the Google account after a
// successful sign-in.
friend class PasswordStoreSigninNotifierImpl;
// SigninManagers that fire |GoogleSigninSucceededWithPassword| // SigninManagers that fire |GoogleSigninSucceededWithPassword|
// notifications. // notifications.
friend class SigninManager; friend class SigninManager;
friend class FakeSigninManager; friend class FakeSigninManager;
// Called when a user signs into Google services such as sync. Also passes
// the password of the Google account that was used to sign in.
// This method is not called during a reauth.
//
// Observers should override |GoogleSigninSucceeded| if they are not
// interested in the password thas was used during the sign-in.
//
// Note: The password is always empty on mobile as the user signs in to
// Chrome with accounts that were added to the device, so Chrome does not
// have access to the password.
virtual void GoogleSigninSucceededWithPassword(
const std::string& account_id,
const std::string& username,
const std::string& password) {}
}; };
// On non-ChromeOS platforms, SigninManagerBase should only be instantiated // On non-ChromeOS platforms, SigninManagerBase should only be instantiated
......
...@@ -61,8 +61,7 @@ class TestSigninManagerObserver : public SigninManagerBase::Observer { ...@@ -61,8 +61,7 @@ class TestSigninManagerObserver : public SigninManagerBase::Observer {
num_successful_signins_++; num_successful_signins_++;
} }
void GoogleSigninSucceededWithPassword(const std::string& account_id, void GoogleSigninSucceededWithPassword(const AccountInfo& account_info,
const std::string& username,
const std::string& password) override { const std::string& password) override {
num_successful_signins_with_password_++; num_successful_signins_with_password_++;
} }
......
...@@ -281,6 +281,14 @@ void IdentityManager::GoogleSigninSucceeded(const AccountInfo& account_info) { ...@@ -281,6 +281,14 @@ void IdentityManager::GoogleSigninSucceeded(const AccountInfo& account_info) {
} }
} }
void IdentityManager::GoogleSigninSucceededWithPassword(
const AccountInfo& account_info,
const std::string& password) {
for (auto& observer : observer_list_) {
observer.OnPrimaryAccountSetWithPassword(account_info, password);
}
}
void IdentityManager::GoogleSignedOut(const AccountInfo& account_info) { void IdentityManager::GoogleSignedOut(const AccountInfo& account_info) {
DCHECK(!HasPrimaryAccount()); DCHECK(!HasPrimaryAccount());
for (auto& observer : observer_list_) { for (auto& observer : observer_list_) {
......
...@@ -68,6 +68,14 @@ class IdentityManager : public SigninManagerBase::Observer, ...@@ -68,6 +68,14 @@ class IdentityManager : public SigninManagerBase::Observer,
// This method is not called during a reauth. // This method is not called during a reauth.
virtual void OnPrimaryAccountSet(const AccountInfo& primary_account_info) {} virtual void OnPrimaryAccountSet(const AccountInfo& primary_account_info) {}
// Called when an account becomes the user's primary account using the
// legacy workflow (non-DICE). If access to the password is not required,
// it is preferred to instead override OnPrimaryAccountSet() which will
// also be called at the same time.
virtual void OnPrimaryAccountSetWithPassword(
const AccountInfo& primary_account_info,
const std::string& password) {}
// Called when when the user moves from having a primary account to no // Called when when the user moves from having a primary account to no
// longer having a primary account. // longer having a primary account.
virtual void OnPrimaryAccountCleared( virtual void OnPrimaryAccountCleared(
...@@ -336,6 +344,8 @@ class IdentityManager : public SigninManagerBase::Observer, ...@@ -336,6 +344,8 @@ class IdentityManager : public SigninManagerBase::Observer,
// SigninManagerBase::Observer: // SigninManagerBase::Observer:
void GoogleSigninSucceeded(const AccountInfo& account_info) override; void GoogleSigninSucceeded(const AccountInfo& account_info) override;
void GoogleSigninSucceededWithPassword(const AccountInfo& account_info,
const std::string& password) override;
void GoogleSignedOut(const AccountInfo& account_info) override; void GoogleSignedOut(const AccountInfo& account_info) override;
void GoogleSigninFailed(const GoogleServiceAuthError& error) override; void GoogleSigninFailed(const GoogleServiceAuthError& error) override;
......
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