Commit 4e30d19a authored by rogerta@chromium.org's avatar rogerta@chromium.org

User cloud policy token forwarder: Replace PO2TS::GetPrimaryAccountId() with...

User cloud policy token forwarder: Replace PO2TS::GetPrimaryAccountId() with SMB::GetAuthenticatedAccountId.

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

BUG=333995,107160

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255298 0039d316-1c4b-4281-b951-d872f2087c98
parent 3f34fba9
......@@ -59,6 +59,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/rlz/rlz.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/app_list/start_page_service.h"
......@@ -458,10 +460,9 @@ void LoginUtilsImpl::InitProfilePreferences(Profile* user_profile,
// Make sure that the google service username is properly set (we do this
// on every sign in, not just the first login, to deal with existing
// profiles that might not have it set yet).
StringPrefMember google_services_username;
google_services_username.Init(prefs::kGoogleServicesUsername,
user_profile->GetPrefs());
google_services_username.SetValue(user_id);
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(user_profile);
signin_manager->SetAuthenticatedUsername(user_id);
}
}
......
......@@ -23,6 +23,8 @@
#include "chrome/browser/signin/fake_profile_oauth2_token_service_wrapper.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/common/chrome_constants.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
......@@ -180,8 +182,12 @@ class UserCloudPolicyManagerChromeOSTest : public testing::Test {
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
ASSERT_TRUE(token_service);
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile_);
ASSERT_TRUE(signin_manager);
token_forwarder_.reset(
new UserCloudPolicyTokenForwarder(manager_.get(), token_service));
new UserCloudPolicyTokenForwarder(manager_.get(), token_service,
signin_manager));
}
}
......@@ -535,7 +541,10 @@ TEST_F(UserCloudPolicyManagerChromeOSTest, NonBlockingFirstFetch) {
static_cast<FakeProfileOAuth2TokenService*>(
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_));
ASSERT_TRUE(token_service);
const std::string account_id = token_service->GetPrimaryAccountId();
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile_);
ASSERT_TRUE(signin_manager);
const std::string& account_id = signin_manager->GetAuthenticatedAccountId();
EXPECT_FALSE(token_service->RefreshTokenIsAvailable(account_id));
token_service->UpdateCredentials(account_id, "refresh_token");
EXPECT_TRUE(token_service->RefreshTokenIsAvailable(account_id));
......
......@@ -7,6 +7,7 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/signin_manager.h"
#include "components/policy/core/common/cloud/cloud_policy_core.h"
#include "content/public/browser/notification_source.h"
#include "google_apis/gaia/gaia_constants.h"
......@@ -16,10 +17,12 @@ namespace policy {
UserCloudPolicyTokenForwarder::UserCloudPolicyTokenForwarder(
UserCloudPolicyManagerChromeOS* manager,
ProfileOAuth2TokenService* token_service)
ProfileOAuth2TokenService* token_service,
SigninManagerBase* signin_manager)
: OAuth2TokenService::Consumer("policy_token_forwarder"),
manager_(manager),
token_service_(token_service) {
token_service_(token_service),
signin_manager_(signin_manager) {
// Start by waiting for the CloudPolicyService to be initialized, so that
// we can check if it already has a DMToken or not.
if (manager_->core()->service()->IsInitializationComplete()) {
......@@ -79,7 +82,7 @@ void UserCloudPolicyTokenForwarder::Initialize() {
// here if the client is already registered, so check and bail out here.
if (token_service_->RefreshTokenIsAvailable(
token_service_->GetPrimaryAccountId()))
signin_manager_->GetAuthenticatedAccountId()))
RequestAccessToken();
else
token_service_->AddObserver(this);
......@@ -90,7 +93,7 @@ void UserCloudPolicyTokenForwarder::RequestAccessToken() {
scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth);
scopes.insert(GaiaUrls::GetInstance()->oauth_wrap_bridge_user_info_scope());
request_ = token_service_->StartRequest(
token_service_->GetPrimaryAccountId(), scopes, this);
signin_manager_->GetAuthenticatedAccountId(), scopes, this);
}
} // namespace policy
......@@ -11,6 +11,7 @@
#include "google_apis/gaia/oauth2_token_service.h"
class ProfileOAuth2TokenService;
class SigninManagerBase;
namespace policy {
......@@ -30,7 +31,8 @@ class UserCloudPolicyTokenForwarder : public BrowserContextKeyedService,
// so this object will be Shutdown() first and these pointers can be used
// until that point.
UserCloudPolicyTokenForwarder(UserCloudPolicyManagerChromeOS* manager,
ProfileOAuth2TokenService* token_service);
ProfileOAuth2TokenService* token_service,
SigninManagerBase* signin_manager);
virtual ~UserCloudPolicyTokenForwarder();
// BrowserContextKeyedService:
......@@ -56,6 +58,7 @@ class UserCloudPolicyTokenForwarder : public BrowserContextKeyedService,
UserCloudPolicyManagerChromeOS* manager_;
ProfileOAuth2TokenService* token_service_;
SigninManagerBase* signin_manager_;
scoped_ptr<OAuth2TokenService::Request> request_;
DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyTokenForwarder);
......
......@@ -10,6 +10,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 "components/browser_context_keyed_service/browser_context_dependency_manager.h"
namespace policy {
......@@ -24,6 +26,7 @@ UserCloudPolicyTokenForwarderFactory::UserCloudPolicyTokenForwarderFactory()
: BrowserContextKeyedServiceFactory(
"UserCloudPolicyTokenForwarder",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(SigninManagerFactory::GetInstance());
DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
DependsOn(UserCloudPolicyManagerFactoryChromeOS::GetInstance());
}
......@@ -38,9 +41,12 @@ BrowserContextKeyedService*
UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
if (!token_service || !manager)
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile);
if (!signin_manager || !token_service || !manager)
return NULL;
return new UserCloudPolicyTokenForwarder(manager, token_service);
return new UserCloudPolicyTokenForwarder(manager, token_service,
signin_manager);
}
bool UserCloudPolicyTokenForwarderFactory::
......
......@@ -137,9 +137,11 @@ class FakeSigninManager : public SigninManagerBase {
}
void SignOut() {
std::string username = GetAuthenticatedUsername();
clear_authenticated_username();
profile()->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername);
GoogleServiceSignoutDetails details(GetAuthenticatedUsername());
GoogleServiceSignoutDetails details(username);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
content::Source<Profile>(profile_),
......
......@@ -623,8 +623,6 @@ void SigninManager::OnExternalSigninCompleted(const std::string& username) {
void SigninManager::OnSignedIn(const std::string& username) {
SetAuthenticatedUsername(username);
possibly_invalid_username_.clear();
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
GetAuthenticatedUsername());
// TODO(blundell): Eliminate this notification send once crbug.com/333997 is
// fixed.
......
......@@ -89,11 +89,12 @@ void SigninManagerBase::SetAuthenticatedUsername(const std::string& username) {
return;
#endif
}
std::string pref_username = profile_->GetPrefs()->GetString(
prefs::kGoogleServicesUsername);
DCHECK(pref_username.empty() ||
gaia::AreEmailsSame(username, pref_username));
authenticated_username_ = username;
// TODO(tim): We could go further in ensuring kGoogleServicesUsername and
// authenticated_username_ are consistent once established (e.g. remove
// authenticated_username_ altogether). Bug 107160.
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username);
NotifyDiagnosticsObservers(USERNAME, username);
// Go ahead and update the last signed in username here as well. Once a
......
......@@ -217,8 +217,6 @@ bool ProfileSyncServiceHarness::SetupSync(
// Authenticate sync client using GAIA credentials.
service()->signin()->SetAuthenticatedUsername(username_);
profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
username_);
GoogleServiceSigninSuccessDetails details(username_, password_);
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
......
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