blob: fff65ebae4e8d9561192de667337d6880ff13a6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_
#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_
#include <string>
#include "base/hash_tables.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/debugger/devtools_remote.h"
#include "net/base/listen_socket.h"
class InspectableTabProxy;
class DevToolsRemoteListenSocket;
class DevToolsRemoteMessage;
// Dispatches DevToolsRemoteMessages to their appropriate handlers (Tools)
// based on the "Tool" message header value.
class DevToolsProtocolHandler
: public DevToolsRemoteListener,
public OutboundSocketDelegate {
public:
typedef base::hash_map< std::string, scoped_refptr<DevToolsRemoteListener> >
ToolToListenerMap;
explicit DevToolsProtocolHandler(int port);
// This method should be called after the object construction.
void Start();
// This method should be called before the object destruction.
void Stop();
// Registers a |listener| to handle messages for a certain |tool_name| Tool.
// |listener| is the new message handler to register.
// As DevToolsRemoteListener inherits base::RefCountedThreadSafe,
// you should have no problems with ownership and destruction.
// |tool_name| is the name of the Tool to associate the listener with.
void RegisterDestination(DevToolsRemoteListener* listener,
const std::string& tool_name);
// Unregisters a |listener| so that it will no longer handle messages
// directed to the specified |tool_name| tool.
void UnregisterDestination(DevToolsRemoteListener* listener,
const std::string& tool_name);
InspectableTabProxy* inspectable_tab_proxy() {
return inspectable_tab_proxy_.get();
}
// DevToolsRemoteListener interface
virtual void HandleMessage(const DevToolsRemoteMessage& message);
virtual void OnAcceptConnection(ListenSocket *connection);
virtual void OnConnectionLost();
// OutboundSocketDelegate interface
virtual void Send(const DevToolsRemoteMessage& message);
private:
virtual ~DevToolsProtocolHandler();
void Init();
void Teardown();
int port_;
ToolToListenerMap tool_to_listener_map_;
scoped_refptr<ListenSocket> connection_;
scoped_refptr<DevToolsRemoteListenSocket> server_;
scoped_ptr<InspectableTabProxy> inspectable_tab_proxy_;
DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolHandler);
};
#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_PROTOCOL_HANDLER_H_
|