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. 4 5 #ifndef CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_FILTER_H_ 6 #define CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_FILTER_H_ 7 8 #include <set> 9 #include <string> 10 11 #include "ipc/message_filter.h" 12 13 struct DevToolsMessageData; 14 15 namespace base { 16 class MessageLoop; 17 class MessageLoopProxy; 18 } 19 20 namespace content { 21 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 { 29 public: 30 // There is a single instance of this class instantiated by the RenderThread. 31 DevToolsAgentFilter(); 32 33 static void SendRpcMessage(const DevToolsMessageData& data); 34 35 // IPC::MessageFilter override. Called on IO thread. 36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 37 38 // Called on the main thread. 39 void AddEmbeddedWorkerRouteOnMainThread(int32 routing_id); 40 void RemoveEmbeddedWorkerRouteOnMainThread(int32 routing_id); 41 42 protected: 43 virtual ~DevToolsAgentFilter(); 44 45 private: 46 void OnDispatchOnInspectorBackend(const std::string& message); 47 48 // Called on IO thread 49 void AddEmbeddedWorkerRoute(int32 routing_id); 50 void RemoveEmbeddedWorkerRoute(int32 routing_id); 51 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_; 57 58 std::set<int32> embedded_worker_routes_; 59 60 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentFilter); 61 }; 62 63 } // namespace content 64 65 #endif // CONTENT_RENDERER_DEVTOOLS_DEVTOOLS_AGENT_FILTER_H_ 66