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_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "content/browser/devtools/devtools_protocol.h"
19 class DictionaryValue
;
20 class MessageLoopProxy
;
30 // This class handles the "Browser" target for remote debugging.
31 class DevToolsBrowserTarget
32 : public base::RefCountedThreadSafe
<DevToolsBrowserTarget
> {
34 DevToolsBrowserTarget(net::HttpServer
* server
, int connection_id
);
36 int connection_id() const { return connection_id_
; }
38 // Takes ownership of |handler|.
39 void RegisterDomainHandler(const std::string
& domain
,
40 DevToolsProtocol::Handler
* handler
,
41 bool handle_on_ui_thread
);
43 void HandleMessage(const std::string
& data
);
48 friend class base::RefCountedThreadSafe
<DevToolsBrowserTarget
>;
49 ~DevToolsBrowserTarget();
51 void HandleCommandOnUIThread(
52 DevToolsProtocol::Handler
*,
53 scoped_refptr
<DevToolsProtocol::Command
> command
);
55 void DeleteHandlersOnUIThread(
56 std::vector
<DevToolsProtocol::Handler
*> handlers
);
58 void Respond(const std::string
& message
);
59 void RespondFromUIThread(const std::string
& message
);
61 scoped_refptr
<base::MessageLoopProxy
> message_loop_proxy_
;
62 net::HttpServer
* http_server_
;
63 const int connection_id_
;
65 typedef std::map
<std::string
, DevToolsProtocol::Handler
*> DomainHandlerMap
;
66 DomainHandlerMap handlers_
;
67 std::set
<std::string
> handle_on_ui_thread_
;
68 base::WeakPtrFactory
<DevToolsBrowserTarget
> weak_factory_
;
70 DISALLOW_COPY_AND_ASSIGN(DevToolsBrowserTarget
);
73 } // namespace content
75 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_BROWSER_TARGET_H_