Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/extensions/api/settings_overrides/settings_overrides_api.h

Issue 2639153002: Make extensions DSE persistent in browser prefs (Reland) (Closed)
Patch Set: Rebased and updated after review, use new keyword conflicts resolution Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <memory>
8 #include <set> 9 #include <set>
9 #include <string> 10 #include <string>
10 11
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
13 #include "components/search_engines/template_url_service.h" 14 #include "components/search_engines/template_url_service.h"
14 #include "extensions/browser/browser_context_keyed_api_factory.h" 15 #include "extensions/browser/browser_context_keyed_api_factory.h"
15 #include "extensions/browser/extension_registry_observer.h" 16 #include "extensions/browser/extension_registry_observer.h"
16 17
17 class Profile; 18 class Profile;
18 19
19 namespace extensions { 20 namespace extensions {
20 class ExtensionRegistry; 21 class ExtensionRegistry;
21 22
22 class SettingsOverridesAPI : public BrowserContextKeyedAPI, 23 class SettingsOverridesAPI : public BrowserContextKeyedAPI,
23 public ExtensionRegistryObserver { 24 public ExtensionRegistryObserver {
24 public: 25 public:
25 explicit SettingsOverridesAPI(content::BrowserContext* context); 26 explicit SettingsOverridesAPI(content::BrowserContext* context);
26 ~SettingsOverridesAPI() override; 27 ~SettingsOverridesAPI() override;
27 28
28 // BrowserContextKeyedAPI implementation. 29 // BrowserContextKeyedAPI implementation.
29 static BrowserContextKeyedAPIFactory<SettingsOverridesAPI>* 30 static BrowserContextKeyedAPIFactory<SettingsOverridesAPI>*
30 GetFactoryInstance(); 31 GetFactoryInstance();
31 32
32 private: 33 private:
33 friend class BrowserContextKeyedAPIFactory<SettingsOverridesAPI>; 34 friend class BrowserContextKeyedAPIFactory<SettingsOverridesAPI>;
34 35
35 typedef std::set<scoped_refptr<const Extension> > PendingExtensions;
36
37 // Wrappers around PreferenceAPI. 36 // Wrappers around PreferenceAPI.
38 void SetPref(const std::string& extension_id, 37 void SetPref(const std::string& extension_id,
39 const std::string& pref_key, 38 const std::string& pref_key,
40 base::Value* value); 39 std::unique_ptr<base::Value> value) const;
41 void UnsetPref(const std::string& extension_id, 40 void UnsetPref(const std::string& extension_id,
42 const std::string& pref_key); 41 const std::string& pref_key) const;
43 42
44 // ExtensionRegistryObserver implementation. 43 // ExtensionRegistryObserver implementation.
45 void OnExtensionLoaded(content::BrowserContext* browser_context, 44 void OnExtensionLoaded(content::BrowserContext* browser_context,
46 const Extension* extension) override; 45 const Extension* extension) override;
47 void OnExtensionUnloaded(content::BrowserContext* browser_context, 46 void OnExtensionUnloaded(content::BrowserContext* browser_context,
48 const Extension* extension, 47 const Extension* extension,
49 UnloadedExtensionInfo::Reason reason) override; 48 UnloadedExtensionInfo::Reason reason) override;
50 49
51 // KeyedService implementation.
52 void Shutdown() override;
53
54 void OnTemplateURLsLoaded();
55
56 void RegisterSearchProvider(const Extension* extension) const; 50 void RegisterSearchProvider(const Extension* extension) const;
57 // BrowserContextKeyedAPI implementation. 51 // BrowserContextKeyedAPI implementation.
58 static const char* service_name() { return "SettingsOverridesAPI"; } 52 static const char* service_name() { return "SettingsOverridesAPI"; }
59 53
60 Profile* profile_; 54 Profile* profile_;
61 TemplateURLService* url_service_; 55 TemplateURLService* url_service_;
62 56
63 // List of extensions waiting for the TemplateURLService to Load to
64 // have search provider registered.
65 PendingExtensions pending_extensions_;
66
67 // Listen to extension load, unloaded notifications. 57 // Listen to extension load, unloaded notifications.
68 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 58 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
69 extension_registry_observer_; 59 extension_registry_observer_;
70 60
71 std::unique_ptr<TemplateURLService::Subscription> template_url_sub_;
72
73 DISALLOW_COPY_AND_ASSIGN(SettingsOverridesAPI); 61 DISALLOW_COPY_AND_ASSIGN(SettingsOverridesAPI);
74 }; 62 };
75 63
76 template <> 64 template <>
77 void BrowserContextKeyedAPIFactory< 65 void BrowserContextKeyedAPIFactory<
78 SettingsOverridesAPI>::DeclareFactoryDependencies(); 66 SettingsOverridesAPI>::DeclareFactoryDependencies();
79 67
80 } // namespace extensions 68 } // namespace extensions
81 69
82 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_A PI_H_ 70 #endif // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_A PI_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698