OLD | NEW |
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_with_cache.h" | 15 #include "chrome/browser/extensions/api/declarative/rules_registry.h" |
16 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | 16 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
20 | 20 |
21 class Profile; | 21 class Profile; |
22 | 22 |
23 namespace content { | 23 namespace content { |
24 class NotificationSource; | 24 class NotificationSource; |
25 class NotificationSource; | 25 class NotificationSource; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 ContentRulesRegistry* content_rules_registry() const { | 66 ContentRulesRegistry* content_rules_registry() const { |
67 return content_rules_registry_; | 67 return content_rules_registry_; |
68 } | 68 } |
69 | 69 |
70 // For testing. | 70 // For testing. |
71 void SimulateExtensionUnloaded(const std::string& extension_id); | 71 void SimulateExtensionUnloaded(const std::string& extension_id); |
72 private: | 72 private: |
73 friend class ProfileKeyedAPIFactory<RulesRegistryService>; | 73 friend class ProfileKeyedAPIFactory<RulesRegistryService>; |
74 | 74 |
75 // Maps event names to RuleRegistries that handle these events. | 75 // Maps event names to RuleRegistries that handle these events. |
76 typedef std::map<std::string, scoped_refptr<RulesRegistry> > RulesRegistryMap; | 76 typedef std::map<std::string, scoped_refptr<RulesRegistry> > |
| 77 RulesRegistryMap; |
77 | 78 |
78 // Notifies all RulesRegistries that |extension_id| was unloaded. | 79 // Notifies all RulesRegistries that |extension_id| was unloaded. |
79 // It is not guaranteed that this notification is processed synchronously. | 80 // It is not guaranteed that this notification is processed synchronously. |
80 // If extensions live on another thread, the notification is posted. | 81 // If extensions live on another thread, the notification is posted. |
81 void OnExtensionUnloaded(const std::string& extension_id); | 82 void OnExtensionUnloaded(const std::string& extension_id); |
82 | 83 |
83 // Implementation of content::NotificationObserver. | 84 // Implementation of content::NotificationObserver. |
84 virtual void Observe(int type, | 85 virtual void Observe(int type, |
85 const content::NotificationSource& source, | 86 const content::NotificationSource& source, |
86 const content::NotificationDetails& details) OVERRIDE; | 87 const content::NotificationDetails& details) OVERRIDE; |
87 | 88 |
88 // ProfileKeyedAPI implementation. | 89 // ProfileKeyedAPI implementation. |
89 static const char* service_name() { | 90 static const char* service_name() { |
90 return "RulesRegistryService"; | 91 return "RulesRegistryService"; |
91 } | 92 } |
92 static const bool kServiceHasOwnInstanceInIncognito = true; | 93 static const bool kServiceHasOwnInstanceInIncognito = true; |
93 static const bool kServiceIsNULLWhileTesting = true; | 94 static const bool kServiceIsNULLWhileTesting = true; |
94 | 95 |
95 RulesRegistryMap rule_registries_; | 96 RulesRegistryMap rule_registries_; |
96 | 97 |
97 // We own the parts of the registries which need to run on the UI thread. | 98 // We own the parts of the registries which need to run on the UI thread. |
98 ScopedVector<RulesRegistryWithCache::RuleStorageOnUI> ui_parts_of_registries_; | 99 ScopedVector<RulesCacheDelegate> ui_parts_of_registries_; |
99 | 100 |
100 // Weak pointer into rule_registries_ to make it easier to handle content rule | 101 // Weak pointer into rule_registries_ to make it easier to handle content rule |
101 // conditions. | 102 // conditions. |
102 ContentRulesRegistry* content_rules_registry_; | 103 ContentRulesRegistry* content_rules_registry_; |
103 | 104 |
104 content::NotificationRegistrar registrar_; | 105 content::NotificationRegistrar registrar_; |
105 | 106 |
106 Profile* profile_; | 107 Profile* profile_; |
107 | 108 |
108 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 109 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
109 }; | 110 }; |
110 | 111 |
111 } // namespace extensions | 112 } // namespace extensions |
112 | 113 |
113 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 114 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
OLD | NEW |