1 // Copyright 2014 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 #include "content/browser/devtools/browser_devtools_agent_host.h"
8 #include "content/browser/devtools/devtools_protocol_handler.h"
9 #include "content/browser/devtools/protocol/io_handler.h"
10 #include "content/browser/devtools/protocol/system_info_handler.h"
11 #include "content/browser/devtools/protocol/tethering_handler.h"
12 #include "content/browser/devtools/protocol/tracing_handler.h"
16 scoped_refptr
<DevToolsAgentHost
> DevToolsAgentHost::CreateForBrowser(
17 scoped_refptr
<base::SingleThreadTaskRunner
> tethering_task_runner
,
18 const CreateServerSocketCallback
& socket_callback
) {
19 return new BrowserDevToolsAgentHost(tethering_task_runner
, socket_callback
);
22 BrowserDevToolsAgentHost::BrowserDevToolsAgentHost(
23 scoped_refptr
<base::SingleThreadTaskRunner
> tethering_task_runner
,
24 const CreateServerSocketCallback
& socket_callback
)
25 : io_handler_(new devtools::io::IOHandler(GetIOContext())),
26 system_info_handler_(new devtools::system_info::SystemInfoHandler()),
28 new devtools::tethering::TetheringHandler(socket_callback
,
29 tethering_task_runner
)),
30 tracing_handler_(new devtools::tracing::TracingHandler(
31 devtools::tracing::TracingHandler::Browser
, GetIOContext())),
32 protocol_handler_(new DevToolsProtocolHandler(
34 base::Bind(&BrowserDevToolsAgentHost::SendMessageToClient
,
35 base::Unretained(this)))) {
36 DevToolsProtocolDispatcher
* dispatcher
= protocol_handler_
->dispatcher();
37 dispatcher
->SetIOHandler(io_handler_
.get());
38 dispatcher
->SetSystemInfoHandler(system_info_handler_
.get());
39 dispatcher
->SetTetheringHandler(tethering_handler_
.get());
40 dispatcher
->SetTracingHandler(tracing_handler_
.get());
43 BrowserDevToolsAgentHost::~BrowserDevToolsAgentHost() {
46 void BrowserDevToolsAgentHost::Attach() {
49 void BrowserDevToolsAgentHost::Detach() {
52 DevToolsAgentHost::Type
BrowserDevToolsAgentHost::GetType() {
56 std::string
BrowserDevToolsAgentHost::GetTitle() {
60 GURL
BrowserDevToolsAgentHost::GetURL() {
64 bool BrowserDevToolsAgentHost::Activate() {
68 bool BrowserDevToolsAgentHost::Close() {
72 bool BrowserDevToolsAgentHost::DispatchProtocolMessage(
73 const std::string
& message
) {
74 protocol_handler_
->HandleMessage(message
);