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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 // Initialize the filter. | 538 // Initialize the filter. |
539 OnDefaultFilteringBehaviorChanged(); | 539 OnDefaultFilteringBehaviorChanged(); |
540 UpdateSiteLists(); | 540 UpdateSiteLists(); |
541 UpdateManualHosts(); | 541 UpdateManualHosts(); |
542 UpdateManualURLs(); | 542 UpdateManualURLs(); |
543 } | 543 } |
544 | 544 |
545 void ManagedUserService::RegisterAndInitSync( | 545 void ManagedUserService::RegisterAndInitSync( |
546 Profile* custodian_profile, | 546 Profile* custodian_profile, |
547 const ProfileManager::CreateCallback& callback) { | 547 const ProfileManager::CreateCallback& callback) { |
| 548 |
| 549 // Register the managed user with the custodian's account. |
548 ManagedUserRegistrationService* registration_service = | 550 ManagedUserRegistrationService* registration_service = |
549 ManagedUserRegistrationServiceFactory::GetForProfile(custodian_profile); | 551 ManagedUserRegistrationServiceFactory::GetForProfile(custodian_profile); |
550 string16 name = UTF8ToUTF16( | 552 string16 name = UTF8ToUTF16( |
551 profile_->GetPrefs()->GetString(prefs::kProfileName)); | 553 profile_->GetPrefs()->GetString(prefs::kProfileName)); |
552 ManagedUserRegistrationInfo info(name); | 554 ManagedUserRegistrationInfo info(name); |
553 registration_service->Register( | 555 registration_service->Register( |
554 info, | 556 info, |
555 base::Bind(&ManagedUserService::OnManagedUserRegistered, | 557 base::Bind(&ManagedUserService::OnManagedUserRegistered, |
556 weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile)); | 558 weak_ptr_factory_.GetWeakPtr(), callback, custodian_profile)); |
| 559 |
| 560 // Fetch the custodian's profile information, to store the name. |
| 561 // TODO(pamg): If --gaia-profile-info (keyword: switches::kGaiaProfileInfo) |
| 562 // is ever enabled, take the name from the ProfileInfoCache instead. |
| 563 registration_service->DownloadProfile(custodian_profile, |
| 564 base::Bind(&ManagedUserService::OnCustodianProfileDownloaded, |
| 565 weak_ptr_factory_.GetWeakPtr())); |
| 566 } |
| 567 |
| 568 void ManagedUserService::OnCustodianProfileDownloaded( |
| 569 const string16& full_name) { |
| 570 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianName, |
| 571 UTF16ToUTF8(full_name)); |
557 } | 572 } |
558 | 573 |
559 void ManagedUserService::OnManagedUserRegistered( | 574 void ManagedUserService::OnManagedUserRegistered( |
560 const ProfileManager::CreateCallback& callback, | 575 const ProfileManager::CreateCallback& callback, |
561 Profile* custodian_profile, | 576 Profile* custodian_profile, |
562 const GoogleServiceAuthError& auth_error, | 577 const GoogleServiceAuthError& auth_error, |
563 const std::string& token) { | 578 const std::string& token) { |
564 if (auth_error.state() != GoogleServiceAuthError::NONE) { | 579 if (auth_error.state() != GoogleServiceAuthError::NONE) { |
565 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); | 580 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); |
566 DCHECK_EQ(std::string(), token); | 581 DCHECK_EQ(std::string(), token); |
(...skipping 28 matching lines...) Expand all Loading... |
595 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 610 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
596 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 611 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
597 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 612 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
598 bool allow = false; | 613 bool allow = false; |
599 bool result = it.value().GetAsBoolean(&allow); | 614 bool result = it.value().GetAsBoolean(&allow); |
600 DCHECK(result); | 615 DCHECK(result); |
601 (*url_map)[GURL(it.key())] = allow; | 616 (*url_map)[GURL(it.key())] = allow; |
602 } | 617 } |
603 url_filter_context_.SetManualURLs(url_map.Pass()); | 618 url_filter_context_.SetManualURLs(url_map.Pass()); |
604 } | 619 } |
OLD | NEW |