| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_RENDERER_DEVTOOLS_AGENT_FILTER_H_ | 5 #ifndef CHROME_RENDERER_DEVTOOLS_AGENT_FILTER_H_ |
| 6 #define CHROME_RENDERER_DEVTOOLS_AGENT_FILTER_H_ | 6 #define CHROME_RENDERER_DEVTOOLS_AGENT_FILTER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "ipc/ipc_channel_proxy.h" | 11 #include "ipc/ipc_channel_proxy.h" |
| 12 | 12 |
| 13 // DevToolsAgentFilter is registered as an IPC filter in order to be able to | 13 // DevToolsAgentFilter is registered as an IPC filter in order to be able to |
| 14 // dispatch messages while on the IO thread. The reason for that is that while | 14 // dispatch messages while on the IO thread. The reason for that is that while |
| 15 // debugging, Render thread is being held by the v8 and hence no messages | 15 // debugging, Render thread is being held by the v8 and hence no messages |
| 16 // are being dispatched there. While holding the thread in a tight loop, | 16 // are being dispatched there. While holding the thread in a tight loop, |
| 17 // v8 provides thread-safe Api for controlling debugger. In our case v8's Api | 17 // v8 provides thread-safe Api for controlling debugger. In our case v8's Api |
| 18 // is being used from this communication agent on the IO thread. | 18 // is being used from this communication agent on the IO thread. |
| 19 class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { | 19 class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { |
| 20 public: | 20 public: |
| 21 // There is a single instance of this class instantiated by the RenderThread. | 21 // There is a single instance of this class instantiated by the RenderThread. |
| 22 DevToolsAgentFilter(); | 22 DevToolsAgentFilter(); |
| 23 virtual ~DevToolsAgentFilter(); | 23 virtual ~DevToolsAgentFilter(); |
| 24 | 24 |
| 25 static void SendRpcMessage(const std::string& class_name, | |
| 26 const std::string& method_name, | |
| 27 const std::string& param1, | |
| 28 const std::string& param2, | |
| 29 const std::string& param3); | |
| 30 | |
| 31 private: | 25 private: |
| 32 // IPC::ChannelProxy::MessageFilter override. Called on IO thread. | 26 // IPC::ChannelProxy::MessageFilter override. Called on IO thread. |
| 33 virtual bool OnMessageReceived(const IPC::Message& message); | 27 virtual bool OnMessageReceived(const IPC::Message& message); |
| 34 | 28 |
| 35 virtual void OnFilterAdded(IPC::Channel* channel) { channel_ = channel; } | |
| 36 | |
| 37 static void DispatchMessageLoop(); | 29 static void DispatchMessageLoop(); |
| 38 | 30 |
| 39 // OnDebuggerCommand will be executed in the IO thread so that we can | 31 // OnDebuggerCommand will be executed in the IO thread so that we can |
| 40 // handle debug messages even when v8 is stopped. | 32 // handle debug messages even when v8 is stopped. |
| 41 void OnDebuggerCommand(const std::string& command); | 33 void OnDebuggerCommand(const std::string& command); |
| 42 void OnDebuggerPauseScript(); | 34 void OnDebuggerPauseScript(); |
| 43 void OnRpcMessage(const std::string& class_name, | |
| 44 const std::string& method_name, | |
| 45 const std::string& param1, | |
| 46 const std::string& param2, | |
| 47 const std::string& param3); | |
| 48 | 35 |
| 49 bool message_handled_; | 36 int current_routing_id_; |
| 50 | |
| 51 // Made static to allow DevToolsAgent to use it for replying directly | |
| 52 // from IO thread. | |
| 53 static int current_routing_id_; | |
| 54 static IPC::Channel* channel_; | |
| 55 | 37 |
| 56 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentFilter); | 38 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentFilter); |
| 57 }; | 39 }; |
| 58 | 40 |
| 59 #endif // CHROME_RENDERER_DEVTOOLS_AGENT_FILTER_H_ | 41 #endif // CHROME_RENDERER_DEVTOOLS_AGENT_FILTER_H_ |
| OLD | NEW |