Commit dee2d72a authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[GCM] Use SigninManager in GCMProfileService::IdentityObserver

As a first step toward completely eliminating the usage of
ProfileIdentityProvider in //components/gcm_driver, this CL threads in
SigninManager and replaces direct usage of ProfileIdentityProvider in
GCMProfileService::IdentityObserver with equivalent usage of
SigninManager.

Note that it is easy to verify that the usage is equivalent:
The ProfileIdentityProvider method calls are replaced with their
implementations in profile_identity_provider.cc.

Full design doc here:
https://docs.google.com/document/d/1OmNrIiMDkF7eOYVB4RIiDvY7pQz3zUrOf-D4TVwdRQA/edit?ts=5aa6b936#

TBR=zea@chromium.org, rockot@chromium.org

Bug: 809923
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I20515d7431f0e8f5370a47cd04c8b21eb0874d6f
Reviewed-on: https://chromium-review.googlesource.com/1004999
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556408}
parent 7ebede76
......@@ -212,6 +212,7 @@ class ExtensionGCMAppHandlerTest : public testing::Test {
profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(),
chrome::GetChannel(),
gcm::GetProductCategoryForSubtypes(profile->GetPrefs()),
SigninManagerFactory::GetForProfile(profile),
std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider(
SigninManagerFactory::GetForProfile(profile),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
......
......@@ -87,6 +87,7 @@ KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor(
profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(),
chrome::GetChannel(),
gcm::GetProductCategoryForSubtypes(profile->GetPrefs()),
SigninManagerFactory::GetForProfile(profile),
std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider(
SigninManagerFactory::GetForProfile(profile),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
......
......@@ -54,6 +54,7 @@ std::unique_ptr<KeyedService> BuildGCMProfileService(
profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(),
chrome::GetChannel(),
gcm::GetProductCategoryForSubtypes(profile->GetPrefs()),
SigninManagerFactory::GetForProfile(profile),
std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider(
SigninManagerFactory::GetForProfile(profile),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
......
......@@ -28,7 +28,6 @@
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/gcm_desktop_utils.h"
#include "components/gcm_driver/gcm_driver_desktop.h"
#include "components/signin/core/browser/signin_manager.h"
#include "google_apis/gaia/identity_provider.h"
#include "net/url_request/url_request_context_getter.h"
#endif
......@@ -38,21 +37,25 @@ namespace gcm {
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
// Identity observer only has actual work to do when the user is actually signed
// in. It ensures that account tracker is taking
class GCMProfileService::IdentityObserver : public IdentityProvider::Observer {
class GCMProfileService::IdentityObserver : public SigninManagerBase::Observer {
public:
IdentityObserver(ProfileIdentityProvider* identity_provider,
IdentityObserver(SigninManagerBase* signin_manager,
ProfileIdentityProvider* identity_provider,
net::URLRequestContextGetter* request_context,
GCMDriver* driver);
~IdentityObserver() override;
// IdentityProvider::Observer:
void OnActiveAccountLogin() override;
void OnActiveAccountLogout() override;
// SigninManagerBase::Observer:
void GoogleSigninSucceeded(const std::string& account_id,
const std::string& username) override;
void GoogleSignedOut(const std::string& account_id,
const std::string& username) override;
private:
void StartAccountTracker(net::URLRequestContextGetter* request_context);
GCMDriver* driver_;
SigninManagerBase* signin_manager_;
IdentityProvider* identity_provider_;
std::unique_ptr<GCMAccountTracker> gcm_account_tracker_;
......@@ -66,27 +69,31 @@ class GCMProfileService::IdentityObserver : public IdentityProvider::Observer {
};
GCMProfileService::IdentityObserver::IdentityObserver(
SigninManagerBase* signin_manager,
ProfileIdentityProvider* identity_provider,
net::URLRequestContextGetter* request_context,
GCMDriver* driver)
: driver_(driver),
signin_manager_(signin_manager),
identity_provider_(identity_provider),
weak_ptr_factory_(this) {
identity_provider_->AddObserver(this);
signin_manager_->AddObserver(this);
OnActiveAccountLogin();
GoogleSigninSucceeded(signin_manager_->GetAuthenticatedAccountId(),
signin_manager_->GetAuthenticatedAccountInfo().email);
StartAccountTracker(request_context);
}
GCMProfileService::IdentityObserver::~IdentityObserver() {
if (gcm_account_tracker_)
gcm_account_tracker_->Shutdown();
identity_provider_->RemoveObserver(this);
signin_manager_->RemoveObserver(this);
}
void GCMProfileService::IdentityObserver::OnActiveAccountLogin() {
void GCMProfileService::IdentityObserver::GoogleSigninSucceeded(
const std::string& account_id,
const std::string& username) {
// This might be called multiple times when the password changes.
const std::string account_id = identity_provider_->GetActiveAccountId();
if (account_id == account_id_)
return;
account_id_ = account_id;
......@@ -95,7 +102,9 @@ void GCMProfileService::IdentityObserver::OnActiveAccountLogin() {
driver_->OnSignedIn();
}
void GCMProfileService::IdentityObserver::OnActiveAccountLogout() {
void GCMProfileService::IdentityObserver::GoogleSignedOut(
const std::string& account_id,
const std::string& username) {
account_id_.clear();
// Still need to notify GCMDriver for UMA purpose.
......@@ -141,12 +150,14 @@ GCMProfileService::GCMProfileService(
net::URLRequestContextGetter* request_context,
version_info::Channel channel,
const std::string& product_category_for_subtypes,
SigninManagerBase* signin_manager,
std::unique_ptr<ProfileIdentityProvider> identity_provider,
std::unique_ptr<GCMClientFactory> gcm_client_factory,
const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner)
: profile_identity_provider_(std::move(identity_provider)),
signin_manager_(signin_manager),
request_context_(request_context) {
driver_ = CreateGCMDriverDesktop(
std::move(gcm_client_factory), prefs,
......@@ -154,8 +165,9 @@ GCMProfileService::GCMProfileService(
product_category_for_subtypes, ui_task_runner, io_task_runner,
blocking_task_runner);
identity_observer_.reset(new IdentityObserver(
profile_identity_provider_.get(), request_context_, driver_.get()));
identity_observer_.reset(
new IdentityObserver(signin_manager_, profile_identity_provider_.get(),
request_context_, driver_.get()));
}
#endif // BUILDFLAG(USE_GCM_FROM_PLATFORM)
......@@ -179,7 +191,8 @@ void GCMProfileService::SetDriverForTesting(std::unique_ptr<GCMDriver> driver) {
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
if (identity_observer_) {
identity_observer_ = std::make_unique<IdentityObserver>(
profile_identity_provider_.get(), request_context_, driver_.get());
signin_manager_, profile_identity_provider_.get(), request_context_,
driver.get());
}
#endif // !BUILDFLAG(USE_GCM_FROM_PLATFORM)
}
......
......@@ -17,6 +17,7 @@
#include "components/gcm_driver/gcm_buildflags.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/core/browser/profile_identity_provider.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/version_info/version_info.h"
class PrefService;
......@@ -48,6 +49,7 @@ class GCMProfileService : public KeyedService {
net::URLRequestContextGetter* request_context,
version_info::Channel channel,
const std::string& product_category_for_subtypes,
SigninManagerBase* signin_manager,
std::unique_ptr<ProfileIdentityProvider> identity_provider,
std::unique_ptr<GCMClientFactory> gcm_client_factory,
const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
......@@ -76,6 +78,7 @@ class GCMProfileService : public KeyedService {
std::unique_ptr<GCMDriver> driver_;
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
SigninManagerBase* signin_manager_;
net::URLRequestContextGetter* request_context_ = nullptr;
// Used for both account tracker and GCM.UserSignedIn UMA.
......
......@@ -67,6 +67,7 @@ IOSChromeGCMProfileServiceFactory::BuildServiceInstanceFor(
browser_state->GetPrefs(), browser_state->GetStatePath(),
browser_state->GetRequestContext(), ::GetChannel(),
GetProductCategoryForSubtypes(),
ios::SigninManagerFactory::GetForBrowserState(browser_state),
base::WrapUnique(new ProfileIdentityProvider(
ios::SigninManagerFactory::GetForBrowserState(browser_state),
OAuth2TokenServiceFactory::GetForBrowserState(browser_state),
......
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