OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_
H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_
H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_
H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_
H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/scoped_observer.h" |
12 #include "chrome/browser/search_engines/template_url_service.h" | 12 #include "chrome/browser/search_engines/template_url_service.h" |
13 #include "content/public/browser/notification_observer.h" | |
14 #include "content/public/browser/notification_registrar.h" | |
15 #include "extensions/browser/browser_context_keyed_api_factory.h" | 13 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 14 #include "extensions/browser/extension_registry_observer.h" |
16 | 15 |
17 class TemplateURL; | 16 class TemplateURL; |
18 | 17 |
19 namespace extensions { | 18 namespace extensions { |
| 19 class ExtensionRegistry; |
20 | 20 |
21 class SettingsOverridesAPI : public BrowserContextKeyedAPI, | 21 class SettingsOverridesAPI : public BrowserContextKeyedAPI, |
22 public content::NotificationObserver { | 22 public ExtensionRegistryObserver { |
23 public: | 23 public: |
24 explicit SettingsOverridesAPI(content::BrowserContext* context); | 24 explicit SettingsOverridesAPI(content::BrowserContext* context); |
25 virtual ~SettingsOverridesAPI(); | 25 virtual ~SettingsOverridesAPI(); |
26 | 26 |
27 // BrowserContextKeyedAPI implementation. | 27 // BrowserContextKeyedAPI implementation. |
28 static BrowserContextKeyedAPIFactory<SettingsOverridesAPI>* | 28 static BrowserContextKeyedAPIFactory<SettingsOverridesAPI>* |
29 GetFactoryInstance(); | 29 GetFactoryInstance(); |
30 | 30 |
31 private: | 31 private: |
32 friend class BrowserContextKeyedAPIFactory<SettingsOverridesAPI>; | 32 friend class BrowserContextKeyedAPIFactory<SettingsOverridesAPI>; |
33 | 33 |
34 typedef std::set<scoped_refptr<const Extension> > PendingExtensions; | 34 typedef std::set<scoped_refptr<const Extension> > PendingExtensions; |
35 | 35 |
36 // Wrappers around PreferenceAPI. | 36 // Wrappers around PreferenceAPI. |
37 void SetPref(const std::string& extension_id, | 37 void SetPref(const std::string& extension_id, |
38 const std::string& pref_key, | 38 const std::string& pref_key, |
39 base::Value* value); | 39 base::Value* value); |
40 void UnsetPref(const std::string& extension_id, | 40 void UnsetPref(const std::string& extension_id, |
41 const std::string& pref_key); | 41 const std::string& pref_key); |
42 // content::NotificationObserver implementation. | 42 |
43 virtual void Observe(int type, | 43 // ExtensionRegistryObserver implementation. |
44 const content::NotificationSource& source, | 44 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
45 const content::NotificationDetails& details) OVERRIDE; | 45 const Extension* extension) OVERRIDE; |
| 46 virtual void OnExtensionUnloaded( |
| 47 content::BrowserContext* browser_context, |
| 48 const Extension* extension, |
| 49 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 50 |
46 // KeyedService implementation. | 51 // KeyedService implementation. |
47 virtual void Shutdown() OVERRIDE; | 52 virtual void Shutdown() OVERRIDE; |
48 | 53 |
49 void OnTemplateURLsLoaded(); | 54 void OnTemplateURLsLoaded(); |
50 | 55 |
51 void RegisterSearchProvider(const Extension* extension) const; | 56 void RegisterSearchProvider(const Extension* extension) const; |
52 // BrowserContextKeyedAPI implementation. | 57 // BrowserContextKeyedAPI implementation. |
53 static const char* service_name() { return "SettingsOverridesAPI"; } | 58 static const char* service_name() { return "SettingsOverridesAPI"; } |
54 | 59 |
55 Profile* profile_; | 60 Profile* profile_; |
56 TemplateURLService* url_service_; | 61 TemplateURLService* url_service_; |
57 | 62 |
58 // List of extensions waiting for the TemplateURLService to Load to | 63 // List of extensions waiting for the TemplateURLService to Load to |
59 // have search provider registered. | 64 // have search provider registered. |
60 PendingExtensions pending_extensions_; | 65 PendingExtensions pending_extensions_; |
61 | 66 |
62 content::NotificationRegistrar registrar_; | 67 // Listen to extension load, unloaded notifications. |
| 68 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 69 extension_registry_observer_; |
| 70 |
63 scoped_ptr<TemplateURLService::Subscription> template_url_sub_; | 71 scoped_ptr<TemplateURLService::Subscription> template_url_sub_; |
64 | 72 |
65 DISALLOW_COPY_AND_ASSIGN(SettingsOverridesAPI); | 73 DISALLOW_COPY_AND_ASSIGN(SettingsOverridesAPI); |
66 }; | 74 }; |
67 | 75 |
68 template <> | 76 template <> |
69 void BrowserContextKeyedAPIFactory< | 77 void BrowserContextKeyedAPIFactory< |
70 SettingsOverridesAPI>::DeclareFactoryDependencies(); | 78 SettingsOverridesAPI>::DeclareFactoryDependencies(); |
71 | 79 |
72 } // namespace extensions | 80 } // namespace extensions |
73 | 81 |
74 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_A
PI_H_ | 82 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_A
PI_H_ |
OLD | NEW |