| OLD | NEW |
| 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 urls->push_back(url); | 443 urls->push_back(url); |
| 444 } | 444 } |
| 445 } | 445 } |
| 446 | 446 |
| 447 void ManagedUserService::InitForTesting() { | 447 void ManagedUserService::InitForTesting() { |
| 448 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kProfileIsManaged)); | 448 DCHECK(!profile_->GetPrefs()->GetBoolean(prefs::kProfileIsManaged)); |
| 449 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); | 449 profile_->GetPrefs()->SetBoolean(prefs::kProfileIsManaged, true); |
| 450 Init(); | 450 Init(); |
| 451 } | 451 } |
| 452 | 452 |
| 453 void ManagedUserService::InitSync(const std::string& sync_token) { | 453 void ManagedUserService::InitSync(const std::string& refresh_token) { |
| 454 ProfileSyncService* service = | 454 ProfileSyncService* service = |
| 455 ProfileSyncServiceFactory::GetForProfile(profile_); | 455 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 456 DCHECK(!service->sync_initialized()); | 456 DCHECK(!service->sync_initialized()); |
| 457 // Tell the sync service that setup is in progress so we don't start syncing | 457 // Tell the sync service that setup is in progress so we don't start syncing |
| 458 // until we've finished configuration. | 458 // until we've finished configuration. |
| 459 service->SetSetupInProgress(true); | 459 service->SetSetupInProgress(true); |
| 460 | 460 |
| 461 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 461 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 462 token_service->AddAuthTokenManually(GaiaConstants::kSyncService, sync_token); | 462 token_service->UpdateCredentialsWithOAuth2( |
| 463 GaiaAuthConsumer::ClientOAuthResult(refresh_token, std::string(), 0)); |
| 463 | 464 |
| 464 bool sync_everything = false; | 465 bool sync_everything = false; |
| 465 syncer::ModelTypeSet synced_datatypes; | 466 syncer::ModelTypeSet synced_datatypes; |
| 466 synced_datatypes.Put(syncer::MANAGED_USER_SETTINGS); | 467 synced_datatypes.Put(syncer::MANAGED_USER_SETTINGS); |
| 467 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); | 468 service->OnUserChoseDatatypes(sync_everything, synced_datatypes); |
| 468 | 469 |
| 469 // Notify ProfileSyncService that we are done with configuration. | 470 // Notify ProfileSyncService that we are done with configuration. |
| 470 service->SetSetupInProgress(false); | 471 service->SetSetupInProgress(false); |
| 471 service->SetSyncSetupCompleted(); | 472 service->SetSyncSetupCompleted(); |
| 472 } | 473 } |
| 473 | 474 |
| 474 // static | 475 // static |
| 475 const char* ManagedUserService::GetManagedUserPseudoEmail() { | 476 const char* ManagedUserService::GetManagedUserPseudoEmail() { |
| 476 return kManagedUserPseudoEmail; | 477 return kManagedUserPseudoEmail; |
| 477 } | 478 } |
| 478 | 479 |
| 479 void ManagedUserService::Init() { | 480 void ManagedUserService::Init() { |
| 480 if (!ProfileIsManaged()) | 481 if (!ProfileIsManaged()) |
| 481 return; | 482 return; |
| 482 | 483 |
| 483 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 484 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 484 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { | 485 if (command_line->HasSwitch(switches::kManagedUserSyncToken)) { |
| 485 InitSync( | 486 InitSync( |
| 486 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); | 487 command_line->GetSwitchValueASCII(switches::kManagedUserSyncToken)); |
| 487 } | 488 } |
| 488 | 489 |
| 490 // TokenService only loads tokens automatically if we're signed in, so we have |
| 491 // to nudge it ourselves. |
| 492 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| 493 token_service->LoadTokensFromDB(); |
| 494 |
| 489 extensions::ExtensionSystem* extension_system = | 495 extensions::ExtensionSystem* extension_system = |
| 490 extensions::ExtensionSystem::Get(profile_); | 496 extensions::ExtensionSystem::Get(profile_); |
| 491 extensions::ManagementPolicy* management_policy = | 497 extensions::ManagementPolicy* management_policy = |
| 492 extension_system->management_policy(); | 498 extension_system->management_policy(); |
| 493 if (management_policy) | 499 if (management_policy) |
| 494 extension_system->management_policy()->RegisterProvider(this); | 500 extension_system->management_policy()->RegisterProvider(this); |
| 495 | 501 |
| 496 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 502 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 497 content::Source<Profile>(profile_)); | 503 content::Source<Profile>(profile_)); |
| 498 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 504 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 582 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
| 577 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 583 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
| 578 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 584 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 579 bool allow = false; | 585 bool allow = false; |
| 580 bool result = it.value().GetAsBoolean(&allow); | 586 bool result = it.value().GetAsBoolean(&allow); |
| 581 DCHECK(result); | 587 DCHECK(result); |
| 582 (*url_map)[GURL(it.key())] = allow; | 588 (*url_map)[GURL(it.key())] = allow; |
| 583 } | 589 } |
| 584 url_filter_context_.SetManualURLs(url_map.Pass()); | 590 url_filter_context_.SetManualURLs(url_map.Pass()); |
| 585 } | 591 } |
| OLD | NEW |