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