| 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" |
| 11 #include "base/sequenced_task_runner.h" | 11 #include "base/sequenced_task_runner.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
| 15 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" | |
| 16 #include "chrome/browser/managed_mode/managed_mode_site_list.h" | 15 #include "chrome/browser/managed_mode/managed_mode_site_list.h" |
| 17 #include "chrome/browser/managed_mode/managed_user_registration_service.h" | 16 #include "chrome/browser/managed_mode/managed_user_registration_service.h" |
| 18 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 17 #include "chrome/browser/policy/managed_mode_policy_provider.h" |
| 19 #include "chrome/browser/policy/profile_policy_connector.h" | 18 #include "chrome/browser/policy/profile_policy_connector.h" |
| 20 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 19 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 21 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/signin/token_service.h" | 22 #include "chrome/browser/signin/token_service.h" |
| 24 #include "chrome/browser/signin/token_service_factory.h" | 23 #include "chrome/browser/signin/token_service_factory.h" |
| 25 #include "chrome/browser/sync/glue/session_model_associator.h" | 24 #include "chrome/browser/sync/glue/session_model_associator.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 138 |
| 140 bool ManagedUserService::ProfileIsManaged() const { | 139 bool ManagedUserService::ProfileIsManaged() const { |
| 141 return ProfileIsManaged(profile_); | 140 return ProfileIsManaged(profile_); |
| 142 } | 141 } |
| 143 | 142 |
| 144 // static | 143 // static |
| 145 bool ManagedUserService::ProfileIsManaged(Profile* profile) { | 144 bool ManagedUserService::ProfileIsManaged(Profile* profile) { |
| 146 return profile->GetPrefs()->GetBoolean(prefs::kProfileIsManaged); | 145 return profile->GetPrefs()->GetBoolean(prefs::kProfileIsManaged); |
| 147 } | 146 } |
| 148 | 147 |
| 149 bool ManagedUserService::IsElevatedForWebContents( | |
| 150 const content::WebContents* web_contents) const { | |
| 151 const ManagedModeNavigationObserver* observer = | |
| 152 ManagedModeNavigationObserver::FromWebContents(web_contents); | |
| 153 return observer ? observer->is_elevated() : false; | |
| 154 } | |
| 155 | |
| 156 bool ManagedUserService::IsPassphraseEmpty() const { | |
| 157 PrefService* pref_service = profile_->GetPrefs(); | |
| 158 return pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty(); | |
| 159 } | |
| 160 | |
| 161 bool ManagedUserService::CanSkipPassphraseDialog( | |
| 162 const content::WebContents* web_contents) const { | |
| 163 #if defined(OS_CHROMEOS) | |
| 164 NOTREACHED(); | |
| 165 #endif | |
| 166 return IsElevatedForWebContents(web_contents) || | |
| 167 IsPassphraseEmpty(); | |
| 168 } | |
| 169 | |
| 170 void ManagedUserService::RequestAuthorization( | |
| 171 content::WebContents* web_contents, | |
| 172 const PassphraseCheckedCallback& callback) { | |
| 173 #if defined(OS_CHROMEOS) | |
| 174 NOTREACHED(); | |
| 175 #endif | |
| 176 | |
| 177 if (CanSkipPassphraseDialog(web_contents)) { | |
| 178 callback.Run(true); | |
| 179 return; | |
| 180 } | |
| 181 | |
| 182 // Is deleted automatically when the dialog is closed. | |
| 183 new ManagedUserPassphraseDialog(web_contents, callback); | |
| 184 } | |
| 185 | |
| 186 // static | 148 // static |
| 187 void ManagedUserService::RegisterUserPrefs( | 149 void ManagedUserService::RegisterUserPrefs( |
| 188 user_prefs::PrefRegistrySyncable* registry) { | 150 user_prefs::PrefRegistrySyncable* registry) { |
| 189 registry->RegisterDictionaryPref( | 151 registry->RegisterDictionaryPref( |
| 190 prefs::kManagedModeManualHosts, | 152 prefs::kManagedModeManualHosts, |
| 191 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 153 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 192 registry->RegisterDictionaryPref( | 154 registry->RegisterDictionaryPref( |
| 193 prefs::kManagedModeManualURLs, | 155 prefs::kManagedModeManualURLs, |
| 194 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 156 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 195 registry->RegisterIntegerPref( | 157 registry->RegisterIntegerPref( |
| 196 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, | 158 prefs::kDefaultManagedModeFilteringBehavior, ManagedModeURLFilter::ALLOW, |
| 197 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 159 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 198 registry->RegisterStringPref( | |
| 199 prefs::kManagedModeLocalPassphrase, std::string(), | |
| 200 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 201 registry->RegisterStringPref( | |
| 202 prefs::kManagedModeLocalSalt, std::string(), | |
| 203 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 204 } | 160 } |
| 205 | 161 |
| 206 // static | 162 // static |
| 207 bool ManagedUserService::AreManagedUsersEnabled() { | 163 bool ManagedUserService::AreManagedUsersEnabled() { |
| 208 // Allow enabling by command line for now for easier development. | 164 // Allow enabling by command line for now for easier development. |
| 209 return base::FieldTrialList::FindFullName(kManagedModeFinchName) == | 165 return base::FieldTrialList::FindFullName(kManagedModeFinchName) == |
| 210 kManagedModeFinchActive || | 166 kManagedModeFinchActive || |
| 211 CommandLine::ForCurrentProcess()->HasSwitch( | 167 CommandLine::ForCurrentProcess()->HasSwitch( |
| 212 switches::kEnableManagedUsers); | 168 switches::kEnableManagedUsers); |
| 213 } | 169 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 | 290 |
| 335 bool ManagedUserService::ExtensionManagementPolicyImpl( | 291 bool ManagedUserService::ExtensionManagementPolicyImpl( |
| 336 const std::string& extension_id, | 292 const std::string& extension_id, |
| 337 string16* error) const { | 293 string16* error) const { |
| 338 if (!ProfileIsManaged()) | 294 if (!ProfileIsManaged()) |
| 339 return true; | 295 return true; |
| 340 | 296 |
| 341 if (elevated_for_testing_) | 297 if (elevated_for_testing_) |
| 342 return true; | 298 return true; |
| 343 | 299 |
| 344 if (elevated_for_extensions_.count(extension_id)) | |
| 345 return true; | |
| 346 | |
| 347 if (error) | 300 if (error) |
| 348 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_MODE); | 301 *error = l10n_util::GetStringUTF16(IDS_EXTENSIONS_LOCKED_MANAGED_MODE); |
| 349 return false; | 302 return false; |
| 350 } | 303 } |
| 351 | 304 |
| 352 ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() { | 305 ScopedVector<ManagedModeSiteList> ManagedUserService::GetActiveSiteLists() { |
| 353 ScopedVector<ManagedModeSiteList> site_lists; | 306 ScopedVector<ManagedModeSiteList> site_lists; |
| 354 ExtensionService* extension_service = | 307 ExtensionService* extension_service = |
| 355 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 308 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 356 // Can be NULL in unit tests. | 309 // Can be NULL in unit tests. |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 559 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
| 607 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 560 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
| 608 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 561 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
| 609 bool allow = false; | 562 bool allow = false; |
| 610 bool result = it.value().GetAsBoolean(&allow); | 563 bool result = it.value().GetAsBoolean(&allow); |
| 611 DCHECK(result); | 564 DCHECK(result); |
| 612 (*url_map)[GURL(it.key())] = allow; | 565 (*url_map)[GURL(it.key())] = allow; |
| 613 } | 566 } |
| 614 url_filter_context_.SetManualURLs(url_map.Pass()); | 567 url_filter_context_.SetManualURLs(url_map.Pass()); |
| 615 } | 568 } |
| OLD | NEW |