OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/preference/preference_api.h" | 5 #include "chrome/browser/extensions/api/preference/preference_api.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
| 10 #include "base/lazy_instance.h" |
10 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" | 15 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" |
15 #include "chrome/browser/extensions/api/preference/preference_helpers.h" | 16 #include "chrome/browser/extensions/api/preference/preference_helpers.h" |
16 #include "chrome/browser/extensions/api/proxy/proxy_api.h" | 17 #include "chrome/browser/extensions/api/proxy/proxy_api.h" |
17 #include "chrome/browser/extensions/extension_prefs.h" | 18 #include "chrome/browser/extensions/extension_prefs.h" |
18 #include "chrome/browser/extensions/extension_prefs_scope.h" | 19 #include "chrome/browser/extensions/extension_prefs_scope.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 320 |
320 void PreferenceAPI::Shutdown() { | 321 void PreferenceAPI::Shutdown() { |
321 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 322 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
322 } | 323 } |
323 | 324 |
324 void PreferenceAPI::OnListenerAdded(const EventListenerInfo& details) { | 325 void PreferenceAPI::OnListenerAdded(const EventListenerInfo& details) { |
325 preference_event_router_.reset(new PreferenceEventRouter(profile_)); | 326 preference_event_router_.reset(new PreferenceEventRouter(profile_)); |
326 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 327 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
327 } | 328 } |
328 | 329 |
| 330 static base::LazyInstance<ProfileKeyedAPIFactory<PreferenceAPI> > |
| 331 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 332 |
| 333 template <> |
| 334 ProfileKeyedAPIFactory<PreferenceAPI>* |
| 335 ProfileKeyedAPIFactory<PreferenceAPI>::GetInstance() { |
| 336 return &g_factory.Get(); |
| 337 } |
| 338 |
329 PreferenceFunction::~PreferenceFunction() { } | 339 PreferenceFunction::~PreferenceFunction() { } |
330 | 340 |
331 bool PreferenceFunction::ValidateBrowserPref( | 341 bool PreferenceFunction::ValidateBrowserPref( |
332 const std::string& extension_pref_key, | 342 const std::string& extension_pref_key, |
333 std::string* browser_pref_key) { | 343 std::string* browser_pref_key) { |
334 APIPermission::ID permission = APIPermission::kInvalid; | 344 APIPermission::ID permission = APIPermission::kInvalid; |
335 EXTENSION_FUNCTION_VALIDATE( | 345 EXTENSION_FUNCTION_VALIDATE( |
336 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( | 346 PrefMapping::GetInstance()->FindBrowserPrefForExtensionPref( |
337 extension_pref_key, browser_pref_key, &permission)); | 347 extension_pref_key, browser_pref_key, &permission)); |
338 if (!GetExtension()->HasAPIPermission(permission)) { | 348 if (!GetExtension()->HasAPIPermission(permission)) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 if (!ValidateBrowserPref(pref_key, &browser_pref)) | 539 if (!ValidateBrowserPref(pref_key, &browser_pref)) |
530 return false; | 540 return false; |
531 | 541 |
532 ExtensionPrefs* prefs = | 542 ExtensionPrefs* prefs = |
533 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); | 543 ExtensionSystem::Get(profile_)->extension_service()->extension_prefs(); |
534 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); | 544 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); |
535 return true; | 545 return true; |
536 } | 546 } |
537 | 547 |
538 } // namespace extensions | 548 } // namespace extensions |
OLD | NEW |