Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2767)

Unified Diff: chrome/browser/managed_mode/managed_user_service.cc

Issue 15780020: Setup Sync to use OAuth token for managed users. (Closed) Base URL: http://git.chromium.org/chromium/src.git@issue226464a
Patch Set: fix Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/managed_mode/managed_user_service.cc
diff --git a/chrome/browser/managed_mode/managed_user_service.cc b/chrome/browser/managed_mode/managed_user_service.cc
index 7ad603ad4f68849d0e70b588d30a4f74facc3536..7601dddad16cde5587a21beb649bf7c0b7c05db3 100644
--- a/chrome/browser/managed_mode/managed_user_service.cc
+++ b/chrome/browser/managed_mode/managed_user_service.cc
@@ -139,10 +139,21 @@ void ManagedUserService::URLFilterContext::SetManualURLs(
ManagedUserService::ManagedUserService(Profile* profile)
: weak_ptr_factory_(this),
profile_(profile),
- elevated_for_testing_(false) {}
+ waiting_for_sync_initialization_(false),
+ elevated_for_testing_(false) {
+}
ManagedUserService::~ManagedUserService() {}
+void ManagedUserService::Shutdown() {
+ if (!waiting_for_sync_initialization_)
+ return;
+
+ ProfileSyncService* sync_service =
+ ProfileSyncServiceFactory::GetForProfile(profile_);
+ sync_service->RemoveObserver(this);
+}
+
bool ManagedUserService::ProfileIsManaged() const {
return ProfileIsManaged(profile_);
}
@@ -269,6 +280,21 @@ bool ManagedUserService::UserMayModifySettings(
extension ? extension->id() : std::string(), error);
}
+void ManagedUserService::OnStateChanged() {
+ ProfileSyncService* service =
+ ProfileSyncServiceFactory::GetForProfile(profile_);
+ if (waiting_for_sync_initialization_ && service->sync_initialized()) {
+ SetupSync();
+ service->RemoveObserver(this);
+ waiting_for_sync_initialization_ = false;
+ return;
+ }
+
+ DLOG_IF(ERROR, service->GetAuthError().state() ==
+ GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)
+ << "Credentials rejected";
+}
+
void ManagedUserService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -296,6 +322,21 @@ void ManagedUserService::Observe(int type,
}
}
+void ManagedUserService::SetupSync() {
+ ProfileSyncService* service =
+ ProfileSyncServiceFactory::GetForProfile(profile_);
+ DCHECK(service->sync_initialized());
+
+ bool sync_everything = false;
+ syncer::ModelTypeSet synced_datatypes;
+ synced_datatypes.Put(syncer::MANAGED_USER_SETTINGS);
+ service->OnUserChoseDatatypes(sync_everything, synced_datatypes);
+
+ // Notify ProfileSyncService that we are done with configuration.
+ service->SetSetupInProgress(false);
+ service->SetSyncSetupCompleted();
+}
+
bool ManagedUserService::ExtensionManagementPolicyImpl(
const std::string& extension_id,
string16* error) const {
@@ -413,25 +454,24 @@ void ManagedUserService::InitForTesting() {
Init();
}
-void ManagedUserService::InitSync(const std::string& sync_token) {
+void ManagedUserService::InitSync(const std::string& refresh_token) {
ProfileSyncService* service =
ProfileSyncServiceFactory::GetForProfile(profile_);
- DCHECK(!service->sync_initialized());
// Tell the sync service that setup is in progress so we don't start syncing
// until we've finished configuration.
service->SetSetupInProgress(true);
TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
- token_service->AddAuthTokenManually(GaiaConstants::kSyncService, sync_token);
-
- bool sync_everything = false;
- syncer::ModelTypeSet synced_datatypes;
- synced_datatypes.Put(syncer::MANAGED_USER_SETTINGS);
- service->OnUserChoseDatatypes(sync_everything, synced_datatypes);
-
- // Notify ProfileSyncService that we are done with configuration.
- service->SetSetupInProgress(false);
- service->SetSyncSetupCompleted();
+ token_service->UpdateCredentialsWithOAuth2(
+ GaiaAuthConsumer::ClientOAuthResult(refresh_token, std::string(), 0));
+
+ // Continue in SetupSync() once the Sync backend has been initialized.
+ if (service->sync_initialized()) {
+ SetupSync();
+ } else {
+ ProfileSyncServiceFactory::GetForProfile(profile_)->AddObserver(this);
+ waiting_for_sync_initialization_ = true;
+ }
}
// static
@@ -454,6 +494,11 @@ void ManagedUserService::Init() {
command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken));
}
+ // TokenService only loads tokens automatically if we're signed in, so we have
+ // to nudge it ourselves.
+ TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
+ token_service->LoadTokensFromDB();
+
extensions::ExtensionSystem* extension_system =
extensions::ExtensionSystem::Get(profile_);
extensions::ManagementPolicy* management_policy =

Powered by Google App Engine
This is Rietveld 408576698