OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 PPAPI_PROXY_PLUGIN_DISPATCHER_H_ | 5 #ifndef PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
6 #define PPAPI_PROXY_PLUGIN_DISPATCHER_H_ | 6 #define PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // will be automatically called when requested by the renderer side. The | 34 // will be automatically called when requested by the renderer side. The |
35 // module ID will be set upon receipt of the InitializeModule message. | 35 // module ID will be set upon receipt of the InitializeModule message. |
36 // | 36 // |
37 // You must call Dispatcher::InitWithChannel after the constructor. | 37 // You must call Dispatcher::InitWithChannel after the constructor. |
38 PluginDispatcher(base::ProcessHandle remote_process_handle, | 38 PluginDispatcher(base::ProcessHandle remote_process_handle, |
39 GetInterfaceFunc get_interface, | 39 GetInterfaceFunc get_interface, |
40 InitModuleFunc init_module, | 40 InitModuleFunc init_module, |
41 ShutdownModuleFunc shutdown_module); | 41 ShutdownModuleFunc shutdown_module); |
42 ~PluginDispatcher(); | 42 ~PluginDispatcher(); |
43 | 43 |
44 // Sets/gets the global dispatcher pointer. New code should use the | |
45 // GetForInstance version below, this is currently here as a stopgap while | |
46 // the transition is being made. | |
47 // | |
48 // TODO(brettw) remove this. | |
49 static PluginDispatcher* Get(); | |
50 static void SetGlobal(PluginDispatcher* dispatcher); | |
51 | |
52 // The plugin side maintains a mapping from PP_Instance to Dispatcher so | 44 // The plugin side maintains a mapping from PP_Instance to Dispatcher so |
53 // that we can send the messages to the right channel if there are multiple | 45 // that we can send the messages to the right channel if there are multiple |
54 // renderers sharing the same plugin. | 46 // renderers sharing the same plugin. This mapping is maintained by |
| 47 // DidCreateInstance/DidDestroyInstance. |
55 static PluginDispatcher* GetForInstance(PP_Instance instance); | 48 static PluginDispatcher* GetForInstance(PP_Instance instance); |
56 /* TODO(brettw) enable this when Get() is removed. | |
57 static void SetForInstance(PP_Instance instance, | |
58 PluginDispatcher* dispatcher); | |
59 static void RemoveForInstance(PP_Instance instance); | |
60 */ | |
61 | 49 |
62 // Dispatcher overrides. | 50 // Dispatcher overrides. |
63 virtual bool IsPlugin() const; | 51 virtual bool IsPlugin() const; |
64 | 52 |
65 // IPC::Channel::Listener implementation. | 53 // IPC::Channel::Listener implementation. |
66 virtual bool OnMessageReceived(const IPC::Message& msg); | 54 virtual bool OnMessageReceived(const IPC::Message& msg); |
67 | 55 |
68 // Keep track of all active instances to associate data with it, like the | 56 // Keeps track of which dispatcher to use for each instance, active instances |
69 // current size. | 57 // and tracks associated data like the current size. |
70 void DidCreateInstance(PP_Instance instance); | 58 void DidCreateInstance(PP_Instance instance); |
71 void DidDestroyInstance(PP_Instance instance); | 59 void DidDestroyInstance(PP_Instance instance); |
72 | 60 |
73 // Gets the data for an existing instance, or NULL if the instance id doesn't | 61 // Gets the data for an existing instance, or NULL if the instance id doesn't |
74 // correspond to a known instance. | 62 // correspond to a known instance. |
75 InstanceData* GetInstanceData(PP_Instance instance); | 63 InstanceData* GetInstanceData(PP_Instance instance); |
76 | 64 |
77 private: | 65 private: |
| 66 friend class PluginDispatcherTest; |
| 67 |
78 // IPC message handlers. | 68 // IPC message handlers. |
79 void OnMsgInitializeModule(PP_Module pp_module, bool* result); | 69 void OnMsgInitializeModule(PP_Module pp_module, bool* result); |
80 void OnMsgShutdown(); | 70 void OnMsgShutdown(); |
| 71 void OnMsgSupportsInterface(const std::string& interface_name, bool* result); |
81 | 72 |
82 InitModuleFunc init_module_; | 73 InitModuleFunc init_module_; |
83 ShutdownModuleFunc shutdown_module_; | 74 ShutdownModuleFunc shutdown_module_; |
84 | 75 |
| 76 // All target proxies currently created. These are ones that receive |
| 77 // messages. |
| 78 scoped_ptr<InterfaceProxy> target_proxies_[INTERFACE_ID_COUNT]; |
| 79 |
85 typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; | 80 typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; |
86 InstanceDataMap instance_map_; | 81 InstanceDataMap instance_map_; |
87 | 82 |
88 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); | 83 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); |
89 }; | 84 }; |
90 | 85 |
91 } // namespace proxy | 86 } // namespace proxy |
92 } // namespace pp | 87 } // namespace pp |
93 | 88 |
94 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ | 89 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
OLD | NEW |