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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 registry->RegisterDictionaryPref( | 169 registry->RegisterDictionaryPref( |
170 prefs::kManagedModeManualHosts, | 170 prefs::kManagedModeManualHosts, |
171 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 171 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
172 registry->RegisterDictionaryPref( | 172 registry->RegisterDictionaryPref( |
173 prefs::kManagedModeManualURLs, | 173 prefs::kManagedModeManualURLs, |
174 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 174 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
175 registry->RegisterIntegerPref( | 175 registry->RegisterIntegerPref( |
176 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, | 176 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, |
177 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 177 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
178 registry->RegisterStringPref( | 178 registry->RegisterStringPref( |
179 prefs::kManagedUserCustodian, std::string(), | 179 prefs::kManagedUserCustodianEmail, std::string(), |
| 180 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 181 registry->RegisterStringPref( |
| 182 prefs::kManagedUserCustodianName, std::string(), |
180 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 183 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
181 } | 184 } |
182 | 185 |
183 // static | 186 // static |
184 bool ManagedUserService::AreManagedUsersEnabled() { | 187 bool ManagedUserService::AreManagedUsersEnabled() { |
185 // Allow enabling by command line for now for easier development. | 188 // Allow enabling by command line for now for easier development. |
186 return base::FieldTrialList::FindFullName(kManagedModeFinchName) == | 189 return base::FieldTrialList::FindFullName(kManagedModeFinchName) == |
187 kManagedModeFinchActive || | 190 kManagedModeFinchActive || |
188 CommandLine::ForCurrentProcess()->HasSwitch( | 191 CommandLine::ForCurrentProcess()->HasSwitch( |
189 switches::kEnableManagedUsers); | 192 switches::kEnableManagedUsers); |
(...skipping 21 matching lines...) Expand all Loading... |
211 | 214 |
212 return (*sites.begin())->category_id; | 215 return (*sites.begin())->category_id; |
213 } | 216 } |
214 | 217 |
215 // static | 218 // static |
216 void ManagedUserService::GetCategoryNames(CategoryList* list) { | 219 void ManagedUserService::GetCategoryNames(CategoryList* list) { |
217 ManagedModeSiteList::GetCategoryNames(list); | 220 ManagedModeSiteList::GetCategoryNames(list); |
218 } | 221 } |
219 | 222 |
220 std::string ManagedUserService::GetCustodianEmailAddress() const { | 223 std::string ManagedUserService::GetCustodianEmailAddress() const { |
221 return profile_->GetPrefs()->GetString(prefs::kManagedUserCustodian); | 224 return profile_->GetPrefs()->GetString(prefs::kManagedUserCustodianEmail); |
| 225 } |
| 226 |
| 227 std::string ManagedUserService::GetCustodianName() const { |
| 228 std::string name = profile_->GetPrefs()->GetString( |
| 229 prefs::kManagedUserCustodianName); |
| 230 return name.empty() ? GetCustodianEmailAddress() : name; |
222 } | 231 } |
223 | 232 |
224 std::string ManagedUserService::GetDebugPolicyProviderName() const { | 233 std::string ManagedUserService::GetDebugPolicyProviderName() const { |
225 // Save the string space in official builds. | 234 // Save the string space in official builds. |
226 #ifdef NDEBUG | 235 #ifdef NDEBUG |
227 NOTREACHED(); | 236 NOTREACHED(); |
228 return std::string(); | 237 return std::string(); |
229 #else | 238 #else |
230 return "Managed User Service"; | 239 return "Managed User Service"; |
231 #endif | 240 #endif |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 bool ManagedUserService::ExtensionManagementPolicyImpl( | 349 bool ManagedUserService::ExtensionManagementPolicyImpl( |
341 const std::string& extension_id, | 350 const std::string& extension_id, |
342 string16* error) const { | 351 string16* error) const { |
343 if (!ProfileIsManaged()) | 352 if (!ProfileIsManaged()) |
344 return true; | 353 return true; |
345 | 354 |
346 if (elevated_for_testing_) | 355 if (elevated_for_testing_) |
347 return true; | 356 return true; |
348 | 357 |
349 if (error) | 358 if (error) |
350 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_MODE); | 359 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_USER); |
351 return false; | 360 return false; |
352 } | 361 } |
353 | 362 |
354 ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() { | 363 ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() { |
355 ScopedVector<ManagedModeSiteList> site_lists; | 364 ScopedVector<ManagedModeSiteList> site_lists; |
356 ExtensionService* extension_service = | 365 ExtensionService* extension_service = |
357 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 366 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
358 // Can be NULL in unit tests. | 367 // Can be NULL in unit tests. |
359 if (!extension_service) | 368 if (!extension_service) |
360 return site_lists.Pass(); | 369 return site_lists.Pass(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 // Initialize the filter. | 538 // Initialize the filter. |
530 OnDefaultFilteringBehaviorChanged(); | 539 OnDefaultFilteringBehaviorChanged(); |
531 UpdateSiteLists(); | 540 UpdateSiteLists(); |
532 UpdateManualHosts(); | 541 UpdateManualHosts(); |
533 UpdateManualURLs(); | 542 UpdateManualURLs(); |
534 } | 543 } |
535 | 544 |
536 void ManagedUserService::RegisterAndInitSync( | 545 void ManagedUserService::RegisterAndInitSync( |
537 Profile* custodian_profile, | 546 Profile* custodian_profile, |
538 const ProfileManager::CreateCallback& callback) { | 547 const ProfileManager::CreateCallback& callback) { |
| 548 |
| 549 // Register the managed user with the custodian's account. |
539 ManagedUserRegistrationService* registration_service = | 550 ManagedUserRegistrationService* registration_service = |
540 ManagedUserRegistrationServiceFactory::GetForProfile(custodian_profile); | 551 ManagedUserRegistrationServiceFactory::GetForProfile(custodian_profile); |
541 string16 name = UTF8ToUTF16( | 552 string16 name = UTF8ToUTF16( |
542 profile_->GetPrefs()->GetString(prefs::kProfileName)); | 553 profile_->GetPrefs()->GetString(prefs::kProfileName)); |
543 ManagedUserRegistrationInfo info(name); | 554 ManagedUserRegistrationInfo info(name); |
544 registration_service->Register( | 555 registration_service->Register( |
545 info, | 556 info, |
546 base::Bind(&ManagedUserService::OnManagedUserRegistered, | 557 base::Bind(&ManagedUserService::OnManagedUserRegistered, |
547 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 registration_service->DownloadProfile(custodian_profile, |
| 562 base::Bind(&ManagedUserService::OnCustodianProfileDownloaded, |
| 563 weak_ptr_factory_.GetWeakPtr())); |
| 564 } |
| 565 |
| 566 void ManagedUserService::OnCustodianProfileDownloaded( |
| 567 const string16& full_name) { |
| 568 // Store the custodian's display name in our prefs. |
| 569 // TODO(pamg): If --gaia-profile-info (keyword: switches::kGaiaProfileInfo) |
| 570 // is ever enabled, integrate with it properly. |
| 571 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianName, |
| 572 UTF16ToUTF8(full_name)); |
548 } | 573 } |
549 | 574 |
550 void ManagedUserService::OnManagedUserRegistered( | 575 void ManagedUserService::OnManagedUserRegistered( |
551 const ProfileManager::CreateCallback& callback, | 576 const ProfileManager::CreateCallback& callback, |
552 Profile* custodian_profile, | 577 Profile* custodian_profile, |
553 const GoogleServiceAuthError& auth_error, | 578 const GoogleServiceAuthError& auth_error, |
554 const std::string& token) { | 579 const std::string& token) { |
555 if (auth_error.state() != GoogleServiceAuthError::NONE) { | 580 if (auth_error.state() != GoogleServiceAuthError::NONE) { |
556 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); | 581 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); |
557 DCHECK_EQ(std::string(), token); | 582 DCHECK_EQ(std::string(), token); |
| 583 |
558 callback.Run(profile_, Profile::CREATE_STATUS_REMOTE_FAIL); | 584 callback.Run(profile_, Profile::CREATE_STATUS_REMOTE_FAIL); |
559 return; | 585 return; |
560 } | 586 } |
561 | 587 |
562 InitSync(token); | 588 InitSync(token); |
563 SigninManagerBase* signin = | 589 SigninManagerBase* signin = |
564 SigninManagerFactory::GetForProfile(custodian_profile); | 590 SigninManagerFactory::GetForProfile(custodian_profile); |
565 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodian, | 591 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianEmail, |
566 signin->GetAuthenticatedUsername()); | 592 signin->GetAuthenticatedUsername()); |
567 callback.Run(profile_, Profile::CREATE_STATUS_INITIALIZED); | 593 callback.Run(profile_, Profile::CREATE_STATUS_INITIALIZED); |
568 } | 594 } |
569 | 595 |
570 void ManagedUserService::UpdateManualHosts() { | 596 void ManagedUserService::UpdateManualHosts() { |
571 const DictionaryValue* dict = | 597 const DictionaryValue* dict = |
572 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); | 598 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); |
573 scoped_ptr<std::map<std::string, bool> > host_map( | 599 scoped_ptr<std::map<std::string, bool> > host_map( |
574 new std::map<std::string, bool>()); | 600 new std::map<std::string, bool>()); |
575 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 601 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
(...skipping 10 matching lines...) Expand all Loading... |
586 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 612 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
587 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 613 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
588 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 614 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
589 bool allow = false; | 615 bool allow = false; |
590 bool result = it.value().GetAsBoolean(&allow); | 616 bool result = it.value().GetAsBoolean(&allow); |
591 DCHECK(result); | 617 DCHECK(result); |
592 (*url_map)[GURL(it.key())] = allow; | 618 (*url_map)[GURL(it.key())] = allow; |
593 } | 619 } |
594 url_filter_context_.SetManualURLs(url_map.Pass()); | 620 url_filter_context_.SetManualURLs(url_map.Pass()); |
595 } | 621 } |
OLD | NEW |