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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_FILTER_H_
6 #define CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_FILTER_H_
11 #include "ipc/message_filter.h"
13 struct DevToolsMessageData;
17 class MessageLoopProxy;
22 // DevToolsAgentFilter is registered as an IPC filter in order to be able to
23 // dispatch messages while on the IO thread. The reason for that is that while
24 // debugging, Render thread is being held by the v8 and hence no messages
25 // are being dispatched there. While holding the thread in a tight loop,
26 // v8 provides thread-safe Api for controlling debugger. In our case v8's Api
27 // is being used from this communication agent on the IO thread.
28 class DevToolsAgentFilter : public IPC::MessageFilter {
30 // There is a single instance of this class instantiated by the RenderThread.
31 DevToolsAgentFilter();
33 static void SendRpcMessage(const DevToolsMessageData& data);
35 // IPC::MessageFilter override. Called on IO thread.
36 bool OnMessageReceived(const IPC::Message& message) override;
38 // Called on the main thread.
39 void AddEmbeddedWorkerRouteOnMainThread(int32 routing_id);
40 void RemoveEmbeddedWorkerRouteOnMainThread(int32 routing_id);
43 ~DevToolsAgentFilter() override;
46 void OnDispatchOnInspectorBackend(const std::string& message);
48 // Called on IO thread
49 void AddEmbeddedWorkerRoute(int32 routing_id);
50 void RemoveEmbeddedWorkerRoute(int32 routing_id);
52 bool message_handled_;
53 base::MessageLoop* render_thread_loop_;
54 // Proxy to the IO message loop.
55 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
56 int current_routing_id_;
58 std::set<int32> embedded_worker_routes_;
60 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentFilter);
63 } // namespace content
65 #endif // CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_FILTER_H_