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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 registry->RegisterDictionaryPref( | 158 registry->RegisterDictionaryPref( |
159 prefs::kManagedModeManualHosts, | 159 prefs::kManagedModeManualHosts, |
160 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 160 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
161 registry->RegisterDictionaryPref( | 161 registry->RegisterDictionaryPref( |
162 prefs::kManagedModeManualURLs, | 162 prefs::kManagedModeManualURLs, |
163 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 163 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
164 registry->RegisterIntegerPref( | 164 registry->RegisterIntegerPref( |
165 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, | 165 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, |
166 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 166 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
167 registry->RegisterStringPref( | 167 registry->RegisterStringPref( |
168 prefs::kManagedUserCustodian, std::string(), | 168 prefs::kManagedUserCustodianEmail, std::string(), |
| 169 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 170 registry->RegisterStringPref( |
| 171 prefs::kManagedUserCustodianName, std::string(), |
169 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 172 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
170 } | 173 } |
171 | 174 |
172 // static | 175 // static |
173 bool ManagedUserService::AreManagedUsersEnabled() { | 176 bool ManagedUserService::AreManagedUsersEnabled() { |
174 // Allow enabling by command line for now for easier development. | 177 // Allow enabling by command line for now for easier development. |
175 return base::FieldTrialList::FindFullName(kManagedModeFinchName) == | 178 return base::FieldTrialList::FindFullName(kManagedModeFinchName) == |
176 kManagedModeFinchActive || | 179 kManagedModeFinchActive || |
177 CommandLine::ForCurrentProcess()->HasSwitch( | 180 CommandLine::ForCurrentProcess()->HasSwitch( |
178 switches::kEnableManagedUsers); | 181 switches::kEnableManagedUsers); |
(...skipping 21 matching lines...) Expand all Loading... |
200 | 203 |
201 return (*sites.begin())->category_id; | 204 return (*sites.begin())->category_id; |
202 } | 205 } |
203 | 206 |
204 // static | 207 // static |
205 void ManagedUserService::GetCategoryNames(CategoryList* list) { | 208 void ManagedUserService::GetCategoryNames(CategoryList* list) { |
206 ManagedModeSiteList::GetCategoryNames(list); | 209 ManagedModeSiteList::GetCategoryNames(list); |
207 } | 210 } |
208 | 211 |
209 std::string ManagedUserService::GetCustodianEmailAddress() const { | 212 std::string ManagedUserService::GetCustodianEmailAddress() const { |
210 return profile_->GetPrefs()->GetString(prefs::kManagedUserCustodian); | 213 return profile_->GetPrefs()->GetString(prefs::kManagedUserCustodianEmail); |
| 214 } |
| 215 |
| 216 std::string ManagedUserService::GetCustodianName() const { |
| 217 std::string name = profile_->GetPrefs()->GetString( |
| 218 prefs::kManagedUserCustodianName); |
| 219 return name.empty() ? GetCustodianEmailAddress() : name; |
211 } | 220 } |
212 | 221 |
213 std::string ManagedUserService::GetDebugPolicyProviderName() const { | 222 std::string ManagedUserService::GetDebugPolicyProviderName() const { |
214 // Save the string space in official builds. | 223 // Save the string space in official builds. |
215 #ifdef NDEBUG | 224 #ifdef NDEBUG |
216 NOTREACHED(); | 225 NOTREACHED(); |
217 return std::string(); | 226 return std::string(); |
218 #else | 227 #else |
219 return "Managed User Service"; | 228 return "Managed User Service"; |
220 #endif | 229 #endif |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 if (auth_error.state() != GoogleServiceAuthError::NONE) { | 519 if (auth_error.state() != GoogleServiceAuthError::NONE) { |
511 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); | 520 LOG(ERROR) << "Managed user OAuth error: " << auth_error.ToString(); |
512 DCHECK_EQ(std::string(), token); | 521 DCHECK_EQ(std::string(), token); |
513 callback.Run(profile_, Profile::CREATE_STATUS_REMOTE_FAIL); | 522 callback.Run(profile_, Profile::CREATE_STATUS_REMOTE_FAIL); |
514 return; | 523 return; |
515 } | 524 } |
516 | 525 |
517 InitSync(token); | 526 InitSync(token); |
518 SigninManagerBase* signin = | 527 SigninManagerBase* signin = |
519 SigninManagerFactory::GetForProfile(custodian_profile); | 528 SigninManagerFactory::GetForProfile(custodian_profile); |
520 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodian, | 529 profile_->GetPrefs()->SetString(prefs::kManagedUserCustodianEmail, |
521 signin->GetAuthenticatedUsername()); | 530 signin->GetAuthenticatedUsername()); |
522 callback.Run(profile_, Profile::CREATE_STATUS_INITIALIZED); | 531 callback.Run(profile_, Profile::CREATE_STATUS_INITIALIZED); |
523 } | 532 } |
524 | 533 |
525 void ManagedUserService::UpdateManualHosts() { | 534 void ManagedUserService::UpdateManualHosts() { |
526 const DictionaryValue* dict = | 535 const DictionaryValue* dict = |
527 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); | 536 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualHosts); |
528 scoped_ptr<std::map<std::string, bool> > host_map( | 537 scoped_ptr<std::map<std::string, bool> > host_map( |
529 new std::map<std::string, bool>()); | 538 new std::map<std::string, bool>()); |
530 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 539 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
(...skipping 10 matching lines...) Expand all Loading... |
541 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 550 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
542 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 551 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
543 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 552 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
544 bool allow = false; | 553 bool allow = false; |
545 bool result = it.value().GetAsBoolean(&allow); | 554 bool result = it.value().GetAsBoolean(&allow); |
546 DCHECK(result); | 555 DCHECK(result); |
547 (*url_map)[GURL(it.key())] = allow; | 556 (*url_map)[GURL(it.key())] = allow; |
548 } | 557 } |
549 url_filter_context_.SetManualURLs(url_map.Pass()); | 558 url_filter_context_.SetManualURLs(url_map.Pass()); |
550 } | 559 } |
OLD | NEW |