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

Side by Side 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: invalidation 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/managed_mode/managed_user_service.h" 5 #include "chrome/browser/managed_mode/managed_user_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 urls->push_back(url); 406 urls->push_back(url);
407 } 407 }
408 } 408 }
409 409
410 void ManagedUserService::InitForTesting() { 410 void ManagedUserService::InitForTesting() {
411 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kProfileIsManaged)); 411 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kProfileIsManaged));
412 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); 412 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true);
413 Init(); 413 Init();
414 } 414 }
415 415
416 void ManagedUserService::InitSync(const std::string& sync_token) { 416 void ManagedUserService::InitSync(const std::string& refresh_token) {
417 ProfileSyncService* service = 417 ProfileSyncService* service =
418 ProfileSyncServiceFactory::GetForProfile(profile_); 418 ProfileSyncServiceFactory::GetForProfile(profile_);
419 DCHECK(!service->sync_initialized()); 419 DCHECK(!service->sync_initialized());
420 // Tell the sync service that setup is in progress so we don't start syncing 420 // Tell the sync service that setup is in progress so we don't start syncing
421 // until we've finished configuration. 421 // until we've finished configuration.
422 service->SetSetupInProgress(true); 422 service->SetSetupInProgress(true);
423 423
424 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 424 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
425 token_service->AddAuthTokenManually(GaiaConstants::kSyncService, sync_token); 425 token_service->UpdateCredentialsWithOAuth2(
426 GaiaAuthConsumer::ClientOAuthResult(refresh_token, std::string(), 0));
426 427
427 bool sync_everything = false; 428 bool sync_everything = false;
428 syncer::ModelTypeSet synced_datatypes; 429 syncer::ModelTypeSet synced_datatypes;
429 synced_datatypes.Put(syncer::MANAGED_USER_SETTINGS); 430 synced_datatypes.Put(syncer::MANAGED_USER_SETTINGS);
430 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); 431 service->OnUserChoseDatatypes(sync_everything, synced_datatypes);
431 432
432 // Notify ProfileSyncService that we are done with configuration. 433 // Notify ProfileSyncService that we are done with configuration.
433 service->SetSetupInProgress(false); 434 service->SetSetupInProgress(false);
434 service->SetSyncSetupCompleted(); 435 service->SetSyncSetupCompleted();
435 } 436 }
(...skipping 11 matching lines...) Expand all
447 448
448 return; 449 return;
449 } 450 }
450 451
451 CommandLine* command_line = CommandLine::ForCurrentProcess(); 452 CommandLine* command_line = CommandLine::ForCurrentProcess();
452 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { 453 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) {
453 InitSync( 454 InitSync(
454 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); 455 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken));
455 } 456 }
456 457
458 // TokenService only loads tokens automatically if we're signed in, so we have
459 // to nudge it ourselves.
460 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
461 token_service->LoadTokensFromDB();
462
457 extensions::ExtensionSystem* extension_system = 463 extensions::ExtensionSystem* extension_system =
458 extensions::ExtensionSystem::Get(profile_); 464 extensions::ExtensionSystem::Get(profile_);
459 extensions::ManagementPolicy* management_policy = 465 extensions::ManagementPolicy* management_policy =
460 extension_system->management_policy(); 466 extension_system->management_policy();
461 if (management_policy) 467 if (management_policy)
462 extension_system->management_policy()->RegisterProvider(this); 468 extension_system->management_policy()->RegisterProvider(this);
463 469
464 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 470 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
465 content::Source<Profile>(profile_)); 471 content::Source<Profile>(profile_));
466 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 472 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); 547 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs);
542 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); 548 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>());
543 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { 549 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
544 bool allow = false; 550 bool allow = false;
545 bool result = it.value().GetAsBoolean(&allow); 551 bool result = it.value().GetAsBoolean(&allow);
546 DCHECK(result); 552 DCHECK(result);
547 (*url_map)[GURL(it.key())] = allow; 553 (*url_map)[GURL(it.key())] = allow;
548 } 554 }
549 url_filter_context_.SetManualURLs(url_map.Pass()); 555 url_filter_context_.SetManualURLs(url_map.Pass());
550 } 556 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698