OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILE_SYSTEM_PLUGIN_PLUGINEV
ENTROUTER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILE_SYSTEM_PLUGIN_PLUGINEV
ENTROUTER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <set> |
| 10 #include <string> |
| 11 |
| 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" |
| 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/values.h" |
| 17 |
| 18 #include "ppapi/host/resource_host.h" |
| 19 |
| 20 template <typename T> |
| 21 struct DefaultSingletonTraits; |
| 22 |
| 23 namespace extensions { |
| 24 struct Event; |
| 25 } // namespace extensions |
| 26 |
| 27 namespace chromeos { |
| 28 |
| 29 class EventToPluginList; |
| 30 class PluginListeningInstances; |
| 31 |
| 32 class PluginEventRouter { |
| 33 public: |
| 34 class PluginEventRouterClient { |
| 35 virtual void OnDispatchEvent(std::string event_name, |
| 36 scoped_ptr<base::ListValue> event_args) {} |
| 37 friend class PluginListeningInstances; |
| 38 }; |
| 39 |
| 40 static PluginEventRouter* GetInstance(); |
| 41 // Register and array of events for a plugin |
| 42 void AddEventsListener(const std::vector<std::string>& event_names, |
| 43 PluginEventRouterClient* plugin_ref, |
| 44 const std::string& plugin_id); |
| 45 // Register a single event for the plugin |
| 46 void AddEventListener(const std::string& event_name, |
| 47 PluginEventRouterClient* plugin_ref, |
| 48 const std::string& plugin_id); |
| 49 // Remove an array of events at a time |
| 50 void RemoveEventsListeners(const std::vector<std::string>& event_names, |
| 51 PluginEventRouterClient* plugin_ref, |
| 52 const std::string& plugin_id); |
| 53 // Remove a single event |
| 54 void RemoveEventListener(const std::string& event_name, |
| 55 PluginEventRouterClient* plugin_process, |
| 56 const std::string& plugin_id); |
| 57 |
| 58 // Does the router have any listener on this event |
| 59 bool HasEventListener(const std::string& event_name); |
| 60 |
| 61 // Does a specific plugin have the event registered |
| 62 bool PluginHasEventListener(const std::string& event_name, |
| 63 const std::string& plugin_id); |
| 64 void DispatchEventToPlugin(const std::string& plugin_id, |
| 65 scoped_ptr<extensions::Event> event); |
| 66 |
| 67 private: |
| 68 PluginEventRouter(); |
| 69 ~PluginEventRouter(); |
| 70 friend struct DefaultSingletonTraits<PluginEventRouter>; |
| 71 |
| 72 // [event_name] = map[plugin1, plugin2] |
| 73 typedef std::map<std::string, EventToPluginList> EventList; |
| 74 typedef EventList::iterator EventListIterator; |
| 75 EventList listOfListenedEvents_; |
| 76 |
| 77 base::WeakPtrFactory<PluginEventRouter> weak_ptr_factory_; |
| 78 DISALLOW_COPY_AND_ASSIGN(PluginEventRouter); |
| 79 }; |
| 80 |
| 81 class PluginListeningInstances { |
| 82 public: |
| 83 PluginListeningInstances( |
| 84 const std::string& plugin_id, |
| 85 PluginEventRouter::PluginEventRouterClient* instance_); |
| 86 ~PluginListeningInstances(); |
| 87 |
| 88 void AddPluginInstance(PluginEventRouter::PluginEventRouterClient* instance); |
| 89 void RemovePluginInstance( |
| 90 PluginEventRouter::PluginEventRouterClient* instance); |
| 91 bool Empty(); |
| 92 void DispatchEvent(std::string event_name, |
| 93 scoped_ptr<base::ListValue> event_args); |
| 94 |
| 95 protected: |
| 96 std::string plugin_id_; |
| 97 typedef std::set<PluginEventRouter::PluginEventRouterClient*> SetOfInstances; |
| 98 typedef SetOfInstances::iterator SetOfInstancesIterator; |
| 99 SetOfInstances plugin_instances_; |
| 100 }; |
| 101 |
| 102 class EventToPluginList { |
| 103 public: |
| 104 EventToPluginList(const std::string& event_name, |
| 105 const std::string& plugin_id, |
| 106 PluginEventRouter::PluginEventRouterClient* instance); |
| 107 ~EventToPluginList(); |
| 108 |
| 109 void AddPluginInstance(const std::string& plugin_id, |
| 110 PluginEventRouter::PluginEventRouterClient* instance); |
| 111 void RemovePluginInstance( |
| 112 const std::string& plugin_id, |
| 113 PluginEventRouter::PluginEventRouterClient* instance); |
| 114 bool Empty(); |
| 115 |
| 116 bool HasPlugin(const std::string& plugin_id); |
| 117 |
| 118 void DispatchEventToPlugin(std::string plugin_id, |
| 119 std::string event_name, |
| 120 scoped_ptr<base::ListValue> event_args); |
| 121 |
| 122 protected: |
| 123 std::string event_name_; |
| 124 // [plugin_id] = set[ instance_1, instance_2 ] |
| 125 typedef std::map<std::string, PluginListeningInstances> ListOfPlugins; |
| 126 typedef ListOfPlugins::iterator PluginListIterator; |
| 127 ListOfPlugins plugin_list_; |
| 128 }; |
| 129 |
| 130 } // namespace chromeos |
| 131 |
| 132 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILE_SYSTEM_PLUGIN_PLUGI
NEVENTROUTER_H_ |
OLD | NEW |