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

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: Took out rules_registry() from TestExtensionSystem Created 7 years, 7 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
42 // Registers the default RulesRegistries used in Chromium. 47 // Registers the default RulesRegistries used in Chromium.
43 void RegisterDefaultRulesRegistries(); 48 void RegisterDefaultRulesRegistries();
44 49
45 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. 50 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry.
46 void RegisterRulesRegistry(const std::string& event_name, 51 void RegisterRulesRegistry(const std::string& event_name,
47 scoped_refptr<RulesRegistry> rule_registry); 52 scoped_refptr<RulesRegistry> rule_registry);
48 53
49 // Returns the RulesRegistry for |event_name| or NULL if no such registry 54 // Returns the RulesRegistry for |event_name| or NULL if no such registry
50 // has been registered. 55 // has been registered.
51 scoped_refptr<RulesRegistry> GetRulesRegistry( 56 scoped_refptr<RulesRegistry> GetRulesRegistry(
52 const std::string& event_name) const; 57 const std::string& event_name) const;
53 58
54 // Accessors for each type of rules registry. 59 // Accessors for each type of rules registry.
55 ContentRulesRegistry* content_rules_registry() const { 60 ContentRulesRegistry* content_rules_registry() const {
56 return content_rules_registry_; 61 return content_rules_registry_;
57 } 62 }
58 63
59 // For testing. 64 // For testing.
60 void SimulateExtensionUnloaded(const std::string& extension_id); 65 void SimulateExtensionUnloaded(const std::string& extension_id);
61 private: 66 private:
67 friend class ProfileKeyedAPIFactory<RulesRegistryService>;
68
62 // Maps event names to RuleRegistries that handle these events. 69 // Maps event names to RuleRegistries that handle these events.
63 typedef std::map<std::string, scoped_refptr<RulesRegistry> > RulesRegistryMap; 70 typedef std::map<std::string, scoped_refptr<RulesRegistry> > RulesRegistryMap;
64 71
65 // Notifies all RulesRegistries that |extension_id| was unloaded. 72 // Notifies all RulesRegistries that |extension_id| was unloaded.
66 // It is not guaranteed that this notification is processed synchronously. 73 // It is not guaranteed that this notification is processed synchronously.
67 // If extensions live on another thread, the notification is posted. 74 // If extensions live on another thread, the notification is posted.
68 void OnExtensionUnloaded(const std::string& extension_id); 75 void OnExtensionUnloaded(const std::string& extension_id);
69 76
70 // Implementation of content::NotificationObserver. 77 // Implementation of content::NotificationObserver.
71 virtual void Observe(int type, 78 virtual void Observe(int type,
72 const content::NotificationSource& source, 79 const content::NotificationSource& source,
73 const content::NotificationDetails& details) OVERRIDE; 80 const content::NotificationDetails& details) OVERRIDE;
74 81
82 // ProfileKeyedAPI implementation.
83 static const char* service_name() {
84 return "RulesRegistryService";
85 }
86
75 RulesRegistryMap rule_registries_; 87 RulesRegistryMap rule_registries_;
76 88
77 // These are weak pointers to the delegates owned by the RulesRegistry's. We 89 // 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. 90 // keep track of them so we can tell them to do cleanup on shutdown.
79 std::vector<RulesRegistryStorageDelegate*> delegates_; 91 std::vector<RulesRegistryStorageDelegate*> delegates_;
80 92
81 // Weak pointer into rule_registries_ to make it easier to handle content rule 93 // Weak pointer into rule_registries_ to make it easier to handle content rule
82 // conditions. 94 // conditions.
83 ContentRulesRegistry* content_rules_registry_; 95 ContentRulesRegistry* content_rules_registry_;
84 96
85 content::NotificationRegistrar registrar_; 97 content::NotificationRegistrar registrar_;
86 98
87 Profile* profile_; 99 Profile* profile_;
88 100
89 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); 101 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService);
90 }; 102 };
91 103
92 } // namespace extensions 104 } // namespace extensions
93 105
94 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ 106 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698