Commit cc13e7eb authored by David Roger's avatar David Roger Committed by Commit Bot

[signin] Cleanup the SigninClient implementations

- SigninClient duplicates API that is already in
  SigninManagerBase::Observer. This CL removes these functions from the
  SigninClient and uses SigninManagerBase::Observer instead.
- Several SigninClient implementations depend on SigninErrorController,
  but this dependency is conceptually wrong. This CL moves the
  corresponding code out of SigninClient implementations.

Change-Id: I4a09e40a204713ba3cb8ea76e65c46228fc3923d
Bug: 836212
Reviewed-on: https://chromium-review.googlesource.com/c/1346950
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612170}
parent 34c52daf
...@@ -1451,6 +1451,10 @@ jumbo_split_static_library("browser") { ...@@ -1451,6 +1451,10 @@ jumbo_split_static_library("browser") {
"signin/signin_error_controller_factory.h", "signin/signin_error_controller_factory.h",
"signin/signin_manager_factory.cc", "signin/signin_manager_factory.cc",
"signin/signin_manager_factory.h", "signin/signin_manager_factory.h",
"signin/signin_profile_attributes_updater.cc",
"signin/signin_profile_attributes_updater.h",
"signin/signin_profile_attributes_updater_factory.cc",
"signin/signin_profile_attributes_updater_factory.h",
"signin/signin_promo_util.cc", "signin/signin_promo_util.cc",
"signin/signin_promo_util.h", "signin/signin_promo_util.h",
"signin/signin_status_metrics_provider_chromeos.cc", "signin/signin_status_metrics_provider_chromeos.cc",
......
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
#include "chrome/browser/signin/account_tracker_service_factory.h" #include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h" #include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/signin_profile_attributes_updater_factory.h"
#include "chrome/browser/sync/model_type_store_service_factory.h" #include "chrome/browser/sync/model_type_store_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/user_event_service_factory.h" #include "chrome/browser/sync/user_event_service_factory.h"
...@@ -371,6 +372,7 @@ void ChromeBrowserMainExtraPartsProfiles:: ...@@ -371,6 +372,7 @@ void ChromeBrowserMainExtraPartsProfiles::
#endif #endif
ShortcutsBackendFactory::GetInstance(); ShortcutsBackendFactory::GetInstance();
SigninManagerFactory::GetInstance(); SigninManagerFactory::GetInstance();
SigninProfileAttributesUpdaterFactory::GetInstance();
if (SiteEngagementService::IsEnabled()) if (SiteEngagementService::IsEnabled())
SiteEngagementServiceFactory::GetInstance(); SiteEngagementServiceFactory::GetInstance();
......
...@@ -94,21 +94,16 @@ SigninClient::SignoutDecision IsSignoutAllowed( ...@@ -94,21 +94,16 @@ SigninClient::SignoutDecision IsSignoutAllowed(
} // namespace } // namespace
ChromeSigninClient::ChromeSigninClient( ChromeSigninClient::ChromeSigninClient(Profile* profile)
Profile* profile,
SigninErrorController* signin_error_controller)
: OAuth2TokenService::Consumer("chrome_signin_client"), : OAuth2TokenService::Consumer("chrome_signin_client"),
profile_(profile), profile_(profile),
signin_error_controller_(signin_error_controller),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
signin_error_controller_->AddObserver(this);
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
content::GetNetworkConnectionTracker()->AddNetworkConnectionObserver(this); content::GetNetworkConnectionTracker()->AddNetworkConnectionObserver(this);
#endif #endif
} }
ChromeSigninClient::~ChromeSigninClient() { ChromeSigninClient::~ChromeSigninClient() {
signin_error_controller_->RemoveObserver(this);
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
content::GetNetworkConnectionTracker()->RemoveNetworkConnectionObserver(this); content::GetNetworkConnectionTracker()->RemoveNetworkConnectionObserver(this);
#endif #endif
...@@ -128,22 +123,6 @@ bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) { ...@@ -128,22 +123,6 @@ bool ChromeSigninClient::ProfileAllowsSigninCookies(Profile* profile) {
PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); } PrefService* ChromeSigninClient::GetPrefs() { return profile_->GetPrefs(); }
void ChromeSigninClient::OnSignedOut() {
ProfileAttributesEntry* entry;
bool has_entry = g_browser_process->profile_manager()->
GetProfileAttributesStorage().
GetProfileAttributesWithPath(profile_->GetPath(), &entry);
// If sign out occurs because Sync setup was in progress and the Profile got
// deleted, then the profile's no longer in the ProfileAttributesStorage.
if (!has_entry)
return;
entry->SetLocalAuthCredentials(std::string());
entry->SetAuthInfo(std::string(), base::string16());
entry->SetIsSigninRequired(false);
}
scoped_refptr<network::SharedURLLoaderFactory> scoped_refptr<network::SharedURLLoaderFactory>
ChromeSigninClient::GetURLLoaderFactory() { ChromeSigninClient::GetURLLoaderFactory() {
if (url_loader_factory_for_testing_) if (url_loader_factory_for_testing_)
...@@ -191,19 +170,6 @@ void ChromeSigninClient::RemoveContentSettingsObserver( ...@@ -191,19 +170,6 @@ void ChromeSigninClient::RemoveContentSettingsObserver(
->RemoveObserver(observer); ->RemoveObserver(observer);
} }
void ChromeSigninClient::OnSignedIn(const std::string& account_id,
const std::string& gaia_id,
const std::string& username,
const std::string& password) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
ProfileAttributesEntry* entry;
if (profile_manager->GetProfileAttributesStorage().
GetProfileAttributesWithPath(profile_->GetPath(), &entry)) {
entry->SetAuthInfo(gaia_id, base::UTF8ToUTF16(username));
ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager);
}
}
void ChromeSigninClient::PostSignedIn(const std::string& account_id, void ChromeSigninClient::PostSignedIn(const std::string& account_id,
const std::string& username, const std::string& username,
const std::string& password) { const std::string& password) {
...@@ -261,21 +227,6 @@ void ChromeSigninClient::PreSignOut( ...@@ -261,21 +227,6 @@ void ChromeSigninClient::PreSignOut(
} }
} }
void ChromeSigninClient::OnErrorChanged() {
// Some tests don't have a ProfileManager.
if (g_browser_process->profile_manager() == nullptr)
return;
ProfileAttributesEntry* entry;
if (!g_browser_process->profile_manager()->GetProfileAttributesStorage().
GetProfileAttributesWithPath(profile_->GetPath(), &entry)) {
return;
}
entry->SetIsAuthError(signin_error_controller_->HasError());
}
void ChromeSigninClient::OnGetTokenInfoResponse( void ChromeSigninClient::OnGetTokenInfoResponse(
std::unique_ptr<base::DictionaryValue> token_info) { std::unique_ptr<base::DictionaryValue> token_info) {
if (!token_info->HasKey("error")) { if (!token_info->HasKey("error")) {
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/signin/core/browser/signin_client.h" #include "components/signin/core/browser/signin_client.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "google_apis/gaia/gaia_oauth_client.h" #include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gaia/oauth2_token_service.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
...@@ -31,12 +30,10 @@ class ChromeSigninClient ...@@ -31,12 +30,10 @@ class ChromeSigninClient
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
public network::NetworkConnectionTracker::NetworkConnectionObserver, public network::NetworkConnectionTracker::NetworkConnectionObserver,
#endif #endif
public SigninErrorController::Observer,
public gaia::GaiaOAuthClient::Delegate, public gaia::GaiaOAuthClient::Delegate,
public OAuth2TokenService::Consumer { public OAuth2TokenService::Consumer {
public: public:
explicit ChromeSigninClient( explicit ChromeSigninClient(Profile* profile);
Profile* profile, SigninErrorController* signin_error_controller);
~ChromeSigninClient() override; ~ChromeSigninClient() override;
void DoFinalInit() override; void DoFinalInit() override;
...@@ -49,7 +46,6 @@ class ChromeSigninClient ...@@ -49,7 +46,6 @@ class ChromeSigninClient
void PreSignOut( void PreSignOut(
base::OnceCallback<void(SignoutDecision)> on_signout_decision_reached, base::OnceCallback<void(SignoutDecision)> on_signout_decision_reached,
signin_metrics::ProfileSignout signout_source_metric) override; signin_metrics::ProfileSignout signout_source_metric) override;
void OnSignedOut() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override; scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
network::mojom::CookieManager* GetCookieManager() override; network::mojom::CookieManager* GetCookieManager() override;
bool IsFirstRun() const override; bool IsFirstRun() const override;
...@@ -70,17 +66,10 @@ class ChromeSigninClient ...@@ -70,17 +66,10 @@ class ChromeSigninClient
// <Build Info> <OS> <Version number> (<Last change>)<channel or "-devel"> // <Build Info> <OS> <Version number> (<Last change>)<channel or "-devel">
// If version information is unavailable, returns "invalid." // If version information is unavailable, returns "invalid."
std::string GetProductVersion() override; std::string GetProductVersion() override;
void OnSignedIn(const std::string& account_id,
const std::string& gaia_id,
const std::string& username,
const std::string& password) override;
void PostSignedIn(const std::string& account_id, void PostSignedIn(const std::string& account_id,
const std::string& username, const std::string& username,
const std::string& password) override; const std::string& password) override;
// SigninErrorController::Observer implementation.
void OnErrorChanged() override;
// gaia::GaiaOAuthClient::Delegate implementation. // gaia::GaiaOAuthClient::Delegate implementation.
void OnGetTokenInfoResponse( void OnGetTokenInfoResponse(
std::unique_ptr<base::DictionaryValue> token_info) override; std::unique_ptr<base::DictionaryValue> token_info) override;
...@@ -122,8 +111,6 @@ class ChromeSigninClient ...@@ -122,8 +111,6 @@ class ChromeSigninClient
Profile* profile_; Profile* profile_;
SigninErrorController* signin_error_controller_;
// Stored callback from PreSignOut(); // Stored callback from PreSignOut();
base::OnceCallback<void(SignoutDecision)> on_signout_decision_reached_; base::OnceCallback<void(SignoutDecision)> on_signout_decision_reached_;
......
...@@ -4,18 +4,14 @@ ...@@ -4,18 +4,14 @@
#include "chrome/browser/signin/chrome_signin_client_factory.h" #include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "base/bind.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h" #include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/signin/core/browser/account_consistency_method.h"
ChromeSigninClientFactory::ChromeSigninClientFactory() ChromeSigninClientFactory::ChromeSigninClientFactory()
: BrowserContextKeyedServiceFactory( : BrowserContextKeyedServiceFactory(
"ChromeSigninClient", "ChromeSigninClient",
BrowserContextDependencyManager::GetInstance()) { BrowserContextDependencyManager::GetInstance()) {
DependsOn(SigninErrorControllerFactory::GetInstance());
} }
ChromeSigninClientFactory::~ChromeSigninClientFactory() {} ChromeSigninClientFactory::~ChromeSigninClientFactory() {}
...@@ -33,10 +29,7 @@ ChromeSigninClientFactory* ChromeSigninClientFactory::GetInstance() { ...@@ -33,10 +29,7 @@ ChromeSigninClientFactory* ChromeSigninClientFactory::GetInstance() {
KeyedService* ChromeSigninClientFactory::BuildServiceInstanceFor( KeyedService* ChromeSigninClientFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context); return new ChromeSigninClient(Profile::FromBrowserContext(context));
ChromeSigninClient* client = new ChromeSigninClient(
profile, SigninErrorControllerFactory::GetForProfile(profile));
return client;
} }
void ChromeSigninClientFactory::RegisterProfilePrefs( void ChromeSigninClientFactory::RegisterProfilePrefs(
......
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
#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/chrome_signin_client_factory.h" #include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_util.h" #include "chrome/browser/signin/signin_util.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/signin/core/browser/account_consistency_method.h" #include "components/signin/core/browser/account_consistency_method.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "content/public/browser/network_service_instance.h" #include "content/public/browser/network_service_instance.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "services/network/test/test_network_connection_tracker.h" #include "services/network/test/test_network_connection_tracker.h"
...@@ -131,8 +131,8 @@ TEST_F(ChromeSigninClientTest, DelayNetworkCallRunsAfterNetworkChange) { ...@@ -131,8 +131,8 @@ TEST_F(ChromeSigninClientTest, DelayNetworkCallRunsAfterNetworkChange) {
class MockChromeSigninClient : public ChromeSigninClient { class MockChromeSigninClient : public ChromeSigninClient {
public: public:
MockChromeSigninClient(Profile* profile, SigninErrorController* controller) explicit MockChromeSigninClient(Profile* profile)
: ChromeSigninClient(profile, controller) {} : ChromeSigninClient(profile) {}
MOCK_METHOD1(ShowUserManager, void(const base::FilePath&)); MOCK_METHOD1(ShowUserManager, void(const base::FilePath&));
MOCK_METHOD1(LockForceSigninProfile, void(const base::FilePath&)); MOCK_METHOD1(LockForceSigninProfile, void(const base::FilePath&));
...@@ -177,9 +177,9 @@ class ChromeSigninClientSignoutTest : public BrowserWithTestWindowTest { ...@@ -177,9 +177,9 @@ class ChromeSigninClientSignoutTest : public BrowserWithTestWindowTest {
} }
void CreateClient(Profile* profile) { void CreateClient(Profile* profile) {
client_.reset(new MockChromeSigninClient(profile));
SigninErrorController* controller = new SigninErrorController( SigninErrorController* controller = new SigninErrorController(
SigninErrorController::AccountMode::ANY_ACCOUNT); SigninErrorController::AccountMode::ANY_ACCOUNT);
client_.reset(new MockChromeSigninClient(profile, controller));
fake_controller_.reset(controller); fake_controller_.reset(controller);
} }
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/signin/signin_profile_attributes_updater.h"
#include <string>
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/signin/core/browser/account_info.h"
SigninProfileAttributesUpdater::SigninProfileAttributesUpdater(
SigninManagerBase* signin_manager,
SigninErrorController* signin_error_controller,
const base::FilePath& profile_path)
: signin_error_controller_(signin_error_controller),
profile_path_(profile_path),
signin_error_controller_observer_(this),
signin_manager_observer_(this) {
signin_error_controller_observer_.Add(signin_error_controller);
// TODO(crbug.com/908457): Call OnErrorChanged() here, to catch any change
// that happened since the construction of SigninErrorController. Profile
// metrics depend on this bug and must be fixed first.
}
SigninProfileAttributesUpdater::~SigninProfileAttributesUpdater() = default;
void SigninProfileAttributesUpdater::Shutdown() {
signin_error_controller_observer_.RemoveAll();
signin_manager_observer_.RemoveAll();
}
void SigninProfileAttributesUpdater::OnErrorChanged() {
// Some tests don't have a ProfileManager.
if (g_browser_process->profile_manager() == nullptr)
return;
ProfileAttributesEntry* entry;
if (!g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile_path_, &entry)) {
return;
}
entry->SetIsAuthError(signin_error_controller_->HasError());
}
#if !defined(OS_CHROMEOS)
void SigninProfileAttributesUpdater::GoogleSigninSucceeded(
const AccountInfo& account_info) {
ProfileAttributesEntry* entry;
ProfileManager* profile_manager = g_browser_process->profile_manager();
if (!profile_manager->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile_path_, &entry)) {
return;
}
entry->SetAuthInfo(account_info.gaia, base::UTF8ToUTF16(account_info.email));
ProfileMetrics::UpdateReportedProfilesStatistics(profile_manager);
}
void SigninProfileAttributesUpdater::GoogleSignedOut(
const AccountInfo& account_info) {
ProfileAttributesEntry* entry;
bool has_entry = g_browser_process->profile_manager()
->GetProfileAttributesStorage()
.GetProfileAttributesWithPath(profile_path_, &entry);
// If sign out occurs because Sync setup was in progress and the Profile got
// deleted, then the profile's no longer in the ProfileAttributesStorage.
if (!has_entry)
return;
entry->SetLocalAuthCredentials(std::string());
entry->SetAuthInfo(std::string(), base::string16());
entry->SetIsSigninRequired(false);
}
#endif // !defined(OS_CHROMEOS)
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SIGNIN_SIGNIN_PROFILE_ATTRIBUTES_UPDATER_H_
#define CHROME_BROWSER_SIGNIN_SIGNIN_PROFILE_ATTRIBUTES_UPDATER_H_
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "build/build_config.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_manager_base.h"
// This class listens to various signin events and updates the signin-related
// fields of ProfileAttributes.
class SigninProfileAttributesUpdater : public KeyedService,
public SigninErrorController::Observer,
public SigninManagerBase::Observer {
public:
SigninProfileAttributesUpdater(SigninManagerBase* signin_manager,
SigninErrorController* signin_error_controller,
const base::FilePath& profile_path);
~SigninProfileAttributesUpdater() override;
private:
// KeyedService:
void Shutdown() override;
// SigninErrorController::Observer:
void OnErrorChanged() override;
// These observer methods are never called on ChromeOS.
#if !defined(OS_CHROMEOS)
// SigninManagerBase::Observer:
void GoogleSigninSucceeded(const AccountInfo& account_info) override;
void GoogleSignedOut(const AccountInfo& account_info) override;
#endif
SigninErrorController* signin_error_controller_;
const base::FilePath profile_path_;
ScopedObserver<SigninErrorController, SigninProfileAttributesUpdater>
signin_error_controller_observer_;
ScopedObserver<SigninManagerBase, SigninProfileAttributesUpdater>
signin_manager_observer_;
DISALLOW_COPY_AND_ASSIGN(SigninProfileAttributesUpdater);
};
#endif // CHROME_BROWSER_SIGNIN_SIGNIN_PROFILE_ATTRIBUTES_UPDATER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/signin/signin_profile_attributes_updater_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_error_controller_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/signin_profile_attributes_updater.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/signin/core/browser/signin_manager.h"
// static
SigninProfileAttributesUpdater*
SigninProfileAttributesUpdaterFactory::GetForProfile(Profile* profile) {
return static_cast<SigninProfileAttributesUpdater*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
SigninProfileAttributesUpdaterFactory*
SigninProfileAttributesUpdaterFactory::GetInstance() {
return base::Singleton<SigninProfileAttributesUpdaterFactory>::get();
}
SigninProfileAttributesUpdaterFactory::SigninProfileAttributesUpdaterFactory()
: BrowserContextKeyedServiceFactory(
"SigninProfileAttributesUpdater",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(SigninErrorControllerFactory::GetInstance());
DependsOn(SigninManagerFactory::GetInstance());
}
SigninProfileAttributesUpdaterFactory::
~SigninProfileAttributesUpdaterFactory() {}
KeyedService* SigninProfileAttributesUpdaterFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
return new SigninProfileAttributesUpdater(
SigninManagerFactory::GetForProfile(profile),
SigninErrorControllerFactory::GetForProfile(profile), profile->GetPath());
}
bool SigninProfileAttributesUpdaterFactory::ServiceIsCreatedWithBrowserContext()
const {
return true;
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SIGNIN_SIGNIN_PROFILE_ATTRIBUTES_UPDATER_FACTORY_H_
#define CHROME_BROWSER_SIGNIN_SIGNIN_PROFILE_ATTRIBUTES_UPDATER_FACTORY_H_
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
class SigninProfileAttributesUpdater;
class SigninProfileAttributesUpdaterFactory
: public BrowserContextKeyedServiceFactory {
public:
// Returns nullptr if this profile cannot have a
// SigninProfileAttributesUpdater (for example, if |profile| is incognito).
static SigninProfileAttributesUpdater* GetForProfile(Profile* profile);
// Returns an instance of the factory singleton.
static SigninProfileAttributesUpdaterFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<
SigninProfileAttributesUpdaterFactory>;
SigninProfileAttributesUpdaterFactory();
~SigninProfileAttributesUpdaterFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
DISALLOW_COPY_AND_ASSIGN(SigninProfileAttributesUpdaterFactory);
};
#endif // CHROME_BROWSER_SIGNIN_SIGNIN_PROFILE_ATTRIBUTES_UPDATER_FACTORY_H_
...@@ -41,9 +41,6 @@ class SigninClient : public KeyedService { ...@@ -41,9 +41,6 @@ class SigninClient : public KeyedService {
~SigninClient() override = default; ~SigninClient() override = default;
// Perform Chrome-specific sign out. This happens when user signs out.
virtual void OnSignedOut() = 0;
// Call when done local initialization and SigninClient can initiate any work // Call when done local initialization and SigninClient can initiate any work
// it has to do that may require other components (like ProfileManager) to be // it has to do that may require other components (like ProfileManager) to be
// available. // available.
...@@ -64,12 +61,6 @@ class SigninClient : public KeyedService { ...@@ -64,12 +61,6 @@ class SigninClient : public KeyedService {
// Signin component is being used. // Signin component is being used.
virtual std::string GetProductVersion() = 0; virtual std::string GetProductVersion() = 0;
// Called after Google signin has succeeded.
virtual void OnSignedIn(const std::string& account_id,
const std::string& gaia_id,
const std::string& username,
const std::string& password) {}
// Called after Google signin has succeeded and GetUserInfo has returned. // Called after Google signin has succeeded and GetUserInfo has returned.
virtual void PostSignedIn(const std::string& account_id, virtual void PostSignedIn(const std::string& account_id,
const std::string& username, const std::string& username,
......
...@@ -228,7 +228,6 @@ void SigninManager::OnSignoutDecisionReached( ...@@ -228,7 +228,6 @@ void SigninManager::OnSignoutDecisionReached(
client_->GetPrefs()->ClearPref(prefs::kGoogleServicesAccountId); client_->GetPrefs()->ClearPref(prefs::kGoogleServicesAccountId);
client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUserAccountId); client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUserAccountId);
client_->GetPrefs()->ClearPref(prefs::kSignedInTime); client_->GetPrefs()->ClearPref(prefs::kSignedInTime);
client_->OnSignedOut();
// Determine the duration the user was logged in and log that to UMA. // Determine the duration the user was logged in and log that to UMA.
if (!signin_time.is_null()) { if (!signin_time.is_null()) {
...@@ -434,9 +433,6 @@ void SigninManager::OnSignedIn() { ...@@ -434,9 +433,6 @@ void SigninManager::OnSignedIn() {
if (!reauth_in_progress) if (!reauth_in_progress)
FireGoogleSigninSucceeded(); FireGoogleSigninSucceeded();
client_->OnSignedIn(GetAuthenticatedAccountId(), gaia_id,
GetAuthenticatedAccountInfo().email, password_);
signin_metrics::LogSigninProfile(client_->IsFirstRun(), signin_metrics::LogSigninProfile(client_->IsFirstRun(),
client_->GetInstallDate()); client_->GetInstallDate());
......
...@@ -67,8 +67,6 @@ void FakeCookieManager::SetCanonicalCookie( ...@@ -67,8 +67,6 @@ void FakeCookieManager::SetCanonicalCookie(
std::move(callback).Run(false); std::move(callback).Run(false);
} }
void TestSigninClient::OnSignedOut() {}
void TestSigninClient::PostSignedIn(const std::string& account_id, void TestSigninClient::PostSignedIn(const std::string& account_id,
const std::string& username, const std::string& username,
const std::string& password) { const std::string& password) {
......
...@@ -38,9 +38,6 @@ class TestSigninClient : public SigninClient { ...@@ -38,9 +38,6 @@ class TestSigninClient : public SigninClient {
// once there is a unit test that requires it. // once there is a unit test that requires it.
PrefService* GetPrefs() override; PrefService* GetPrefs() override;
// Does nothing.
void OnSignedOut() override;
// Trace that this was called. // Trace that this was called.
void PostSignedIn(const std::string& account_id, void PostSignedIn(const std::string& account_id,
const std::string& username, const std::string& username,
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "ios/chrome/browser/signin/authentication_service_factory.h" #include "ios/chrome/browser/signin/authentication_service_factory.h"
#include "ios/chrome/browser/signin/gaia_cookie_manager_service_factory.h" #include "ios/chrome/browser/signin/gaia_cookie_manager_service_factory.h"
#include "ios/chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "ios/chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "ios/chrome/browser/signin/signin_browser_state_info_updater_factory.h"
#include "ios/chrome/browser/signin/signin_client_factory.h" #include "ios/chrome/browser/signin/signin_client_factory.h"
#include "ios/chrome/browser/signin/signin_error_controller_factory.h" #include "ios/chrome/browser/signin/signin_error_controller_factory.h"
#include "ios/chrome/browser/signin/signin_manager_factory.h" #include "ios/chrome/browser/signin/signin_manager_factory.h"
...@@ -79,6 +80,7 @@ ...@@ -79,6 +80,7 @@
void EnsureBrowserStateKeyedServiceFactoriesBuilt() { void EnsureBrowserStateKeyedServiceFactoriesBuilt() {
autofill::PersonalDataManagerFactory::GetInstance(); autofill::PersonalDataManagerFactory::GetInstance();
dom_distiller::DomDistillerServiceFactory::GetInstance(); dom_distiller::DomDistillerServiceFactory::GetInstance();
feature_engagement::TrackerFactory::GetInstance();
ios::AboutSigninInternalsFactory::GetInstance(); ios::AboutSigninInternalsFactory::GetInstance();
ios::AccountConsistencyServiceFactory::GetInstance(); ios::AccountConsistencyServiceFactory::GetInstance();
ios::AccountFetcherServiceFactory::GetInstance(); ios::AccountFetcherServiceFactory::GetInstance();
...@@ -102,36 +104,36 @@ void EnsureBrowserStateKeyedServiceFactoriesBuilt() { ...@@ -102,36 +104,36 @@ void EnsureBrowserStateKeyedServiceFactoriesBuilt() {
ios::WebDataServiceFactory::GetInstance(); ios::WebDataServiceFactory::GetInstance();
ios::WebHistoryServiceFactory::GetInstance(); ios::WebHistoryServiceFactory::GetInstance();
translate::TranslateRankerFactory::GetInstance(); translate::TranslateRankerFactory::GetInstance();
suggestions::SuggestionsServiceFactory::GetInstance();
AuthenticationServiceFactory::GetInstance(); AuthenticationServiceFactory::GetInstance();
BrowserDownloadServiceFactory::GetInstance();
BrowserListFactory::GetInstance(); BrowserListFactory::GetInstance();
BrowserListSessionServiceFactory::GetInstance(); BrowserListSessionServiceFactory::GetInstance();
BrowsingDataRemoverFactory::GetInstance(); BrowsingDataRemoverFactory::GetInstance();
ConsentAuditorFactory::GetInstance(); ConsentAuditorFactory::GetInstance();
feature_engagement::TrackerFactory::GetInstance(); FullscreenControllerFactory::GetInstance();
GoogleLogoServiceFactory::GetInstance();
IOSChromeContentSuggestionsServiceFactory::GetInstance();
IOSChromeDeprecatedProfileInvalidationProviderFactory::GetInstance();
IOSChromeFaviconLoaderFactory::GetInstance();
IOSChromeGCMProfileServiceFactory::GetInstance(); IOSChromeGCMProfileServiceFactory::GetInstance();
IOSChromeLargeIconCacheFactory::GetInstance(); IOSChromeLargeIconCacheFactory::GetInstance();
IOSChromeLargeIconServiceFactory::GetInstance(); IOSChromeLargeIconServiceFactory::GetInstance();
IOSChromeFaviconLoaderFactory::GetInstance();
IOSChromeContentSuggestionsServiceFactory::GetInstance();
IOSChromePasswordStoreFactory::GetInstance(); IOSChromePasswordStoreFactory::GetInstance();
IOSChromeDeprecatedProfileInvalidationProviderFactory::GetInstance();
ModelTypeStoreServiceFactory::GetInstance();
ProfileSyncServiceFactory::GetInstance();
IOSUserEventServiceFactory::GetInstance(); IOSUserEventServiceFactory::GetInstance();
GoogleLogoServiceFactory::GetInstance();
LanguageModelManagerFactory::GetInstance(); LanguageModelManagerFactory::GetInstance();
ModelTypeStoreServiceFactory::GetInstance();
ProfileOAuth2TokenServiceFactory::GetInstance(); ProfileOAuth2TokenServiceFactory::GetInstance();
ProfileSyncServiceFactory::GetInstance();
ReadingListModelFactory::GetInstance(); ReadingListModelFactory::GetInstance();
SigninBrowserStateInfoUpdaterFactory::GetInstance();
SigninClientFactory::GetInstance(); SigninClientFactory::GetInstance();
suggestions::SuggestionsServiceFactory::GetInstance();
SnapshotCacheFactory::GetInstance(); SnapshotCacheFactory::GetInstance();
SyncSetupServiceFactory::GetInstance(); SyncSetupServiceFactory::GetInstance();
TabRestoreServiceDelegateImplIOSFactory::GetInstance(); TabRestoreServiceDelegateImplIOSFactory::GetInstance();
TextToSpeechPlaybackControllerFactory::GetInstance();
TranslateAcceptLanguagesFactory::GetInstance(); TranslateAcceptLanguagesFactory::GetInstance();
UnifiedConsentServiceFactory::GetInstance(); UnifiedConsentServiceFactory::GetInstance();
UrlLanguageHistogramFactory::GetInstance(); UrlLanguageHistogramFactory::GetInstance();
BrowserDownloadServiceFactory::GetInstance();
FullscreenControllerFactory::GetInstance();
TextToSpeechPlaybackControllerFactory::GetInstance();
WebStateListWebUsageEnablerFactory::GetInstance(); WebStateListWebUsageEnablerFactory::GetInstance();
} }
...@@ -18,10 +18,7 @@ ...@@ -18,10 +18,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "components/browsing_data/core/browsing_data_utils.h" #include "components/browsing_data/core/browsing_data_utils.h"
#include "components/browsing_data/core/pref_names.h" #include "components/browsing_data/core/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
#include "components/sync_preferences/pref_service_mock_factory.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/web/public/test/test_web_thread_bundle.h" #include "ios/web/public/test/test_web_thread_bundle.h"
#include "ios/web/public/web_task_traits.h" #include "ios/web/public/web_task_traits.h"
...@@ -40,9 +37,7 @@ class CacheCounterTest : public PlatformTest { ...@@ -40,9 +37,7 @@ class CacheCounterTest : public PlatformTest {
public: public:
CacheCounterTest() { CacheCounterTest() {
TestChromeBrowserState::Builder builder; TestChromeBrowserState::Builder builder;
builder.SetPrefService(CreatePrefService());
browser_state_ = builder.Build(); browser_state_ = builder.Build();
context_getter_ = browser_state_->GetRequestContext(); context_getter_ = browser_state_->GetRequestContext();
} }
...@@ -52,19 +47,6 @@ class CacheCounterTest : public PlatformTest { ...@@ -52,19 +47,6 @@ class CacheCounterTest : public PlatformTest {
PrefService* prefs() { return browser_state_->GetPrefs(); } PrefService* prefs() { return browser_state_->GetPrefs(); }
std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService() {
sync_preferences::PrefServiceMockFactory factory;
scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
new user_prefs::PrefRegistrySyncable);
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs =
factory.CreateSyncable(registry.get());
registry->RegisterIntegerPref(
browsing_data::prefs::kDeleteTimePeriod,
static_cast<int>(browsing_data::TimePeriod::ALL_TIME));
registry->RegisterBooleanPref(browsing_data::prefs::kDeleteCache, true);
return prefs;
}
void SetCacheDeletionPref(bool value) { void SetCacheDeletionPref(bool value) {
prefs()->SetBoolean(browsing_data::prefs::kDeleteCache, value); prefs()->SetBoolean(browsing_data::prefs::kDeleteCache, value);
} }
......
...@@ -41,6 +41,10 @@ source_set("signin") { ...@@ -41,6 +41,10 @@ source_set("signin") {
"profile_oauth2_token_service_factory.mm", "profile_oauth2_token_service_factory.mm",
"profile_oauth2_token_service_ios_provider_impl.h", "profile_oauth2_token_service_ios_provider_impl.h",
"profile_oauth2_token_service_ios_provider_impl.mm", "profile_oauth2_token_service_ios_provider_impl.mm",
"signin_browser_state_info_updater.h",
"signin_browser_state_info_updater.mm",
"signin_browser_state_info_updater_factory.h",
"signin_browser_state_info_updater_factory.mm",
"signin_client_factory.cc", "signin_client_factory.cc",
"signin_client_factory.h", "signin_client_factory.h",
"signin_error_controller_factory.cc", "signin_error_controller_factory.cc",
......
...@@ -66,7 +66,6 @@ class FakeSigninClient : public IOSChromeSigninClient { ...@@ -66,7 +66,6 @@ class FakeSigninClient : public IOSChromeSigninClient {
scoped_refptr<content_settings::CookieSettings> cookie_settings, scoped_refptr<content_settings::CookieSettings> cookie_settings,
scoped_refptr<HostContentSettingsMap> host_content_settings_map) scoped_refptr<HostContentSettingsMap> host_content_settings_map)
: IOSChromeSigninClient(browser_state, : IOSChromeSigninClient(browser_state,
signin_error_controller,
cookie_settings, cookie_settings,
host_content_settings_map) {} host_content_settings_map) {}
~FakeSigninClient() override {} ~FakeSigninClient() override {}
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "components/content_settings/core/browser/cookie_settings.h" #include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/signin/core/browser/signin_client.h" #include "components/signin/core/browser/signin_client.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/ios/browser/wait_for_network_callback_helper.h" #include "components/signin/ios/browser/wait_for_network_callback_helper.h"
#include "net/cookies/cookie_change_dispatcher.h" #include "net/cookies/cookie_change_dispatcher.h"
...@@ -20,12 +19,10 @@ class ChromeBrowserState; ...@@ -20,12 +19,10 @@ class ChromeBrowserState;
} }
// Concrete implementation of SigninClient for //ios/chrome. // Concrete implementation of SigninClient for //ios/chrome.
class IOSChromeSigninClient : public SigninClient, class IOSChromeSigninClient : public SigninClient {
public SigninErrorController::Observer {
public: public:
IOSChromeSigninClient( IOSChromeSigninClient(
ios::ChromeBrowserState* browser_state, ios::ChromeBrowserState* browser_state,
SigninErrorController* signin_error_controller,
scoped_refptr<content_settings::CookieSettings> cookie_settings, scoped_refptr<content_settings::CookieSettings> cookie_settings,
scoped_refptr<HostContentSettingsMap> host_content_settings_map); scoped_refptr<HostContentSettingsMap> host_content_settings_map);
~IOSChromeSigninClient() override; ~IOSChromeSigninClient() override;
...@@ -36,10 +33,6 @@ class IOSChromeSigninClient : public SigninClient, ...@@ -36,10 +33,6 @@ class IOSChromeSigninClient : public SigninClient,
// SigninClient implementation. // SigninClient implementation.
base::Time GetInstallDate() override; base::Time GetInstallDate() override;
std::string GetProductVersion() override; std::string GetProductVersion() override;
void OnSignedIn(const std::string& account_id,
const std::string& gaia_id,
const std::string& username,
const std::string& password) override;
std::unique_ptr<GaiaAuthFetcher> CreateGaiaAuthFetcher( std::unique_ptr<GaiaAuthFetcher> CreateGaiaAuthFetcher(
GaiaAuthConsumer* consumer, GaiaAuthConsumer* consumer,
gaia::GaiaSource source, gaia::GaiaSource source,
...@@ -57,10 +50,6 @@ class IOSChromeSigninClient : public SigninClient, ...@@ -57,10 +50,6 @@ class IOSChromeSigninClient : public SigninClient,
void RemoveContentSettingsObserver( void RemoveContentSettingsObserver(
content_settings::Observer* observer) override; content_settings::Observer* observer) override;
void DelayNetworkCall(const base::Closure& callback) override; void DelayNetworkCall(const base::Closure& callback) override;
void OnSignedOut() override;
// SigninErrorController::Observer implementation.
void OnErrorChanged() override;
private: private:
...@@ -68,8 +57,6 @@ class IOSChromeSigninClient : public SigninClient, ...@@ -68,8 +57,6 @@ class IOSChromeSigninClient : public SigninClient,
std::unique_ptr<WaitForNetworkCallbackHelper> network_callback_helper_; std::unique_ptr<WaitForNetworkCallbackHelper> network_callback_helper_;
// The browser state associated with this service. // The browser state associated with this service.
ios::ChromeBrowserState* browser_state_; ios::ChromeBrowserState* browser_state_;
// Used to check for errors related to signing in.
SigninErrorController* signin_error_controller_;
// Used to check if sign in cookies are allowed. // Used to check if sign in cookies are allowed.
scoped_refptr<content_settings::CookieSettings> cookie_settings_; scoped_refptr<content_settings::CookieSettings> cookie_settings_;
// Used to add and remove content settings observers. // Used to add and remove content settings observers.
......
...@@ -25,20 +25,16 @@ ...@@ -25,20 +25,16 @@
IOSChromeSigninClient::IOSChromeSigninClient( IOSChromeSigninClient::IOSChromeSigninClient(
ios::ChromeBrowserState* browser_state, ios::ChromeBrowserState* browser_state,
SigninErrorController* signin_error_controller,
scoped_refptr<content_settings::CookieSettings> cookie_settings, scoped_refptr<content_settings::CookieSettings> cookie_settings,
scoped_refptr<HostContentSettingsMap> host_content_settings_map) scoped_refptr<HostContentSettingsMap> host_content_settings_map)
: network_callback_helper_( : network_callback_helper_(
std::make_unique<WaitForNetworkCallbackHelper>()), std::make_unique<WaitForNetworkCallbackHelper>()),
browser_state_(browser_state), browser_state_(browser_state),
signin_error_controller_(signin_error_controller),
cookie_settings_(cookie_settings), cookie_settings_(cookie_settings),
host_content_settings_map_(host_content_settings_map) { host_content_settings_map_(host_content_settings_map) {
signin_error_controller_->AddObserver(this);
} }
IOSChromeSigninClient::~IOSChromeSigninClient() { IOSChromeSigninClient::~IOSChromeSigninClient() {
signin_error_controller_->RemoveObserver(this);
} }
void IOSChromeSigninClient::Shutdown() { void IOSChromeSigninClient::Shutdown() {
...@@ -57,38 +53,6 @@ std::string IOSChromeSigninClient::GetProductVersion() { ...@@ -57,38 +53,6 @@ std::string IOSChromeSigninClient::GetProductVersion() {
return GetVersionString(); return GetVersionString();
} }
void IOSChromeSigninClient::OnSignedIn(const std::string& account_id,
const std::string& gaia_id,
const std::string& username,
const std::string& password) {
ios::ChromeBrowserStateManager* browser_state_manager =
GetApplicationContext()->GetChromeBrowserStateManager();
BrowserStateInfoCache* cache =
browser_state_manager->GetBrowserStateInfoCache();
size_t index = cache->GetIndexOfBrowserStateWithPath(
browser_state_->GetOriginalChromeBrowserState()->GetStatePath());
if (index != std::string::npos) {
cache->SetAuthInfoOfBrowserStateAtIndex(index, gaia_id,
base::UTF8ToUTF16(username));
}
}
void IOSChromeSigninClient::OnSignedOut() {
BrowserStateInfoCache* cache = GetApplicationContext()
->GetChromeBrowserStateManager()
->GetBrowserStateInfoCache();
size_t index = cache->GetIndexOfBrowserStateWithPath(
browser_state_->GetOriginalChromeBrowserState()->GetStatePath());
// If sign out occurs because Sync setup was in progress and the browser state
// got deleted, then it is no longer in the cache.
if (index == std::string::npos)
return;
cache->SetAuthInfoOfBrowserStateAtIndex(index, std::string(),
base::string16());
}
PrefService* IOSChromeSigninClient::GetPrefs() { PrefService* IOSChromeSigninClient::GetPrefs() {
return browser_state_->GetPrefs(); return browser_state_->GetPrefs();
} }
...@@ -139,16 +103,3 @@ void IOSChromeSigninClient::PreGaiaLogout(base::OnceClosure callback) { ...@@ -139,16 +103,3 @@ void IOSChromeSigninClient::PreGaiaLogout(base::OnceClosure callback) {
ios::AccountConsistencyServiceFactory::GetForBrowserState(browser_state_); ios::AccountConsistencyServiceFactory::GetForBrowserState(browser_state_);
accountConsistencyService->RemoveChromeConnectedCookies(std::move(callback)); accountConsistencyService->RemoveChromeConnectedCookies(std::move(callback));
} }
void IOSChromeSigninClient::OnErrorChanged() {
BrowserStateInfoCache* cache = GetApplicationContext()
->GetChromeBrowserStateManager()
->GetBrowserStateInfoCache();
size_t index = cache->GetIndexOfBrowserStateWithPath(
browser_state_->GetOriginalChromeBrowserState()->GetStatePath());
if (index == std::string::npos)
return;
cache->SetBrowserStateIsAuthErrorAtIndex(
index, signin_error_controller_->HasError());
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_SIGNIN_SIGNIN_BROWSER_STATE_INFO_UPDATER_H_
#define IOS_CHROME_BROWSER_SIGNIN_SIGNIN_BROWSER_STATE_INFO_UPDATER_H_
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "build/build_config.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/core/browser/signin_error_controller.h"
#include "components/signin/core/browser/signin_manager_base.h"
// This class listens to various signin events and updates the signin-related
// fields of BrowserStateInfoCache.
class SigninBrowserStateInfoUpdater : public KeyedService,
public SigninErrorController::Observer,
public SigninManagerBase::Observer {
public:
SigninBrowserStateInfoUpdater(SigninManagerBase* signin_manager,
SigninErrorController* signin_error_controller,
const base::FilePath& browser_state_path);
~SigninBrowserStateInfoUpdater() override;
private:
// KeyedService:
void Shutdown() override;
// SigninErrorController::Observer:
void OnErrorChanged() override;
// SigninManagerBase::Observer:
void GoogleSigninSucceeded(const AccountInfo& account_info) override;
void GoogleSignedOut(const AccountInfo& account_info) override;
SigninErrorController* signin_error_controller_ = nullptr;
const base::FilePath browser_state_path_;
ScopedObserver<SigninErrorController, SigninBrowserStateInfoUpdater>
signin_error_controller_observer_;
ScopedObserver<SigninManagerBase, SigninBrowserStateInfoUpdater>
signin_manager_observer_;
DISALLOW_COPY_AND_ASSIGN(SigninBrowserStateInfoUpdater);
};
#endif // IOS_CHROME_BROWSER_SIGNIN_SIGNIN_BROWSER_STATE_INFO_UPDATER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/signin/signin_browser_state_info_updater.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#include <string>
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "components/signin/core/browser/account_info.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/browser_state_info_cache.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
SigninBrowserStateInfoUpdater::SigninBrowserStateInfoUpdater(
SigninManagerBase* signin_manager,
SigninErrorController* signin_error_controller,
const base::FilePath& browser_state_path)
: signin_error_controller_(signin_error_controller),
browser_state_path_(browser_state_path),
signin_error_controller_observer_(this),
signin_manager_observer_(this) {
signin_error_controller_observer_.Add(signin_error_controller);
// TODO(crbug.com/908457): Call OnErrorChanged() here, to catch any change
// that happened since the construction of SigninErrorController. BrowserState
// metrics depend on this bug and must be fixed first.
}
SigninBrowserStateInfoUpdater::~SigninBrowserStateInfoUpdater() = default;
void SigninBrowserStateInfoUpdater::Shutdown() {
signin_error_controller_observer_.RemoveAll();
signin_manager_observer_.RemoveAll();
}
void SigninBrowserStateInfoUpdater::OnErrorChanged() {
BrowserStateInfoCache* cache = GetApplicationContext()
->GetChromeBrowserStateManager()
->GetBrowserStateInfoCache();
size_t index = cache->GetIndexOfBrowserStateWithPath(browser_state_path_);
if (index == std::string::npos)
return;
cache->SetBrowserStateIsAuthErrorAtIndex(
index, signin_error_controller_->HasError());
}
void SigninBrowserStateInfoUpdater::GoogleSigninSucceeded(
const AccountInfo& account_info) {
ios::ChromeBrowserStateManager* browser_state_manager =
GetApplicationContext()->GetChromeBrowserStateManager();
BrowserStateInfoCache* cache =
browser_state_manager->GetBrowserStateInfoCache();
size_t index = cache->GetIndexOfBrowserStateWithPath(browser_state_path_);
if (index == std::string::npos)
return;
cache->SetAuthInfoOfBrowserStateAtIndex(
index, account_info.gaia, base::UTF8ToUTF16(account_info.email));
}
void SigninBrowserStateInfoUpdater::GoogleSignedOut(
const AccountInfo& account_info) {
BrowserStateInfoCache* cache = GetApplicationContext()
->GetChromeBrowserStateManager()
->GetBrowserStateInfoCache();
size_t index = cache->GetIndexOfBrowserStateWithPath(browser_state_path_);
// If sign out occurs because Sync setup was in progress and the browser state
// got deleted, then it is no longer in the cache.
if (index == std::string::npos)
return;
cache->SetAuthInfoOfBrowserStateAtIndex(index, /*gaia_id=*/std::string(),
/*user_name=*/base::string16());
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_SIGNIN_SIGNIN_BROWSER_STATE_INFO_UPDATER_FACTORY_H_
#define IOS_CHROME_BROWSER_SIGNIN_SIGNIN_BROWSER_STATE_INFO_UPDATER_FACTORY_H_
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
namespace ios {
class ChromeBrowserState;
}
class SigninBrowserStateInfoUpdater;
class SigninBrowserStateInfoUpdaterFactory
: public BrowserStateKeyedServiceFactory {
public:
// Returns nullptr if this browser state cannot have a
// SigninBrowserStateInfoUpdater (for example, if it is incognito).
static SigninBrowserStateInfoUpdater* GetForBrowserState(
ios::ChromeBrowserState* chrome_browser_state);
// Returns an instance of the factory singleton.
static SigninBrowserStateInfoUpdaterFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<
SigninBrowserStateInfoUpdaterFactory>;
SigninBrowserStateInfoUpdaterFactory();
~SigninBrowserStateInfoUpdaterFactory() override;
// BrowserStateKeyedServiceFactory:
std::unique_ptr<KeyedService> BuildServiceInstanceFor(
web::BrowserState* state) const override;
bool ServiceIsCreatedWithBrowserState() const override;
DISALLOW_COPY_AND_ASSIGN(SigninBrowserStateInfoUpdaterFactory);
};
#endif // IOS_CHROME_BROWSER_SIGNIN_SIGNIN_BROWSER_STATE_INFO_UPDATER_FACTORY_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/signin/signin_browser_state_info_updater_factory.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/signin/core/browser/signin_manager.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/signin/signin_browser_state_info_updater.h"
#include "ios/chrome/browser/signin/signin_error_controller_factory.h"
#include "ios/chrome/browser/signin/signin_manager_factory.h"
// static
SigninBrowserStateInfoUpdater*
SigninBrowserStateInfoUpdaterFactory::GetForBrowserState(
ios::ChromeBrowserState* chrome_browser_state) {
return static_cast<SigninBrowserStateInfoUpdater*>(
GetInstance()->GetServiceForBrowserState(chrome_browser_state, true));
}
// static
SigninBrowserStateInfoUpdaterFactory*
SigninBrowserStateInfoUpdaterFactory::GetInstance() {
return base::Singleton<SigninBrowserStateInfoUpdaterFactory>::get();
}
SigninBrowserStateInfoUpdaterFactory::SigninBrowserStateInfoUpdaterFactory()
: BrowserStateKeyedServiceFactory(
"SigninBrowserStateInfoUpdater",
BrowserStateDependencyManager::GetInstance()) {
DependsOn(ios::SigninErrorControllerFactory::GetInstance());
DependsOn(ios::SigninManagerFactory::GetInstance());
}
SigninBrowserStateInfoUpdaterFactory::~SigninBrowserStateInfoUpdaterFactory() {}
std::unique_ptr<KeyedService>
SigninBrowserStateInfoUpdaterFactory::BuildServiceInstanceFor(
web::BrowserState* state) const {
ios::ChromeBrowserState* chrome_browser_state =
ios::ChromeBrowserState::FromBrowserState(state);
return std::make_unique<SigninBrowserStateInfoUpdater>(
ios::SigninManagerFactory::GetForBrowserState(chrome_browser_state),
ios::SigninErrorControllerFactory::GetForBrowserState(
chrome_browser_state),
chrome_browser_state->GetStatePath());
}
bool SigninBrowserStateInfoUpdaterFactory::ServiceIsCreatedWithBrowserState()
const {
return true;
}
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "ios/chrome/browser/content_settings/cookie_settings_factory.h" #include "ios/chrome/browser/content_settings/cookie_settings_factory.h"
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h" #include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "ios/chrome/browser/signin/ios_chrome_signin_client.h" #include "ios/chrome/browser/signin/ios_chrome_signin_client.h"
#include "ios/chrome/browser/signin/signin_error_controller_factory.h"
// static // static
SigninClient* SigninClientFactory::GetForBrowserState( SigninClient* SigninClientFactory::GetForBrowserState(
...@@ -29,7 +28,6 @@ SigninClientFactory::SigninClientFactory() ...@@ -29,7 +28,6 @@ SigninClientFactory::SigninClientFactory()
: BrowserStateKeyedServiceFactory( : BrowserStateKeyedServiceFactory(
"SigninClient", "SigninClient",
BrowserStateDependencyManager::GetInstance()) { BrowserStateDependencyManager::GetInstance()) {
DependsOn(ios::SigninErrorControllerFactory::GetInstance());
DependsOn(ios::CookieSettingsFactory::GetInstance()); DependsOn(ios::CookieSettingsFactory::GetInstance());
DependsOn(ios::HostContentSettingsMapFactory::GetInstance()); DependsOn(ios::HostContentSettingsMapFactory::GetInstance());
} }
...@@ -42,8 +40,6 @@ std::unique_ptr<KeyedService> SigninClientFactory::BuildServiceInstanceFor( ...@@ -42,8 +40,6 @@ std::unique_ptr<KeyedService> SigninClientFactory::BuildServiceInstanceFor(
ios::ChromeBrowserState::FromBrowserState(context); ios::ChromeBrowserState::FromBrowserState(context);
return std::make_unique<IOSChromeSigninClient>( return std::make_unique<IOSChromeSigninClient>(
chrome_browser_state, chrome_browser_state,
ios::SigninErrorControllerFactory::GetForBrowserState(
chrome_browser_state),
ios::CookieSettingsFactory::GetForBrowserState(chrome_browser_state), ios::CookieSettingsFactory::GetForBrowserState(chrome_browser_state),
ios::HostContentSettingsMapFactory::GetForBrowserState( ios::HostContentSettingsMapFactory::GetForBrowserState(
chrome_browser_state)); chrome_browser_state));
......
...@@ -8,9 +8,6 @@ ...@@ -8,9 +8,6 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/browsing_data/core/browsing_data_utils.h" #include "components/browsing_data/core/browsing_data_utils.h"
#include "components/browsing_data/core/pref_names.h" #include "components/browsing_data/core/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/sync_preferences/pref_service_mock_factory.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/browsing_data/browsing_data_counter_wrapper.h" #include "ios/chrome/browser/browsing_data/browsing_data_counter_wrapper.h"
#include "ios/chrome/browser/browsing_data/cache_counter.h" #include "ios/chrome/browser/browsing_data/cache_counter.h"
...@@ -29,17 +26,8 @@ class ClearDataItemTest : public PlatformTest { ...@@ -29,17 +26,8 @@ class ClearDataItemTest : public PlatformTest {
void SetUp() override { void SetUp() override {
// Setup identity services. // Setup identity services.
TestChromeBrowserState::Builder builder; TestChromeBrowserState::Builder builder;
builder.SetPrefService(CreatePrefService());
browser_state_ = builder.Build(); browser_state_ = builder.Build();
} }
std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService() {
sync_preferences::PrefServiceMockFactory factory;
scoped_refptr<user_prefs::PrefRegistrySyncable> registry(
new user_prefs::PrefRegistrySyncable);
std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs =
factory.CreateSyncable(registry.get());
return prefs;
}
std::unique_ptr<TestChromeBrowserState> browser_state_; std::unique_ptr<TestChromeBrowserState> browser_state_;
web::TestWebThreadBundle thread_bundle_; web::TestWebThreadBundle thread_bundle_;
......
...@@ -54,7 +54,6 @@ class IOSWebViewSigninClient : public SigninClient { ...@@ -54,7 +54,6 @@ class IOSWebViewSigninClient : public SigninClient {
gaia::GaiaSource source, gaia::GaiaSource source,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
override; override;
void OnSignedOut() override;
// CWVSyncController setter/getter. // CWVSyncController setter/getter.
void SetSyncController(CWVSyncController* sync_controller); void SetSyncController(CWVSyncController* sync_controller);
......
...@@ -36,8 +36,6 @@ void IOSWebViewSigninClient::Shutdown() { ...@@ -36,8 +36,6 @@ void IOSWebViewSigninClient::Shutdown() {
network_callback_helper_.reset(); network_callback_helper_.reset();
} }
void IOSWebViewSigninClient::OnSignedOut() {}
std::string IOSWebViewSigninClient::GetProductVersion() { std::string IOSWebViewSigninClient::GetProductVersion() {
// TODO(crbug.com/768689): Implement this method with appropriate values. // TODO(crbug.com/768689): Implement this method with appropriate values.
return ""; return "";
......
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