Commit 3caf404d authored by rogerta@chromium.org's avatar rogerta@chromium.org

Replace PO2TS::GetPrimaryAccountId() with SMB::GetAuthenticatedAccountId.

The functionality is the same, just moving the code to a new place.

NOTRY=True
BUG=333995
R=bauerb@chromium.org, brettw@chromium.org, joaodasilva@chromium.org, nhiroki@chromium.org, noms@chromium.org, rlarocque@chromium.org

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=251221

Review URL: https://codereview.chromium.org/150003004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251339 0039d316-1c4b-4281-b951-d872f2087c98
parent 709deb25
...@@ -40,6 +40,8 @@ include_rules = [ ...@@ -40,6 +40,8 @@ include_rules = [
"!chrome/browser/signin/oauth2_token_service.h", "!chrome/browser/signin/oauth2_token_service.h",
"!chrome/browser/signin/profile_oauth2_token_service.h", "!chrome/browser/signin/profile_oauth2_token_service.h",
"!chrome/browser/signin/profile_oauth2_token_service_factory.h", "!chrome/browser/signin/profile_oauth2_token_service_factory.h",
"!chrome/browser/signin/signin_manager.h",
"!chrome/browser/signin/signin_manager_factory.h",
"!chrome/browser/signin/token_service_factory.h", "!chrome/browser/signin/token_service_factory.h",
"!chrome/browser/sync/profile_sync_service.h", "!chrome/browser/sync/profile_sync_service.h",
"!chrome/browser/sync/profile_sync_service_factory.h", "!chrome/browser/sync/profile_sync_service_factory.h",
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h" #include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_token_service.h" #include "google_apis/gaia/oauth2_token_service.h"
...@@ -82,8 +84,10 @@ class RequestImpl : public WebHistoryService::Request, ...@@ -82,8 +84,10 @@ class RequestImpl : public WebHistoryService::Request,
ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile_);
token_request_ = token_service->StartRequest( token_request_ = token_service->StartRequest(
token_service->GetPrimaryAccountId(), oauth_scopes, this); signin_manager->GetAuthenticatedAccountId(), oauth_scopes, this);
is_pending_ = true; is_pending_ = true;
} }
...@@ -103,9 +107,12 @@ class RequestImpl : public WebHistoryService::Request, ...@@ -103,9 +107,12 @@ class RequestImpl : public WebHistoryService::Request,
oauth_scopes.insert(kHistoryOAuthScope); oauth_scopes.insert(kHistoryOAuthScope);
ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
token_service->InvalidateToken(token_service->GetPrimaryAccountId(), SigninManagerBase* signin_manager =
oauth_scopes, SigninManagerFactory::GetForProfile(profile_);
access_token_); token_service->InvalidateToken(
signin_manager->GetAuthenticatedAccountId(),
oauth_scopes,
access_token_);
access_token_.clear(); access_token_.clear();
Start(); Start();
......
...@@ -179,7 +179,7 @@ void TiclInvalidationService::RequestAccessToken() { ...@@ -179,7 +179,7 @@ void TiclInvalidationService::RequestAccessToken() {
oauth2_scopes.insert(kOAuth2Scopes[i]); oauth2_scopes.insert(kOAuth2Scopes[i]);
// Invalidate previous token, otherwise token service will return the same // Invalidate previous token, otherwise token service will return the same
// token again. // token again.
const std::string& account_id = oauth2_token_service_->GetPrimaryAccountId(); const std::string& account_id = signin_manager_->GetAuthenticatedAccountId();
oauth2_token_service_->InvalidateToken(account_id, oauth2_token_service_->InvalidateToken(account_id,
oauth2_scopes, oauth2_scopes,
access_token_); access_token_);
...@@ -237,7 +237,7 @@ void TiclInvalidationService::OnGetTokenFailure( ...@@ -237,7 +237,7 @@ void TiclInvalidationService::OnGetTokenFailure(
void TiclInvalidationService::OnRefreshTokenAvailable( void TiclInvalidationService::OnRefreshTokenAvailable(
const std::string& account_id) { const std::string& account_id) {
if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { if (signin_manager_->GetAuthenticatedAccountId() == account_id) {
if (!IsStarted() && IsReadyToStart()) { if (!IsStarted() && IsReadyToStart()) {
StartInvalidator(PUSH_CLIENT_CHANNEL); StartInvalidator(PUSH_CLIENT_CHANNEL);
} }
...@@ -246,7 +246,7 @@ void TiclInvalidationService::OnRefreshTokenAvailable( ...@@ -246,7 +246,7 @@ void TiclInvalidationService::OnRefreshTokenAvailable(
void TiclInvalidationService::OnRefreshTokenRevoked( void TiclInvalidationService::OnRefreshTokenRevoked(
const std::string& account_id) { const std::string& account_id) {
if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { if (signin_manager_->GetAuthenticatedAccountId() == account_id) {
access_token_.clear(); access_token_.clear();
if (IsStarted()) { if (IsStarted()) {
UpdateInvalidatorCredentials(); UpdateInvalidatorCredentials();
...@@ -312,7 +312,7 @@ bool TiclInvalidationService::IsReadyToStart() { ...@@ -312,7 +312,7 @@ bool TiclInvalidationService::IsReadyToStart() {
} }
if (!oauth2_token_service_->RefreshTokenIsAvailable( if (!oauth2_token_service_->RefreshTokenIsAvailable(
oauth2_token_service_->GetPrimaryAccountId())) { signin_manager_->GetAuthenticatedAccountId())) {
DVLOG(2) DVLOG(2)
<< "Not starting TiclInvalidationServce: Waiting for refresh token."; << "Not starting TiclInvalidationServce: Waiting for refresh token.";
return false; return false;
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h" #include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/glue/device_info.h" #include "chrome/browser/sync/glue/device_info.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -141,10 +143,12 @@ ManagedUserRegistrationUtility::Create(Profile* profile) { ...@@ -141,10 +143,12 @@ ManagedUserRegistrationUtility::Create(Profile* profile) {
ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile); ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile);
scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher = scoped_ptr<ManagedUserRefreshTokenFetcher> token_fetcher =
ManagedUserRefreshTokenFetcher::Create( ManagedUserRefreshTokenFetcher::Create(
token_service, token_service,
token_service->GetPrimaryAccountId(), signin_manager->GetAuthenticatedAccountId(),
profile->GetRequestContext()); profile->GetRequestContext());
ManagedUserSyncService* managed_user_sync_service = ManagedUserSyncService* managed_user_sync_service =
ManagedUserSyncServiceFactory::GetForProfile(profile); ManagedUserSyncServiceFactory::GetForProfile(profile);
......
...@@ -43,7 +43,7 @@ UserPolicySigninService::UserPolicySigninService( ...@@ -43,7 +43,7 @@ UserPolicySigninService::UserPolicySigninService(
// happens in the background after PKS initialization - so this service // happens in the background after PKS initialization - so this service
// should always be created before the oauth token is available. // should always be created before the oauth token is available.
DCHECK(!oauth2_token_service_->RefreshTokenIsAvailable( DCHECK(!oauth2_token_service_->RefreshTokenIsAvailable(
oauth2_token_service_->GetPrimaryAccountId())); signin_manager->GetAuthenticatedAccountId()));
// Listen for an OAuth token to become available so we can register a client // Listen for an OAuth token to become available so we can register a client
// if for some reason the client is not already registered (for example, if // if for some reason the client is not already registered (for example, if
...@@ -116,7 +116,7 @@ void UserPolicySigninService::OnRefreshTokenAvailable( ...@@ -116,7 +116,7 @@ void UserPolicySigninService::OnRefreshTokenAvailable(
} }
// Ignore OAuth tokens for any account but the primary one. // Ignore OAuth tokens for any account but the primary one.
if (account_id != oauth2_token_service_->GetPrimaryAccountId()) if (account_id != signin_manager()->GetAuthenticatedAccountId())
return; return;
// ProfileOAuth2TokenService now has a refresh token so initialize the // ProfileOAuth2TokenService now has a refresh token so initialize the
...@@ -153,7 +153,7 @@ void UserPolicySigninService::OnInitializationCompleted( ...@@ -153,7 +153,7 @@ void UserPolicySigninService::OnInitializationCompleted(
<< "Client already registered - not fetching DMToken"; << "Client already registered - not fetching DMToken";
if (!manager->IsClientRegistered()) { if (!manager->IsClientRegistered()) {
if (!oauth2_token_service_->RefreshTokenIsAvailable( if (!oauth2_token_service_->RefreshTokenIsAvailable(
oauth2_token_service_->GetPrimaryAccountId())) { signin_manager()->GetAuthenticatedAccountId())) {
// No token yet - this class listens for OnRefreshTokenAvailable() // No token yet - this class listens for OnRefreshTokenAvailable()
// and will re-attempt registration once the token is available. // and will re-attempt registration once the token is available.
DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download"; DLOG(WARNING) << "No OAuth Refresh Token - delaying policy download";
...@@ -180,7 +180,7 @@ void UserPolicySigninService::RegisterCloudPolicyService() { ...@@ -180,7 +180,7 @@ void UserPolicySigninService::RegisterCloudPolicyService() {
enterprise_management::DeviceRegisterRequest::BROWSER)); enterprise_management::DeviceRegisterRequest::BROWSER));
registration_helper_->StartRegistration( registration_helper_->StartRegistration(
oauth2_token_service_, oauth2_token_service_,
oauth2_token_service_->GetPrimaryAccountId(), signin_manager()->GetAuthenticatedAccountId(),
base::Bind(&UserPolicySigninService::OnRegistrationComplete, base::Bind(&UserPolicySigninService::OnRegistrationComplete,
base::Unretained(this))); base::Unretained(this)));
} }
......
...@@ -12,9 +12,10 @@ ...@@ -12,9 +12,10 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/policy/cloud/user_policy_signin_service_base.h" #include "chrome/browser/policy/cloud/user_policy_signin_service_base.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h" #include "google_apis/gaia/oauth2_token_service.h"
class Profile; class Profile;
class ProfileOAuth2TokenService;
namespace net { namespace net {
class URLRequestContextGetter; class URLRequestContextGetter;
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h" #include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_constants.h" #include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/gaia_urls.h"
...@@ -233,8 +235,11 @@ void ProfileDownloader::StartForAccount(const std::string& account_id) { ...@@ -233,8 +235,11 @@ void ProfileDownloader::StartForAccount(const std::string& account_id) {
return; return;
} }
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(delegate_->GetBrowserProfile());
account_id_ = account_id_ =
account_id.empty() ? service->GetPrimaryAccountId() : account_id; account_id.empty() ?
signin_manager->GetAuthenticatedAccountId() : account_id;
if (service->RefreshTokenIsAvailable(account_id_)) { if (service->RefreshTokenIsAvailable(account_id_)) {
StartFetchingOAuth2AccessToken(); StartFetchingOAuth2AccessToken();
} else { } else {
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h" #include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h" #include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h"
#include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h" #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h"
#include "chrome/browser/sync_file_system/drive_backend/list_changes_task.h" #include "chrome/browser/sync_file_system/drive_backend/list_changes_task.h"
...@@ -65,9 +67,11 @@ scoped_ptr<SyncEngine> SyncEngine::CreateForBrowserContext( ...@@ -65,9 +67,11 @@ scoped_ptr<SyncEngine> SyncEngine::CreateForBrowserContext(
worker_pool->GetSequenceToken(), worker_pool->GetSequenceToken(),
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
Profile* profile = Profile::FromBrowserContext(context);
ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile( ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
Profile::FromBrowserContext(context)); SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile);
scoped_ptr<drive::DriveServiceInterface> drive_service( scoped_ptr<drive::DriveServiceInterface> drive_service(
new drive::DriveAPIService( new drive::DriveAPIService(
token_service, token_service,
...@@ -75,7 +79,7 @@ scoped_ptr<SyncEngine> SyncEngine::CreateForBrowserContext( ...@@ -75,7 +79,7 @@ scoped_ptr<SyncEngine> SyncEngine::CreateForBrowserContext(
drive_task_runner.get(), drive_task_runner.get(),
base_drive_url, base_download_url, wapi_base_url, base_drive_url, base_download_url, wapi_base_url,
std::string() /* custom_user_agent */)); std::string() /* custom_user_agent */));
drive_service->Initialize(token_service->GetPrimaryAccountId()); drive_service->Initialize(signin_manager->GetAuthenticatedAccountId());
scoped_ptr<drive::DriveUploaderInterface> drive_uploader( scoped_ptr<drive::DriveUploaderInterface> drive_uploader(
new drive::DriveUploader(drive_service.get(), drive_task_runner.get())); new drive::DriveUploader(drive_service.get(), drive_task_runner.get()));
...@@ -351,7 +355,9 @@ void SyncEngine::OnReadyToSendRequests() { ...@@ -351,7 +355,9 @@ void SyncEngine::OnReadyToSendRequests() {
UpdateServiceState(REMOTE_SERVICE_OK, "Authenticated"); UpdateServiceState(REMOTE_SERVICE_OK, "Authenticated");
if (!metadata_database_ && auth_token_service_) { if (!metadata_database_ && auth_token_service_) {
drive_service_->Initialize(auth_token_service_->GetPrimaryAccountId()); SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(auth_token_service_->profile());
drive_service_->Initialize(signin_manager->GetAuthenticatedAccountId());
PostInitializeTask(); PostInitializeTask();
return; return;
} }
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h" #include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h" #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h"
#include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.h" #include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_util.h"
#include "chrome/browser/sync_file_system/logger.h" #include "chrome/browser/sync_file_system/logger.h"
...@@ -157,6 +159,7 @@ bool CreateTemporaryFile(const base::FilePath& dir_path, ...@@ -157,6 +159,7 @@ bool CreateTemporaryFile(const base::FilePath& dir_path,
APIUtil::APIUtil(Profile* profile, APIUtil::APIUtil(Profile* profile,
const base::FilePath& temp_dir_path) const base::FilePath& temp_dir_path)
: oauth_service_(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)), : oauth_service_(ProfileOAuth2TokenServiceFactory::GetForProfile(profile)),
signin_manager_(SigninManagerFactory::GetForProfile(profile)),
upload_next_key_(0), upload_next_key_(0),
temp_dir_path_(temp_dir_path), temp_dir_path_(temp_dir_path),
has_initialized_token_(false) { has_initialized_token_(false) {
...@@ -183,7 +186,7 @@ APIUtil::APIUtil(Profile* profile, ...@@ -183,7 +186,7 @@ APIUtil::APIUtil(Profile* profile,
std::string() /* custom_user_agent */)); std::string() /* custom_user_agent */));
} }
drive_service_->Initialize(oauth_service_->GetPrimaryAccountId()); drive_service_->Initialize(signin_manager_->GetAuthenticatedAccountId());
drive_service_->AddObserver(this); drive_service_->AddObserver(this);
has_initialized_token_ = drive_service_->HasRefreshToken(); has_initialized_token_ = drive_service_->HasRefreshToken();
...@@ -663,7 +666,7 @@ GURL APIUtil::DirectoryTitleToOrigin(const std::string& title) { ...@@ -663,7 +666,7 @@ GURL APIUtil::DirectoryTitleToOrigin(const std::string& title) {
void APIUtil::OnReadyToSendRequests() { void APIUtil::OnReadyToSendRequests() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (!has_initialized_token_) { if (!has_initialized_token_) {
drive_service_->Initialize(oauth_service_->GetPrimaryAccountId()); drive_service_->Initialize(signin_manager_->GetAuthenticatedAccountId());
has_initialized_token_ = true; has_initialized_token_ = true;
} }
FOR_EACH_OBSERVER(APIUtilObserver, observers_, OnAuthenticated()); FOR_EACH_OBSERVER(APIUtilObserver, observers_, OnAuthenticated());
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
class GURL; class GURL;
class Profile; class Profile;
class ProfileOAuth2TokenService; class ProfileOAuth2TokenService;
class SigninManagerBase;
namespace drive { class DriveUploaderInterface; } namespace drive { class DriveUploaderInterface; }
...@@ -242,6 +243,7 @@ class APIUtil : public APIUtilInterface, ...@@ -242,6 +243,7 @@ class APIUtil : public APIUtilInterface,
scoped_ptr<drive::DriveUploaderInterface> drive_uploader_; scoped_ptr<drive::DriveUploaderInterface> drive_uploader_;
ProfileOAuth2TokenService* oauth_service_; ProfileOAuth2TokenService* oauth_service_;
SigninManagerBase* signin_manager_;
UploadCallbackMap upload_callback_map_; UploadCallbackMap upload_callback_map_;
UploadKey upload_next_key_; UploadKey upload_next_key_;
......
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