| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 17 | 16 |
| 18 class Profile; | 17 class Profile; |
| 19 | 18 |
| 20 namespace content { | 19 namespace content { |
| 21 class NotificationSource; | 20 class NotificationSource; |
| 22 class NotificationSource; | 21 class NotificationSource; |
| 23 } | 22 } |
| 24 | 23 |
| 25 namespace extensions { | 24 namespace extensions { |
| 26 class RulesRegistry; | 25 class RulesRegistry; |
| 27 } | 26 } |
| 28 | 27 |
| 29 namespace extensions { | 28 namespace extensions { |
| 30 | 29 |
| 31 // This class owns all RulesRegistries implementations of an ExtensionService. | 30 // This class owns all RulesRegistries implementations of an ExtensionService. |
| 31 // This class lives on the UI thread. |
| 32 class RulesRegistryService : public content::NotificationObserver { | 32 class RulesRegistryService : public content::NotificationObserver { |
| 33 public: | 33 public: |
| 34 explicit RulesRegistryService(Profile* profile); | 34 explicit RulesRegistryService(Profile* profile); |
| 35 virtual ~RulesRegistryService(); | 35 virtual ~RulesRegistryService(); |
| 36 | 36 |
| 37 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. | 37 // Registers a RulesRegistry and wraps it in an InitializingRulesRegistry. |
| 38 void RegisterRulesRegistry(const std::string& event_name, | 38 void RegisterRulesRegistry(const std::string& event_name, |
| 39 scoped_ptr<RulesRegistry> rule_registry); | 39 scoped_refptr<RulesRegistry> rule_registry); |
| 40 | 40 |
| 41 // Returns the RulesRegistry for |event_name| or NULL if no such registry | 41 // Returns the RulesRegistry for |event_name| or NULL if no such registry |
| 42 // has been registered. | 42 // has been registered. |
| 43 RulesRegistry* GetRulesRegistry(const std::string& event_name) const; | 43 scoped_refptr<RulesRegistry> GetRulesRegistry( |
| 44 const std::string& event_name) const; |
| 44 | 45 |
| 46 // For testing. |
| 47 void SimulateExtensionUnloaded(const std::string& extension_id); |
| 45 private: | 48 private: |
| 46 // Maps event names to RuleRegistries that handle these events. | 49 // Maps event names to RuleRegistries that handle these events. |
| 47 typedef std::map<std::string, linked_ptr<RulesRegistry> > RulesRegistryMap; | 50 typedef std::map<std::string, scoped_refptr<RulesRegistry> > RulesRegistryMap; |
| 48 | 51 |
| 49 // Notifies all RulesRegistries that |extension_id| was unloaded. | 52 // Notifies all RulesRegistries that |extension_id| was unloaded. |
| 53 // It is not guaranteed that this notification is processed synchronously. |
| 54 // If extensions live on another thread, the notification is posted. |
| 50 void OnExtensionUnloaded(const std::string& extension_id); | 55 void OnExtensionUnloaded(const std::string& extension_id); |
| 51 | 56 |
| 52 // Implementation of content::NotificationObserver. | 57 // Implementation of content::NotificationObserver. |
| 53 virtual void Observe(int type, | 58 virtual void Observe(int type, |
| 54 const content::NotificationSource& source, | 59 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) OVERRIDE; | 60 const content::NotificationDetails& details) OVERRIDE; |
| 56 | 61 |
| 57 RulesRegistryMap rule_registries_; | 62 RulesRegistryMap rule_registries_; |
| 58 | 63 |
| 59 content::NotificationRegistrar registrar_; | 64 content::NotificationRegistrar registrar_; |
| 60 | 65 |
| 61 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); | 66 DISALLOW_COPY_AND_ASSIGN(RulesRegistryService); |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 } // namespace extensions | 69 } // namespace extensions |
| 65 | 70 |
| 66 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ | 71 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_RULES_REGISTRY_SERVICE_H__ |
| OLD | NEW |