| 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/process.h" | 10 #include "base/process.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "ppapi/proxy/callback_tracker.h" | 12 #include "ppapi/c/pp_instance.h" |
| 13 #include "ppapi/proxy/dispatcher.h" | 13 #include "ppapi/proxy/dispatcher.h" |
| 14 #include "ppapi/proxy/plugin_resource_tracker.h" | |
| 15 #include "ppapi/proxy/plugin_var_tracker.h" | |
| 16 | 14 |
| 17 class MessageLoop; | 15 class MessageLoop; |
| 18 | 16 |
| 19 namespace base { | 17 namespace base { |
| 20 class WaitableEvent; | 18 class WaitableEvent; |
| 21 } | 19 } |
| 22 | 20 |
| 23 namespace pp { | 21 namespace pp { |
| 24 namespace proxy { | 22 namespace proxy { |
| 25 | 23 |
| 26 class PluginDispatcher : public Dispatcher { | 24 class PluginDispatcher : public Dispatcher { |
| 27 public: | 25 public: |
| 28 // Constructor for the plugin side. The init and shutdown functions will be | 26 // Constructor for the plugin side. The init and shutdown functions will be |
| 29 // will be automatically called when requested by the renderer side. The | 27 // will be automatically called when requested by the renderer side. The |
| 30 // module ID will be set upon receipt of the InitializeModule message. | 28 // module ID will be set upon receipt of the InitializeModule message. |
| 31 // | 29 // |
| 32 // You must call Dispatcher::InitWithChannel after the constructor. | 30 // You must call Dispatcher::InitWithChannel after the constructor. |
| 33 PluginDispatcher(base::ProcessHandle remote_process_handle, | 31 PluginDispatcher(base::ProcessHandle remote_process_handle, |
| 34 GetInterfaceFunc get_interface, | 32 GetInterfaceFunc get_interface, |
| 35 InitModuleFunc init_module, | 33 InitModuleFunc init_module, |
| 36 ShutdownModuleFunc shutdown_module); | 34 ShutdownModuleFunc shutdown_module); |
| 37 ~PluginDispatcher(); | 35 ~PluginDispatcher(); |
| 38 | 36 |
| 39 // The plugin maintains a global Dispatcher pointer. There is only one since | 37 // Sets/gets the global dispatcher pointer. New code should use the |
| 40 // there is only one connection to the browser. Don't call this on the | 38 // GetForInstance version below, this is currently here as a stopgap while |
| 41 // browser side, see GetForInstnace. | 39 // the transition is being made. |
| 40 // |
| 41 // TODO(brettw) remove this. |
| 42 static PluginDispatcher* Get(); | 42 static PluginDispatcher* Get(); |
| 43 static void SetGlobal(PluginDispatcher* dispatcher); | 43 static void SetGlobal(PluginDispatcher* dispatcher); |
| 44 | 44 |
| 45 // The plugin side maintains a mapping from PP_Instance to Dispatcher so |
| 46 // that we can send the messages to the right channel if there are multiple |
| 47 // renderers sharing the same plugin. |
| 48 static PluginDispatcher* GetForInstance(PP_Instance instance); |
| 49 /* TODO(brettw) enable this when Get() is removed. |
| 50 static void SetForInstance(PP_Instance instance, |
| 51 PluginDispatcher* dispatcher); |
| 52 static void RemoveForInstance(PP_Instance instance); |
| 53 */ |
| 54 |
| 45 // Dispatcher overrides. | 55 // Dispatcher overrides. |
| 46 virtual bool IsPlugin() const; | 56 virtual bool IsPlugin() const; |
| 47 | 57 |
| 48 // IPC::Channel::Listener implementation. | 58 // IPC::Channel::Listener implementation. |
| 49 virtual bool OnMessageReceived(const IPC::Message& msg); | 59 virtual bool OnMessageReceived(const IPC::Message& msg); |
| 50 | 60 |
| 51 // Returns the resource tracker for the plugin. In the browser process this | |
| 52 // will return NULL. | |
| 53 PluginResourceTracker* plugin_resource_tracker() { | |
| 54 return plugin_resource_tracker_.get(); | |
| 55 } | |
| 56 | |
| 57 // Returns the var tracker for the plugin. In the browser process this | |
| 58 // will return NULL. | |
| 59 PluginVarTracker* plugin_var_tracker() { | |
| 60 return plugin_var_tracker_.get(); | |
| 61 } | |
| 62 | |
| 63 private: | 61 private: |
| 64 // IPC message handlers. | 62 // IPC message handlers. |
| 65 void OnMsgInitializeModule(PP_Module pp_module, bool* result); | 63 void OnMsgInitializeModule(PP_Module pp_module, bool* result); |
| 66 void OnMsgShutdown(); | 64 void OnMsgShutdown(); |
| 67 | 65 |
| 68 InitModuleFunc init_module_; | 66 InitModuleFunc init_module_; |
| 69 ShutdownModuleFunc shutdown_module_; | 67 ShutdownModuleFunc shutdown_module_; |
| 70 | 68 |
| 71 scoped_ptr<PluginResourceTracker> plugin_resource_tracker_; | |
| 72 scoped_ptr<PluginVarTracker> plugin_var_tracker_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); | 69 DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); |
| 75 }; | 70 }; |
| 76 | 71 |
| 77 } // namespace proxy | 72 } // namespace proxy |
| 78 } // namespace pp | 73 } // namespace pp |
| 79 | 74 |
| 80 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ | 75 #endif // PPAPI_PROXY_PLUGIN_DISPATCHER_H_ |
| OLD | NEW |