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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 if (auth_error.state() != GoogleServiceAuthError::NONE) { | 564 if (auth_error.state() != GoogleServiceAuthError::NONE) { |
556 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); | 565 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); |
557 DCHECK_EQ(std::string(), token); | 566 DCHECK_EQ(std::string(), token); |
558 callback.Run(profile_, Profile::CREATE_STATUS_REMOTE_FAIL); | 567 callback.Run(profile_, Profile::CREATE_STATUS_REMOTE_FAIL); |
559 return; | 568 return; |
560 } | 569 } |
561 | 570 |
562 InitSync(token); | 571 InitSync(token); |
563 SigninManagerBase* signin = | 572 SigninManagerBase* signin = |
564 SigninManagerFactory::GetForProfile(custodian_profile); | 573 SigninManagerFactory::GetForProfile(custodian_profile); |
565 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodian, | 574 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianEmail, |
566 signin->GetAuthenticatedUsername()); | 575 signin->GetAuthenticatedUsername()); |
567 callback.Run(profile_, Profile::CREATE_STATUS_INITIALIZED); | 576 callback.Run(profile_, Profile::CREATE_STATUS_INITIALIZED); |
568 } | 577 } |
569 | 578 |
570 void ManagedUserService::UpdateManualHosts() { | 579 void ManagedUserService::UpdateManualHosts() { |
571 const DictionaryValue* dict = | 580 const DictionaryValue* dict = |
572 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); | 581 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); |
573 scoped_ptr<std::map<std::string, bool> > host_map( | 582 scoped_ptr<std::map<std::string, bool> > host_map( |
574 new std::map<std::string, bool>()); | 583 new std::map<std::string, bool>()); |
575 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 584 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
(...skipping 10 matching lines...) Expand all Loading... |
586 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 595 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
587 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 596 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
588 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 597 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
589 bool allow = false; | 598 bool allow = false; |
590 bool result = it.value().GetAsBoolean(&allow); | 599 bool result = it.value().GetAsBoolean(&allow); |
591 DCHECK(result); | 600 DCHECK(result); |
592 (*url_map)[GURL(it.key())] = allow; | 601 (*url_map)[GURL(it.key())] = allow; |
593 } | 602 } |
594 url_filter_context_.SetManualURLs(url_map.Pass()); | 603 url_filter_context_.SetManualURLs(url_map.Pass()); |
595 } | 604 } |
OLD | NEW |