Commit aebef493 authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Remove GaiaCookieManagerService dependency from ChildAccountService

ChildAccountService was observing changes the list of gaia accounts in
the cookie jar in order to notify its observers. We can achieve the
same behaviour by observing IdentityManager instead.

Apart from that the call to GaiaCookieManagerService::ListAccounts()
was successfully replaced by
IdentityManager::GetAccountsInCookieJar(). This allows us to
completely remove the dependency on GaiaCookieManagerService.

Bug: 921007
Change-Id: I7acc064c65ae2d61eb9d807e08183f2ee30e5183
Reviewed-on: https://chromium-review.googlesource.com/c/1409010
Commit-Queue: Sergio Villar <svillar@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629957}
parent e85090e8
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary.h" #include "chrome/browser/supervised_user/child_accounts/permission_request_creator_apiary.h"
#include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h" #include "chrome/browser/supervised_user/experimental/safe_search_url_reporter.h"
...@@ -31,7 +30,6 @@ ...@@ -31,7 +30,6 @@
#include "components/signin/core/browser/gaia_cookie_manager_service.h" #include "components/signin/core/browser/gaia_cookie_manager_service.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "services/identity/public/cpp/identity_manager.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
...@@ -74,13 +72,10 @@ ChildAccountService::ChildAccountService(Profile* profile) ...@@ -74,13 +72,10 @@ ChildAccountService::ChildAccountService(Profile* profile)
: profile_(profile), : profile_(profile),
active_(false), active_(false),
family_fetch_backoff_(&kFamilyFetchBackoffPolicy), family_fetch_backoff_(&kFamilyFetchBackoffPolicy),
gaia_cookie_manager_( identity_manager_(IdentityManagerFactory::GetForProfile(profile)),
GaiaCookieManagerServiceFactory::GetForProfile(profile)), weak_ptr_factory_(this) {}
weak_ptr_factory_(this) {
}
ChildAccountService::~ChildAccountService() { ChildAccountService::~ChildAccountService() {}
}
// static // static
bool ChildAccountService::IsChildAccountDetectionEnabled() { bool ChildAccountService::IsChildAccountDetectionEnabled() {
...@@ -100,17 +95,14 @@ void ChildAccountService::RegisterProfilePrefs( ...@@ -100,17 +95,14 @@ void ChildAccountService::RegisterProfilePrefs(
void ChildAccountService::Init() { void ChildAccountService::Init() {
SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this); SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(this);
gaia_cookie_manager_->AddObserver(this); identity_manager_->AddObserver(this);
IdentityManagerFactory::GetForProfile(profile_)->AddObserver(this);
PropagateChildStatusToUser(profile_->IsChild()); PropagateChildStatusToUser(profile_->IsChild());
// If we're already signed in, check the account immediately just to be sure. // If we're already signed in, check the account immediately just to be sure.
// (We might have missed an update before registering as an observer.) // (We might have missed an update before registering as an observer.)
identity::IdentityManager* identity_manager = if (identity_manager_->HasPrimaryAccount())
IdentityManagerFactory::GetForProfile(profile_); OnAccountUpdated(identity_manager_->GetPrimaryAccountInfo());
if (identity_manager->HasPrimaryAccount())
OnAccountUpdated(identity_manager->GetPrimaryAccountInfo());
} }
bool ChildAccountService::IsChildAccountStatusKnown() { bool ChildAccountService::IsChildAccountStatusKnown() {
...@@ -119,8 +111,7 @@ bool ChildAccountService::IsChildAccountStatusKnown() { ...@@ -119,8 +111,7 @@ bool ChildAccountService::IsChildAccountStatusKnown() {
void ChildAccountService::Shutdown() { void ChildAccountService::Shutdown() {
family_fetcher_.reset(); family_fetcher_.reset();
IdentityManagerFactory::GetForProfile(profile_)->RemoveObserver(this); identity_manager_->RemoveObserver(this);
gaia_cookie_manager_->RemoveObserver(this);
SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(nullptr); SupervisedUserServiceFactory::GetForProfile(profile_)->SetDelegate(nullptr);
DCHECK(!active_); DCHECK(!active_);
} }
...@@ -134,12 +125,17 @@ void ChildAccountService::AddChildStatusReceivedCallback( ...@@ -134,12 +125,17 @@ void ChildAccountService::AddChildStatusReceivedCallback(
} }
ChildAccountService::AuthState ChildAccountService::GetGoogleAuthState() { ChildAccountService::AuthState ChildAccountService::GetGoogleAuthState() {
std::vector<gaia::ListedAccount> accounts; identity::AccountsInCookieJarInfo accounts_in_cookie_jar_info =
std::vector<gaia::ListedAccount> signed_out_accounts; identity_manager_->GetAccountsInCookieJar();
if (!gaia_cookie_manager_->ListAccounts(&accounts, &signed_out_accounts)) if (!accounts_in_cookie_jar_info.accounts_are_fresh)
return AuthState::PENDING; return AuthState::PENDING;
return (accounts.empty() || !accounts[0].valid) ? AuthState::NOT_AUTHENTICATED
: AuthState::AUTHENTICATED; bool first_account_authenticated =
!accounts_in_cookie_jar_info.signed_in_accounts.empty() &&
accounts_in_cookie_jar_info.signed_in_accounts[0].valid;
return first_account_authenticated ? AuthState::AUTHENTICATED
: AuthState::NOT_AUTHENTICATED;
} }
std::unique_ptr<base::CallbackList<void()>::Subscription> std::unique_ptr<base::CallbackList<void()>::Subscription>
...@@ -260,8 +256,7 @@ void ChildAccountService::OnAccountUpdated(const AccountInfo& info) { ...@@ -260,8 +256,7 @@ void ChildAccountService::OnAccountUpdated(const AccountInfo& info) {
return; return;
} }
std::string auth_account_id = std::string auth_account_id = identity_manager_->GetPrimaryAccountId();
IdentityManagerFactory::GetForProfile(profile_)->GetPrimaryAccountId();
if (info.account_id != auth_account_id) if (info.account_id != auth_account_id)
return; return;
...@@ -307,16 +302,15 @@ void ChildAccountService::OnFailure(FamilyInfoFetcher::ErrorCode error) { ...@@ -307,16 +302,15 @@ void ChildAccountService::OnFailure(FamilyInfoFetcher::ErrorCode error) {
ScheduleNextFamilyInfoUpdate(family_fetch_backoff_.GetTimeUntilRelease()); ScheduleNextFamilyInfoUpdate(family_fetch_backoff_.GetTimeUntilRelease());
} }
void ChildAccountService::OnGaiaAccountsInCookieUpdated( void ChildAccountService::OnAccountsInCookieUpdated(
const std::vector<gaia::ListedAccount>& accounts, const identity::AccountsInCookieJarInfo& accounts_in_cookie_jar_info,
const std::vector<gaia::ListedAccount>& signed_out_accounts,
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
google_auth_state_observers_.Notify(); google_auth_state_observers_.Notify();
} }
void ChildAccountService::StartFetchingFamilyInfo() { void ChildAccountService::StartFetchingFamilyInfo() {
family_fetcher_.reset(new FamilyInfoFetcher( family_fetcher_.reset(new FamilyInfoFetcher(
this, IdentityManagerFactory::GetForProfile(profile_), this, identity_manager_,
content::BrowserContext::GetDefaultStoragePartition(profile_) content::BrowserContext::GetDefaultStoragePartition(profile_)
->GetURLLoaderFactoryForBrowserProcess())); ->GetURLLoaderFactoryForBrowserProcess()));
family_fetcher_->StartGetFamilyMembers(); family_fetcher_->StartGetFamilyMembers();
......
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
#include "base/callback_list.h" #include "base/callback_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h" #include "chrome/browser/supervised_user/child_accounts/family_info_fetcher.h"
#include "chrome/browser/supervised_user/supervised_user_service.h" #include "chrome/browser/supervised_user/supervised_user_service.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/signin/core/browser/gaia_cookie_manager_service.h"
#include "net/base/backoff_entry.h" #include "net/base/backoff_entry.h"
#include "services/identity/public/cpp/identity_manager.h" #include "services/identity/public/cpp/identity_manager.h"
...@@ -34,8 +34,7 @@ class Profile; ...@@ -34,8 +34,7 @@ class Profile;
class ChildAccountService : public KeyedService, class ChildAccountService : public KeyedService,
public FamilyInfoFetcher::Consumer, public FamilyInfoFetcher::Consumer,
public identity::IdentityManager::Observer, public identity::IdentityManager::Observer,
public SupervisedUserService::Delegate, public SupervisedUserService::Delegate {
public GaiaCookieManagerService::Observer {
public: public:
enum class AuthState { AUTHENTICATED, NOT_AUTHENTICATED, PENDING }; enum class AuthState { AUTHENTICATED, NOT_AUTHENTICATED, PENDING };
...@@ -88,10 +87,9 @@ class ChildAccountService : public KeyedService, ...@@ -88,10 +87,9 @@ class ChildAccountService : public KeyedService,
const std::vector<FamilyInfoFetcher::FamilyMember>& members) override; const std::vector<FamilyInfoFetcher::FamilyMember>& members) override;
void OnFailure(FamilyInfoFetcher::ErrorCode error) override; void OnFailure(FamilyInfoFetcher::ErrorCode error) override;
// GaiaCookieManagerService::Observer implementation. // IdentityManager::Observer implementation.
void OnGaiaAccountsInCookieUpdated( void OnAccountsInCookieUpdated(
const std::vector<gaia::ListedAccount>& accounts, const identity::AccountsInCookieJarInfo& accounts_in_cookie_jar_info,
const std::vector<gaia::ListedAccount>& signed_out_accounts,
const GoogleServiceAuthError& error) override; const GoogleServiceAuthError& error) override;
void StartFetchingFamilyInfo(); void StartFetchingFamilyInfo();
...@@ -116,7 +114,7 @@ class ChildAccountService : public KeyedService, ...@@ -116,7 +114,7 @@ class ChildAccountService : public KeyedService,
base::OneShotTimer family_fetch_timer_; base::OneShotTimer family_fetch_timer_;
net::BackoffEntry family_fetch_backoff_; net::BackoffEntry family_fetch_backoff_;
GaiaCookieManagerService* gaia_cookie_manager_; identity::IdentityManager* identity_manager_;
base::CallbackList<void()> google_auth_state_observers_; base::CallbackList<void()> google_auth_state_observers_;
......
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