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

Side by Side Diff: chrome/browser/extensions/api/declarative/rules_registry_service.h

Issue 178193030: Rename ProfileKeyedAPI to BrowserContextKeyedAPI and GetProfile to Get. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 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 | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "chrome/browser/extensions/api/declarative/rules_registry.h" 15 #include "chrome/browser/extensions/api/declarative/rules_registry.h"
16 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_registrar.h"
19 #include "extensions/browser/browser_context_keyed_api_factory.h"
20 20
21 class Profile; 21 class Profile;
22 22
23 namespace content { 23 namespace content {
24 class BrowserContext; 24 class BrowserContext;
25 class NotificationSource; 25 class NotificationSource;
26 } 26 }
27 27
28 namespace extensions { 28 namespace extensions {
29 class ContentRulesRegistry; 29 class ContentRulesRegistry;
30 class RulesRegistry; 30 class RulesRegistry;
31 class RulesRegistryStorageDelegate; 31 class RulesRegistryStorageDelegate;
32 } 32 }
33 33
34 namespace extensions { 34 namespace extensions {
35 35
36 // This class owns all RulesRegistries implementations of an ExtensionService. 36 // This class owns all RulesRegistries implementations of an ExtensionService.
37 // This class lives on the UI thread. 37 // This class lives on the UI thread.
38 class RulesRegistryService : public ProfileKeyedAPI, 38 class RulesRegistryService : public BrowserContextKeyedAPI,
39 public content::NotificationObserver { 39 public content::NotificationObserver {
40 public: 40 public:
41 typedef RulesRegistry::WebViewKey WebViewKey; 41 typedef RulesRegistry::WebViewKey WebViewKey;
42 struct RulesRegistryKey { 42 struct RulesRegistryKey {
43 std::string event_name; 43 std::string event_name;
44 WebViewKey webview_key; 44 WebViewKey webview_key;
45 RulesRegistryKey(const std::string event_name, 45 RulesRegistryKey(const std::string event_name,
46 const WebViewKey& webview_key) 46 const WebViewKey& webview_key)
47 : event_name(event_name), 47 : event_name(event_name),
48 webview_key(webview_key) {} 48 webview_key(webview_key) {}
49 bool operator<(const RulesRegistryKey& other) const { 49 bool operator<(const RulesRegistryKey& other) const {
50 return (event_name < other.event_name) || 50 return (event_name < other.event_name) ||
51 ((event_name == other.event_name) && 51 ((event_name == other.event_name) &&
52 (webview_key < other.webview_key)); 52 (webview_key < other.webview_key));
53 } 53 }
54 }; 54 };
55 55
56 explicit RulesRegistryService(content::BrowserContext* context); 56 explicit RulesRegistryService(content::BrowserContext* context);
57 virtual ~RulesRegistryService(); 57 virtual ~RulesRegistryService();
58 58
59 // Unregisters refptrs to concrete RulesRegistries at other objects that were 59 // Unregisters refptrs to concrete RulesRegistries at other objects that were
60 // created by us so that the RulesRegistries can be released. 60 // created by us so that the RulesRegistries can be released.
61 virtual void Shutdown() OVERRIDE; 61 virtual void Shutdown() OVERRIDE;
62 62
63 // ProfileKeyedAPI implementation. 63 // BrowserContextKeyedAPI implementation.
64 static ProfileKeyedAPIFactory<RulesRegistryService>* GetFactoryInstance(); 64 static BrowserContextKeyedAPIFactory<RulesRegistryService>*
65 GetFactoryInstance();
65 66
66 // Convenience method to get the RulesRegistryService for a profile. 67 // Convenience method to get the RulesRegistryService for a profile.
67 static RulesRegistryService* Get(content::BrowserContext* context); 68 static RulesRegistryService* Get(content::BrowserContext* context);
68 69
69 // Registers the default RulesRegistries used in Chromium. 70 // Registers the default RulesRegistries used in Chromium.
70 void EnsureDefaultRulesRegistriesRegistered(const WebViewKey& webview_key); 71 void EnsureDefaultRulesRegistriesRegistered(const WebViewKey& webview_key);
71 72
72 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. 73 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry.
73 void RegisterRulesRegistry(scoped_refptr<RulesRegistry> rule_registry); 74 void RegisterRulesRegistry(scoped_refptr<RulesRegistry> rule_registry);
74 75
(...skipping 10 matching lines...) Expand all
85 return content_rules_registry_; 86 return content_rules_registry_;
86 } 87 }
87 88
88 // Removes all rules registries of a given webview embedder process ID. 89 // Removes all rules registries of a given webview embedder process ID.
89 void RemoveWebViewRulesRegistries(int process_id); 90 void RemoveWebViewRulesRegistries(int process_id);
90 91
91 // For testing. 92 // For testing.
92 void SimulateExtensionUninstalled(const std::string& extension_id); 93 void SimulateExtensionUninstalled(const std::string& extension_id);
93 94
94 private: 95 private:
95 friend class ProfileKeyedAPIFactory<RulesRegistryService>; 96 friend class BrowserContextKeyedAPIFactory<RulesRegistryService>;
96 97
97 // Maps <event name, webview key> to RuleRegistries that handle these 98 // Maps <event name, webview key> to RuleRegistries that handle these
98 // events. 99 // events.
99 typedef std::map<RulesRegistryKey, scoped_refptr<RulesRegistry> > 100 typedef std::map<RulesRegistryKey, scoped_refptr<RulesRegistry> >
100 RulesRegistryMap; 101 RulesRegistryMap;
101 102
102 // Implementation of content::NotificationObserver. 103 // Implementation of content::NotificationObserver.
103 virtual void Observe(int type, 104 virtual void Observe(int type,
104 const content::NotificationSource& source, 105 const content::NotificationSource& source,
105 const content::NotificationDetails& details) OVERRIDE; 106 const content::NotificationDetails& details) OVERRIDE;
106 107
107 // Iterates over all registries, and calls |notification_callback| on them 108 // Iterates over all registries, and calls |notification_callback| on them
108 // with |extension_id| as the argument. If a registry lives on a different 109 // with |extension_id| as the argument. If a registry lives on a different
109 // thread, the call is posted to that thread, so no guarantee of synchronous 110 // thread, the call is posted to that thread, so no guarantee of synchronous
110 // processing. 111 // processing.
111 void NotifyRegistriesHelper( 112 void NotifyRegistriesHelper(
112 void (RulesRegistry::*notification_callback)(const std::string&), 113 void (RulesRegistry::*notification_callback)(const std::string&),
113 const std::string& extension_id); 114 const std::string& extension_id);
114 115
115 // ProfileKeyedAPI implementation. 116 // BrowserContextKeyedAPI implementation.
116 static const char* service_name() { 117 static const char* service_name() {
117 return "RulesRegistryService"; 118 return "RulesRegistryService";
118 } 119 }
119 static const bool kServiceHasOwnInstanceInIncognito = true; 120 static const bool kServiceHasOwnInstanceInIncognito = true;
120 static const bool kServiceIsNULLWhileTesting = true; 121 static const bool kServiceIsNULLWhileTesting = true;
121 122
122 RulesRegistryMap rule_registries_; 123 RulesRegistryMap rule_registries_;
123 124
124 // We own the parts of the registries which need to run on the UI thread. 125 // We own the parts of the registries which need to run on the UI thread.
125 ScopedVector<RulesCacheDelegate> cache_delegates_; 126 ScopedVector<RulesCacheDelegate> cache_delegates_;
126 127
127 // Weak pointer into rule_registries_ to make it easier to handle content rule 128 // Weak pointer into rule_registries_ to make it easier to handle content rule
128 // conditions. 129 // conditions.
129 ContentRulesRegistry* content_rules_registry_; 130 ContentRulesRegistry* content_rules_registry_;
130 131
131 content::NotificationRegistrar registrar_; 132 content::NotificationRegistrar registrar_;
132 133
133 Profile* profile_; 134 Profile* profile_;
134 135
135 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); 136 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService);
136 }; 137 };
137 138
138 } // namespace extensions 139 } // namespace extensions
139 140
140 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ 141 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698