OLD | NEW |
1 // Copyright (c) 2011 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 CONTENT_RENDERER_DEVTOOLS_AGENT_FILTER_H_ | 5 #ifndef CONTENT_RENDERER_DEVTOOLS_AGENT_FILTER_H_ |
6 #define CONTENT_RENDERER_DEVTOOLS_AGENT_FILTER_H_ | 6 #define CONTENT_RENDERER_DEVTOOLS_AGENT_FILTER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
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 class MessageLoop; | 13 class MessageLoop; |
14 struct DevToolsMessageData; | 14 struct DevToolsMessageData; |
15 | 15 |
16 // DevToolsAgentFilter is registered as an IPC filter in order to be able to | 16 // DevToolsAgentFilter is registered as an IPC filter in order to be able to |
17 // dispatch messages while on the IO thread. The reason for that is that while | 17 // dispatch messages while on the IO thread. The reason for that is that while |
18 // debugging, Render thread is being held by the v8 and hence no messages | 18 // debugging, Render thread is being held by the v8 and hence no messages |
19 // are being dispatched there. While holding the thread in a tight loop, | 19 // are being dispatched there. While holding the thread in a tight loop, |
20 // v8 provides thread-safe Api for controlling debugger. In our case v8's Api | 20 // v8 provides thread-safe Api for controlling debugger. In our case v8's Api |
21 // is being used from this communication agent on the IO thread. | 21 // is being used from this communication agent on the IO thread. |
22 class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { | 22 class DevToolsAgentFilter : public IPC::ChannelProxy::MessageFilter { |
23 public: | 23 public: |
24 // There is a single instance of this class instantiated by the RenderThread. | 24 // There is a single instance of this class instantiated by the RenderThread. |
25 DevToolsAgentFilter(); | 25 DevToolsAgentFilter(); |
26 virtual ~DevToolsAgentFilter(); | |
27 | 26 |
28 static void SendRpcMessage(const DevToolsMessageData& data); | 27 static void SendRpcMessage(const DevToolsMessageData& data); |
29 | 28 |
30 private: | |
31 // IPC::ChannelProxy::MessageFilter override. Called on IO thread. | 29 // IPC::ChannelProxy::MessageFilter override. Called on IO thread. |
32 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 30 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
33 | 31 |
34 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; | 32 protected: |
| 33 virtual ~DevToolsAgentFilter(); |
35 | 34 |
| 35 private: |
36 void OnDispatchOnInspectorBackend(const std::string& message); | 36 void OnDispatchOnInspectorBackend(const std::string& message); |
37 | 37 |
38 bool message_handled_; | 38 bool message_handled_; |
39 MessageLoop* render_thread_loop_; | 39 MessageLoop* render_thread_loop_; |
40 | 40 |
41 // Made static to allow DevToolsAgent to use it for replying directly | |
42 // from IO thread. | |
43 static int current_routing_id_; | |
44 static IPC::Channel* channel_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentFilter); | 41 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentFilter); |
47 }; | 42 }; |
48 | 43 |
49 #endif // CONTENT_RENDERER_DEVTOOLS_AGENT_FILTER_H_ | 44 #endif // CONTENT_RENDERER_DEVTOOLS_AGENT_FILTER_H_ |
OLD | NEW |