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/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // static | 147 // static |
148 void ManagedUserService::RegisterUserPrefs(PrefRegistrySyncable* registry) { | 148 void ManagedUserService::RegisterUserPrefs(PrefRegistrySyncable* registry) { |
149 registry->RegisterDictionaryPref(prefs::kManagedModeManualHosts, | 149 registry->RegisterDictionaryPref(prefs::kManagedModeManualHosts, |
150 PrefRegistrySyncable::UNSYNCABLE_PREF); | 150 PrefRegistrySyncable::UNSYNCABLE_PREF); |
151 registry->RegisterDictionaryPref(prefs::kManagedModeManualURLs, | 151 registry->RegisterDictionaryPref(prefs::kManagedModeManualURLs, |
152 PrefRegistrySyncable::UNSYNCABLE_PREF); | 152 PrefRegistrySyncable::UNSYNCABLE_PREF); |
153 registry->RegisterIntegerPref(prefs::kDefaultManagedModeFilteringBehavior, | 153 registry->RegisterIntegerPref(prefs::kDefaultManagedModeFilteringBehavior, |
154 ManagedModeURLFilter::BLOCK, | 154 ManagedModeURLFilter::BLOCK, |
155 PrefRegistrySyncable::UNSYNCABLE_PREF); | 155 PrefRegistrySyncable::UNSYNCABLE_PREF); |
156 registry->RegisterStringPref(prefs::kManagedModeLocalPassphrase, | 156 registry->RegisterStringPref(prefs::kManagedModeLocalPassphrase, |
157 "", | 157 std::string(), |
158 PrefRegistrySyncable::UNSYNCABLE_PREF); | 158 PrefRegistrySyncable::UNSYNCABLE_PREF); |
159 registry->RegisterStringPref(prefs::kManagedModeLocalSalt, | 159 registry->RegisterStringPref(prefs::kManagedModeLocalSalt, |
160 "", | 160 std::string(), |
161 PrefRegistrySyncable::UNSYNCABLE_PREF); | 161 PrefRegistrySyncable::UNSYNCABLE_PREF); |
162 } | 162 } |
163 | 163 |
164 scoped_refptr<const ManagedModeURLFilter> | 164 scoped_refptr<const ManagedModeURLFilter> |
165 ManagedUserService::GetURLFilterForIOThread() { | 165 ManagedUserService::GetURLFilterForIOThread() { |
166 return url_filter_context_.io_url_filter(); | 166 return url_filter_context_.io_url_filter(); |
167 } | 167 } |
168 | 168 |
169 ManagedModeURLFilter* ManagedUserService::GetURLFilterForUIThread() { | 169 ManagedModeURLFilter* ManagedUserService::GetURLFilterForUIThread() { |
170 return url_filter_context_.ui_url_filter(); | 170 return url_filter_context_.ui_url_filter(); |
(...skipping 25 matching lines...) Expand all Loading... |
196 return std::string(); | 196 return std::string(); |
197 #else | 197 #else |
198 return "Managed User Service"; | 198 return "Managed User Service"; |
199 #endif | 199 #endif |
200 } | 200 } |
201 | 201 |
202 bool ManagedUserService::UserMayLoad(const extensions::Extension* extension, | 202 bool ManagedUserService::UserMayLoad(const extensions::Extension* extension, |
203 string16* error) const { | 203 string16* error) const { |
204 string16 tmp_error; | 204 string16 tmp_error; |
205 // |extension| can be NULL in unit tests. | 205 // |extension| can be NULL in unit tests. |
206 if (ExtensionManagementPolicyImpl(extension ? extension->id() : "", | 206 if (ExtensionManagementPolicyImpl(extension ? extension->id() : std::string(), |
207 &tmp_error)) | 207 &tmp_error)) |
208 return true; | 208 return true; |
209 | 209 |
210 // If the extension is already loaded, we allow it, otherwise we'd unload | 210 // If the extension is already loaded, we allow it, otherwise we'd unload |
211 // all existing extensions. | 211 // all existing extensions. |
212 ExtensionService* extension_service = | 212 ExtensionService* extension_service = |
213 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 213 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
214 | 214 |
215 // |extension_service| can be NULL in a unit test. | 215 // |extension_service| can be NULL in a unit test. |
216 if (extension_service && | 216 if (extension_service && |
(...skipping 20 matching lines...) Expand all Loading... |
237 | 237 |
238 if (error) | 238 if (error) |
239 *error = tmp_error; | 239 *error = tmp_error; |
240 return false; | 240 return false; |
241 } | 241 } |
242 | 242 |
243 bool ManagedUserService::UserMayModifySettings( | 243 bool ManagedUserService::UserMayModifySettings( |
244 const extensions::Extension* extension, | 244 const extensions::Extension* extension, |
245 string16* error) const { | 245 string16* error) const { |
246 // |extension| can be NULL in unit tests. | 246 // |extension| can be NULL in unit tests. |
247 return ExtensionManagementPolicyImpl(extension ? extension->id() : "", error); | 247 return ExtensionManagementPolicyImpl( |
| 248 extension ? extension->id() : std::string(), error); |
248 } | 249 } |
249 | 250 |
250 void ManagedUserService::Observe(int type, | 251 void ManagedUserService::Observe(int type, |
251 const content::NotificationSource& source, | 252 const content::NotificationSource& source, |
252 const content::NotificationDetails& details) { | 253 const content::NotificationDetails& details) { |
253 switch (type) { | 254 switch (type) { |
254 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 255 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
255 const extensions::Extension* extension = | 256 const extensions::Extension* extension = |
256 content::Details<extensions::Extension>(details).ptr(); | 257 content::Details<extensions::Extension>(details).ptr(); |
257 if (!extensions::ManagedModeInfo::GetContentPackSiteList( | 258 if (!extensions::ManagedModeInfo::GetContentPackSiteList( |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); | 478 profile_->GetPrefs()->GetDictionary(prefs::kManagedModeManualURLs); |
478 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); | 479 scoped_ptr<std::map<GURL, bool> > url_map(new std::map<GURL, bool>()); |
479 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { | 480 for (DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) { |
480 bool allow = false; | 481 bool allow = false; |
481 bool result = it.value().GetAsBoolean(&allow); | 482 bool result = it.value().GetAsBoolean(&allow); |
482 DCHECK(result); | 483 DCHECK(result); |
483 (*url_map)[GURL(it.key())] = allow; | 484 (*url_map)[GURL(it.key())] = allow; |
484 } | 485 } |
485 url_filter_context_.SetManualURLs(url_map.Pass()); | 486 url_filter_context_.SetManualURLs(url_map.Pass()); |
486 } | 487 } |
OLD | NEW |