Commit e3eac422 authored by tim@chromium.org's avatar tim@chromium.org

Revert 250967 "Revert of [sync]: add ManagedUserSigninManagerWra..."

> Revert of [sync]: add ManagedUserSigninManagerWrapper and pass to ProfileSyncService (https://codereview.chromium.org/137753012/)
> 
> Reason for revert:
> Possible build bustage on Win64.
> 
> Original issue's description:
> > [sync]: add ManagedUserSigninManagerWrapper and pass to ProfileSyncService
> > 
> > BUG=80194
> > 
> > Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=250814
> 
> TBR=bauerb@chromium.org,rogerta@chromium.org,pavely@chromium.org
> NOTREECHECKS=true
> NOTRY=true
> BUG=80194
> 
> Review URL: https://codereview.chromium.org/162943002

TBR=tim@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251114 0039d316-1c4b-4281-b951-d872f2087c98
parent a5fc73ee
// Copyright 2014 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/managed_mode/managed_user_signin_manager_wrapper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager_base.h"
#if defined(ENABLE_MANAGED_USERS)
#include "chrome/browser/managed_mode/managed_user_constants.h"
#endif
ManagedUserSigninManagerWrapper::ManagedUserSigninManagerWrapper(
SigninManagerBase* original) : original_(original) {
}
ManagedUserSigninManagerWrapper::~ManagedUserSigninManagerWrapper() {
}
SigninManagerBase* ManagedUserSigninManagerWrapper::GetOriginal() {
return original_;
}
std::string ManagedUserSigninManagerWrapper::GetEffectiveUsername() const {
if (original_->profile()->IsManaged()) {
#if defined(ENABLE_MANAGED_USERS)
DCHECK_EQ(std::string(), original_->GetAuthenticatedUsername());
return managed_users::kManagedUserPseudoEmail;
#else
NOTREACHED();
#endif
}
return original_->GetAuthenticatedUsername();
}
std::string ManagedUserSigninManagerWrapper::GetAccountIdToUse() const {
if (original_->profile()->IsManaged()) {
#if defined(ENABLE_MANAGED_USERS)
return managed_users::kManagedUserPseudoEmail;
#else
NOTREACHED();
#endif
}
return original_->GetAuthenticatedAccountId();
}
// Copyright 2014 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_MANAGED_MODE_MANAGED_USER_SIGNIN_MANAGER_WRAPPER_H_
#define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SIGNIN_MANAGER_WRAPPER_H_
#include <string>
#include "base/basictypes.h"
class SigninManagerBase;
// Some chrome cloud services support managed users as well as normally
// authenticated users that sign in through SigninManager. To facilitate
// getting the "effective" username and account identifiers, services can
// use this class to wrap the SigninManager and return managed user account
// information when appropriate.
class ManagedUserSigninManagerWrapper {
public:
explicit ManagedUserSigninManagerWrapper(SigninManagerBase* original);
~ManagedUserSigninManagerWrapper();
std::string GetEffectiveUsername() const;
std::string GetAccountIdToUse() const;
SigninManagerBase* GetOriginal();
private:
SigninManagerBase* original_;
DISALLOW_COPY_AND_ASSIGN(ManagedUserSigninManagerWrapper);
};
#endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SIGNIN_MANAGER_WRAPPER_H_
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/defaults.h" #include "chrome/browser/defaults.h"
#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
#include "chrome/browser/net/chrome_cookie_notification_details.h" #include "chrome/browser/net/chrome_cookie_notification_details.h"
#include "chrome/browser/prefs/pref_service_syncable.h" #include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -158,7 +159,7 @@ bool ShouldShowActionOnUI( ...@@ -158,7 +159,7 @@ bool ShouldShowActionOnUI(
ProfileSyncService::ProfileSyncService( ProfileSyncService::ProfileSyncService(
ProfileSyncComponentsFactory* factory, ProfileSyncComponentsFactory* factory,
Profile* profile, Profile* profile,
SigninManagerBase* signin_manager, ManagedUserSigninManagerWrapper* signin_wrapper,
ProfileOAuth2TokenService* oauth2_token_service, ProfileOAuth2TokenService* oauth2_token_service,
StartBehavior start_behavior) StartBehavior start_behavior)
: OAuth2TokenService::Consumer("sync"), : OAuth2TokenService::Consumer("sync"),
...@@ -173,7 +174,7 @@ ProfileSyncService::ProfileSyncService( ...@@ -173,7 +174,7 @@ ProfileSyncService::ProfileSyncService(
backend_initialized_(false), backend_initialized_(false),
sync_disabled_by_admin_(false), sync_disabled_by_admin_(false),
is_auth_in_progress_(false), is_auth_in_progress_(false),
signin_(signin_manager), signin_(signin_wrapper),
unrecoverable_error_reason_(ERROR_REASON_UNSET), unrecoverable_error_reason_(ERROR_REASON_UNSET),
expect_sync_configuration_aborted_(false), expect_sync_configuration_aborted_(false),
encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
...@@ -225,14 +226,15 @@ bool ProfileSyncService::IsSyncEnabledAndLoggedIn() { ...@@ -225,14 +226,15 @@ bool ProfileSyncService::IsSyncEnabledAndLoggedIn() {
return false; return false;
// Sync is logged in if there is a non-empty effective username. // Sync is logged in if there is a non-empty effective username.
return !GetEffectiveUsername().empty(); return !signin_->GetEffectiveUsername().empty();
} }
bool ProfileSyncService::IsOAuthRefreshTokenAvailable() { bool ProfileSyncService::IsOAuthRefreshTokenAvailable() {
if (!oauth2_token_service_) if (!oauth2_token_service_)
return false; return false;
return oauth2_token_service_->RefreshTokenIsAvailable(GetAccountIdToUse()); return oauth2_token_service_->RefreshTokenIsAvailable(
signin_->GetAccountIdToUse());
} }
void ProfileSyncService::Initialize() { void ProfileSyncService::Initialize() {
...@@ -253,7 +255,7 @@ void ProfileSyncService::Initialize() { ...@@ -253,7 +255,7 @@ void ProfileSyncService::Initialize() {
RegisterAuthNotifications(); RegisterAuthNotifications();
if (!HasSyncSetupCompleted() || GetEffectiveUsername().empty()) { if (!HasSyncSetupCompleted() || signin_->GetEffectiveUsername().empty()) {
// Clean up in case of previous crash / setup abort / signout. // Clean up in case of previous crash / setup abort / signout.
DisableForUser(); DisableForUser();
} }
...@@ -534,7 +536,7 @@ void ProfileSyncService::InitSettings() { ...@@ -534,7 +536,7 @@ void ProfileSyncService::InitSettings() {
SyncCredentials ProfileSyncService::GetCredentials() { SyncCredentials ProfileSyncService::GetCredentials() {
SyncCredentials credentials; SyncCredentials credentials;
credentials.email = GetEffectiveUsername(); credentials.email = signin_->GetEffectiveUsername();
DCHECK(!credentials.email.empty()); DCHECK(!credentials.email.empty());
credentials.sync_token = access_token_; credentials.sync_token = access_token_;
...@@ -746,7 +748,7 @@ void ProfileSyncService::OnGetTokenFailure( ...@@ -746,7 +748,7 @@ void ProfileSyncService::OnGetTokenFailure(
void ProfileSyncService::OnRefreshTokenAvailable( void ProfileSyncService::OnRefreshTokenAvailable(
const std::string& account_id) { const std::string& account_id) {
if (account_id == GetAccountIdToUse()) if (account_id == signin_->GetAccountIdToUse())
OnRefreshTokensLoaded(); OnRefreshTokensLoaded();
} }
...@@ -1973,7 +1975,7 @@ void ProfileSyncService::RequestAccessToken() { ...@@ -1973,7 +1975,7 @@ void ProfileSyncService::RequestAccessToken() {
// 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 = GetAccountIdToUse(); const std::string& account_id = signin_->GetAccountIdToUse();
if (!access_token_.empty()) { if (!access_token_.empty()) {
oauth2_token_service_->InvalidateToken( oauth2_token_service_->InvalidateToken(
account_id, oauth2_scopes, access_token_); account_id, oauth2_scopes, access_token_);
...@@ -2159,13 +2161,19 @@ bool ProfileSyncService::IsStartSuppressed() const { ...@@ -2159,13 +2161,19 @@ bool ProfileSyncService::IsStartSuppressed() const {
return sync_prefs_.IsStartSuppressed(); return sync_prefs_.IsStartSuppressed();
} }
SigninManagerBase* ProfileSyncService::signin() const {
return signin_->GetOriginal();
}
void ProfileSyncService::UnsuppressAndStart() { void ProfileSyncService::UnsuppressAndStart() {
DCHECK(profile_); DCHECK(profile_);
sync_prefs_.SetStartSuppressed(false); sync_prefs_.SetStartSuppressed(false);
// Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess // Set username in SigninManager, as SigninManager::OnGetUserInfoSuccess
// is never called for some clients. // is never called for some clients.
if (signin_ && signin_->GetAuthenticatedUsername().empty()) { if (signin_.get() &&
signin_->SetAuthenticatedUsername(sync_prefs_.GetGoogleServicesUsername()); signin_->GetOriginal()->GetAuthenticatedUsername().empty()) {
signin_->GetOriginal()->SetAuthenticatedUsername(
sync_prefs_.GetGoogleServicesUsername());
} }
TryStart(); TryStart();
} }
...@@ -2215,32 +2223,6 @@ std::string ProfileSyncService::GetAccessTokenForTest() const { ...@@ -2215,32 +2223,6 @@ std::string ProfileSyncService::GetAccessTokenForTest() const {
return access_token_; return access_token_;
} }
std::string ProfileSyncService::GetEffectiveUsername() {
if (profile_->IsManaged()) {
#if defined(ENABLE_MANAGED_USERS)
DCHECK_EQ(std::string(), signin_->GetAuthenticatedUsername());
return managed_users::kManagedUserPseudoEmail;
#else
NOTREACHED();
#endif
}
return signin_->GetAuthenticatedUsername();
}
std::string ProfileSyncService::GetAccountIdToUse() {
if (profile_->IsManaged()) {
#if defined(ENABLE_MANAGED_USERS)
return managed_users::kManagedUserPseudoEmail;
#else
NOTREACHED();
#endif
}
// TODO(fgorski): Use GetPrimaryAccountId() when it's available.
return signin_->GetAuthenticatedUsername();
}
WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() {
return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); return MakeWeakHandle(sync_js_controller_.AsWeakPtr());
} }
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "sync/js/sync_js_controller.h" #include "sync/js/sync_js_controller.h"
#include "url/gurl.h" #include "url/gurl.h"
class ManagedUserSigninManagerWrapper;
class Profile; class Profile;
class ProfileOAuth2TokenService; class ProfileOAuth2TokenService;
class ProfileSyncComponentsFactory; class ProfileSyncComponentsFactory;
...@@ -259,10 +260,10 @@ class ProfileSyncService ...@@ -259,10 +260,10 @@ class ProfileSyncService
// Sync server URL for dev channel users // Sync server URL for dev channel users
static const char* kDevServerUrl; static const char* kDevServerUrl;
// Takes ownership of |factory|. // Takes ownership of |factory| and |signin_wrapper|.
ProfileSyncService(ProfileSyncComponentsFactory* factory, ProfileSyncService(ProfileSyncComponentsFactory* factory,
Profile* profile, Profile* profile,
SigninManagerBase* signin, ManagedUserSigninManagerWrapper* signin_wrapper,
ProfileOAuth2TokenService* oauth2_token_service, ProfileOAuth2TokenService* oauth2_token_service,
StartBehavior start_behavior); StartBehavior start_behavior);
virtual ~ProfileSyncService(); virtual ~ProfileSyncService();
...@@ -641,7 +642,7 @@ class ProfileSyncService ...@@ -641,7 +642,7 @@ class ProfileSyncService
const GURL& sync_service_url() const { return sync_service_url_; } const GURL& sync_service_url() const { return sync_service_url_; }
bool auto_start_enabled() const { return auto_start_enabled_; } bool auto_start_enabled() const { return auto_start_enabled_; }
SigninManagerBase* signin() const { return signin_; } SigninManagerBase* signin() const;
bool setup_in_progress() const { return setup_in_progress_; } bool setup_in_progress() const { return setup_in_progress_; }
// Stops the sync backend and sets the flag for suppressing sync startup. // Stops the sync backend and sets the flag for suppressing sync startup.
...@@ -933,7 +934,7 @@ class ProfileSyncService ...@@ -933,7 +934,7 @@ class ProfileSyncService
// Encapsulates user signin - used to set/get the user's authenticated // Encapsulates user signin - used to set/get the user's authenticated
// email address. // email address.
SigninManagerBase* signin_; scoped_ptr<ManagedUserSigninManagerWrapper> signin_;
// Information describing an unrecoverable error. // Information describing an unrecoverable error.
UnrecoverableErrorReason unrecoverable_error_reason_; UnrecoverableErrorReason unrecoverable_error_reason_;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chrome/browser/extensions/extension_system_factory.h" #include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/invalidation/invalidation_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
#include "chrome/browser/password_manager/password_store_factory.h" #include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
...@@ -117,7 +118,7 @@ BrowserContextKeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( ...@@ -117,7 +118,7 @@ BrowserContextKeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor(
new ProfileSyncComponentsFactoryImpl(profile, new ProfileSyncComponentsFactoryImpl(profile,
CommandLine::ForCurrentProcess()), CommandLine::ForCurrentProcess()),
profile, profile,
signin, new ManagedUserSigninManagerWrapper(signin),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile), ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
behavior); behavior);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/prefs/testing_pref_store.h" #include "base/prefs/testing_pref_store.h"
#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.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.h"
...@@ -17,7 +18,8 @@ ProfileSyncServiceMock::ProfileSyncServiceMock(Profile* profile) ...@@ -17,7 +18,8 @@ ProfileSyncServiceMock::ProfileSyncServiceMock(Profile* profile)
: ProfileSyncService( : ProfileSyncService(
NULL, NULL,
profile, profile,
SigninManagerFactory::GetForProfile(profile), new ManagedUserSigninManagerWrapper(
SigninManagerFactory::GetForProfile(profile)),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile), ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
ProfileSyncService::MANUAL_START) {} ProfileSyncService::MANUAL_START) {}
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
#include "chrome/browser/signin/fake_signin_manager.h" #include "chrome/browser/signin/fake_signin_manager.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h" #include "chrome/browser/signin/profile_oauth2_token_service.h"
...@@ -94,7 +95,8 @@ class ProfileSyncServiceStartupTest : public testing::Test { ...@@ -94,7 +95,8 @@ class ProfileSyncServiceStartupTest : public testing::Test {
return new ProfileSyncService( return new ProfileSyncService(
new ProfileSyncComponentsFactoryMock(), new ProfileSyncComponentsFactoryMock(),
profile, profile,
SigninManagerFactory::GetForProfile(profile), new ManagedUserSigninManagerWrapper(
SigninManagerFactory::GetForProfile(profile)),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile), ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
ProfileSyncService::MANUAL_START); ProfileSyncService::MANUAL_START);
} }
...@@ -162,7 +164,7 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { ...@@ -162,7 +164,7 @@ class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
return new ProfileSyncService( return new ProfileSyncService(
new ProfileSyncComponentsFactoryMock(), new ProfileSyncComponentsFactoryMock(),
profile, profile,
signin, new ManagedUserSigninManagerWrapper(signin),
oauth2_token_service, oauth2_token_service,
ProfileSyncService::AUTO_START); ProfileSyncService::AUTO_START);
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/invalidation/invalidation_service_factory.h" #include "chrome/browser/invalidation/invalidation_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service.h" #include "chrome/browser/signin/fake_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.h"
...@@ -125,7 +126,7 @@ class ProfileSyncServiceTest : public ::testing::Test { ...@@ -125,7 +126,7 @@ class ProfileSyncServiceTest : public ::testing::Test {
service_.reset(new ProfileSyncService( service_.reset(new ProfileSyncService(
components_factory_, components_factory_,
profile_.get(), profile_.get(),
signin, new ManagedUserSigninManagerWrapper(signin),
oauth2_token_service, oauth2_token_service,
behavior)); behavior));
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/sync/test_profile_sync_service.h" #include "chrome/browser/sync/test_profile_sync_service.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/managed_mode/managed_user_signin_manager_wrapper.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.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
...@@ -103,7 +104,7 @@ TestProfileSyncService::TestProfileSyncService( ...@@ -103,7 +104,7 @@ TestProfileSyncService::TestProfileSyncService(
ProfileSyncService::StartBehavior behavior) ProfileSyncService::StartBehavior behavior)
: ProfileSyncService(factory, : ProfileSyncService(factory,
profile, profile,
signin, new ManagedUserSigninManagerWrapper(signin),
oauth2_token_service, oauth2_token_service,
behavior) { behavior) {
SetSyncSetupCompleted(); SetSyncSetupCompleted();
......
...@@ -1089,6 +1089,8 @@ ...@@ -1089,6 +1089,8 @@
'browser/managed_mode/managed_user_shared_settings_service_factory.h', 'browser/managed_mode/managed_user_shared_settings_service_factory.h',
'browser/managed_mode/managed_user_shared_settings_update.cc', 'browser/managed_mode/managed_user_shared_settings_update.cc',
'browser/managed_mode/managed_user_shared_settings_update.h', 'browser/managed_mode/managed_user_shared_settings_update.h',
'browser/managed_mode/managed_user_signin_manager_wrapper.cc',
'browser/managed_mode/managed_user_signin_manager_wrapper.h',
'browser/managed_mode/managed_user_sync_service.cc', 'browser/managed_mode/managed_user_sync_service.cc',
'browser/managed_mode/managed_user_sync_service.h', 'browser/managed_mode/managed_user_sync_service.h',
'browser/managed_mode/managed_user_sync_service_factory.cc', 'browser/managed_mode/managed_user_sync_service_factory.cc',
......
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