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

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

Issue 13825014: Change RulesRegistryService to use ProfileKeyedAPI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Convenience method and fixed line wrapping Created 7 years, 8 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 (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/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h" 15 #include "content/public/browser/notification_registrar.h"
15 16
16 class Profile; 17 class Profile;
17 18
18 namespace content { 19 namespace content {
19 class NotificationSource; 20 class NotificationSource;
20 class NotificationSource; 21 class NotificationSource;
21 } 22 }
22 23
23 namespace extensions { 24 namespace extensions {
24 class ContentRulesRegistry; 25 class ContentRulesRegistry;
25 class RulesRegistry; 26 class RulesRegistry;
26 class RulesRegistryStorageDelegate; 27 class RulesRegistryStorageDelegate;
27 } 28 }
28 29
29 namespace extensions { 30 namespace extensions {
30 31
31 // This class owns all RulesRegistries implementations of an ExtensionService. 32 // This class owns all RulesRegistries implementations of an ExtensionService.
32 // This class lives on the UI thread. 33 // This class lives on the UI thread.
33 class RulesRegistryService : public content::NotificationObserver { 34 class RulesRegistryService : public ProfileKeyedAPI,
35 public content::NotificationObserver {
34 public: 36 public:
35 explicit RulesRegistryService(Profile* profile); 37 explicit RulesRegistryService(Profile* profile);
36 virtual ~RulesRegistryService(); 38 virtual ~RulesRegistryService();
37 39
38 // Unregisters refptrs to concrete RulesRegistries at other objects that were 40 // Unregisters refptrs to concrete RulesRegistries at other objects that were
39 // created by us so that the RulesRegistries can be released. 41 // created by us so that the RulesRegistries can be released.
40 void Shutdown(); 42 void Shutdown();
41 43
44 // ProfileKeyedAPI implementation.
45 static ProfileKeyedAPIFactory<RulesRegistryService>* GetFactoryInstance();
46
47 // Convenience method to get the RulesRegistryService for a profile.
48 static RulesRegistryService* Get(Profile* profile);
49
42 // Registers the default RulesRegistries used in Chromium. 50 // Registers the default RulesRegistries used in Chromium.
43 void RegisterDefaultRulesRegistries(); 51 void RegisterDefaultRulesRegistries();
44 52
45 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. 53 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry.
46 void RegisterRulesRegistry(const std::string& event_name, 54 void RegisterRulesRegistry(const std::string& event_name,
47 scoped_refptr<RulesRegistry> rule_registry); 55 scoped_refptr<RulesRegistry> rule_registry);
48 56
49 // Returns the RulesRegistry for |event_name| or NULL if no such registry 57 // Returns the RulesRegistry for |event_name| or NULL if no such registry
50 // has been registered. 58 // has been registered.
51 scoped_refptr<RulesRegistry> GetRulesRegistry( 59 scoped_refptr<RulesRegistry> GetRulesRegistry(
52 const std::string& event_name) const; 60 const std::string& event_name) const;
53 61
54 // Accessors for each type of rules registry. 62 // Accessors for each type of rules registry.
55 ContentRulesRegistry* content_rules_registry() const { 63 ContentRulesRegistry* content_rules_registry() const {
56 return content_rules_registry_; 64 return content_rules_registry_;
57 } 65 }
58 66
59 // For testing. 67 // For testing.
60 void SimulateExtensionUnloaded(const std::string& extension_id); 68 void SimulateExtensionUnloaded(const std::string& extension_id);
61 private: 69 private:
70 friend class ProfileKeyedAPIFactory<RulesRegistryService>;
71
62 // Maps event names to RuleRegistries that handle these events. 72 // Maps event names to RuleRegistries that handle these events.
63 typedef std::map<std::string, scoped_refptr<RulesRegistry> > RulesRegistryMap; 73 typedef std::map<std::string, scoped_refptr<RulesRegistry> > RulesRegistryMap;
64 74
65 // Notifies all RulesRegistries that |extension_id| was unloaded. 75 // Notifies all RulesRegistries that |extension_id| was unloaded.
66 // It is not guaranteed that this notification is processed synchronously. 76 // It is not guaranteed that this notification is processed synchronously.
67 // If extensions live on another thread, the notification is posted. 77 // If extensions live on another thread, the notification is posted.
68 void OnExtensionUnloaded(const std::string& extension_id); 78 void OnExtensionUnloaded(const std::string& extension_id);
69 79
70 // Implementation of content::NotificationObserver. 80 // Implementation of content::NotificationObserver.
71 virtual void Observe(int type, 81 virtual void Observe(int type,
72 const content::NotificationSource& source, 82 const content::NotificationSource& source,
73 const content::NotificationDetails& details) OVERRIDE; 83 const content::NotificationDetails& details) OVERRIDE;
74 84
85 // ProfileKeyedAPI implementation.
86 static const char* service_name() {
87 return "RulesRegistryService";
88 }
89
75 RulesRegistryMap rule_registries_; 90 RulesRegistryMap rule_registries_;
76 91
77 // These are weak pointers to the delegates owned by the RulesRegistry's. We 92 // These are weak pointers to the delegates owned by the RulesRegistry's. We
78 // keep track of them so we can tell them to do cleanup on shutdown. 93 // keep track of them so we can tell them to do cleanup on shutdown.
79 std::vector<RulesRegistryStorageDelegate*> delegates_; 94 std::vector<RulesRegistryStorageDelegate*> delegates_;
80 95
81 // Weak pointer into rule_registries_ to make it easier to handle content rule 96 // Weak pointer into rule_registries_ to make it easier to handle content rule
82 // conditions. 97 // conditions.
83 ContentRulesRegistry* content_rules_registry_; 98 ContentRulesRegistry* content_rules_registry_;
84 99
85 content::NotificationRegistrar registrar_; 100 content::NotificationRegistrar registrar_;
86 101
87 Profile* profile_; 102 Profile* profile_;
88 103
89 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); 104 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService);
90 }; 105 };
91 106
92 } // namespace extensions 107 } // namespace extensions
93 108
94 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ 109 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698