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_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_ |
6 #define CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_ | 6 #define CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "chrome/browser/debugger/devtools_remote.h" | 14 #include "chrome/browser/debugger/devtools_remote.h" |
15 #include "net/base/listen_socket.h" | 15 #include "net/base/listen_socket.h" |
16 | 16 |
17 class InspectableTabProxy; | 17 class InspectableTabProxy; |
18 class DevToolsRemoteListenSocket; | 18 class DevToolsRemoteListenSocket; |
19 class DevToolsRemoteMessage; | 19 class DevToolsRemoteMessage; |
20 | 20 |
21 // Dispatches DevToolsRemoteMessages to their appropriate handlers (Tools) | 21 // Dispatches DevToolsRemoteMessages to their appropriate handlers (Tools) |
22 // based on the "Tool" message header value. | 22 // based on the "Tool" message header value. |
23 class DevToolsProtocolHandler | 23 class DevToolsProtocolHandler |
24 : public DevToolsRemoteListener, | 24 : public DevToolsRemoteListener, |
25 public OutboundSocketDelegate { | 25 public OutboundSocketDelegate { |
26 public: | 26 public: |
27 typedef base::hash_map< std::string, scoped_refptr<DevToolsRemoteListener> > | 27 typedef base::hash_map< std::string, scoped_refptr<DevToolsRemoteListener> > |
28 ToolToListenerMap; | 28 ToolToListenerMap; |
29 | 29 |
30 explicit DevToolsProtocolHandler(int port); | 30 static DevToolsProtocolHandler* Start(int port); |
31 | 31 |
32 // This method should be called after the object construction. | 32 // Called from the main thread in order to stop protocol handler. |
33 void Start(); | 33 // Will schedule tear down task on IO thread. |
34 | |
35 // This method should be called before the object destruction. | |
36 void Stop(); | 34 void Stop(); |
37 | 35 |
38 // Registers a |listener| to handle messages for a certain |tool_name| Tool. | 36 // Registers a |listener| to handle messages for a certain |tool_name| Tool. |
39 // |listener| is the new message handler to register. | 37 // |listener| is the new message handler to register. |
40 // As DevToolsRemoteListener inherits base::RefCountedThreadSafe, | 38 // As DevToolsRemoteListener inherits base::RefCountedThreadSafe, |
41 // you should have no problems with ownership and destruction. | 39 // you should have no problems with ownership and destruction. |
42 // |tool_name| is the name of the Tool to associate the listener with. | 40 // |tool_name| is the name of the Tool to associate the listener with. |
43 void RegisterDestination(DevToolsRemoteListener* listener, | 41 void RegisterDestination(DevToolsRemoteListener* listener, |
44 const std::string& tool_name); | 42 const std::string& tool_name); |
45 | 43 |
46 // Unregisters a |listener| so that it will no longer handle messages | 44 // Unregisters a |listener| so that it will no longer handle messages |
47 // directed to the specified |tool_name| tool. | 45 // directed to the specified |tool_name| tool. |
48 void UnregisterDestination(DevToolsRemoteListener* listener, | 46 void UnregisterDestination(DevToolsRemoteListener* listener, |
49 const std::string& tool_name); | 47 const std::string& tool_name); |
50 | 48 |
51 InspectableTabProxy* inspectable_tab_proxy() { | 49 InspectableTabProxy* inspectable_tab_proxy() { |
52 return inspectable_tab_proxy_.get(); | 50 return inspectable_tab_proxy_.get(); |
53 } | 51 } |
54 | 52 |
55 // DevToolsRemoteListener interface | 53 // DevToolsRemoteListener interface |
56 virtual void HandleMessage(const DevToolsRemoteMessage& message); | 54 virtual void HandleMessage(const DevToolsRemoteMessage& message); |
57 virtual void OnAcceptConnection(ListenSocket *connection); | 55 virtual void OnAcceptConnection(ListenSocket *connection); |
58 virtual void OnConnectionLost(); | 56 virtual void OnConnectionLost(); |
59 | 57 |
60 // OutboundSocketDelegate interface | 58 // OutboundSocketDelegate interface |
61 virtual void Send(const DevToolsRemoteMessage& message); | 59 virtual void Send(const DevToolsRemoteMessage& message); |
62 | 60 |
63 private: | 61 private: |
| 62 explicit DevToolsProtocolHandler(int port); |
64 virtual ~DevToolsProtocolHandler(); | 63 virtual ~DevToolsProtocolHandler(); |
| 64 void Start(); |
65 | 65 |
66 void Init(); | 66 void Init(); |
67 void Teardown(); | 67 void Teardown(); |
68 int port_; | 68 int port_; |
69 ToolToListenerMap tool_to_listener_map_; | 69 ToolToListenerMap tool_to_listener_map_; |
70 scoped_refptr<ListenSocket> connection_; | 70 scoped_refptr<ListenSocket> connection_; |
71 scoped_refptr<DevToolsRemoteListenSocket> server_; | 71 scoped_refptr<DevToolsRemoteListenSocket> server_; |
72 scoped_ptr<InspectableTabProxy> inspectable_tab_proxy_; | 72 scoped_ptr<InspectableTabProxy> inspectable_tab_proxy_; |
73 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolHandler); | 73 DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolHandler); |
74 }; | 74 }; |
75 | 75 |
76 #endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_ | 76 #endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_ |
OLD | NEW |