Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chromecast/browser/devtools/remote_debugging_server.cc

Issue 2300703005: DevTools: merge devtools_http_handler into content - it is used in all the embedders anyways. (Closed)
Patch Set: for review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #include "chromecast/browser/devtools/remote_debugging_server.h" 5 #include "chromecast/browser/devtools/remote_debugging_server.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chromecast/base/pref_names.h" 15 #include "chromecast/base/pref_names.h"
16 #include "chromecast/browser/cast_browser_process.h" 16 #include "chromecast/browser/cast_browser_process.h"
17 #include "chromecast/browser/devtools/cast_dev_tools_delegate.h" 17 #include "chromecast/browser/devtools/cast_dev_tools_delegate.h"
18 #include "chromecast/common/cast_content_client.h" 18 #include "chromecast/common/cast_content_client.h"
19 #include "components/devtools_http_handler/devtools_http_handler.h"
20 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
21 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/devtools_agent_host.h"
22 #include "content/public/browser/devtools_socket_factory.h" 22 #include "content/public/browser/devtools_socket_factory.h"
23 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/user_agent.h" 24 #include "content/public/common/user_agent.h"
25 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
26 #include "net/socket/tcp_server_socket.h" 26 #include "net/socket/tcp_server_socket.h"
27 27
28 #if defined(OS_ANDROID) 28 #if defined(OS_ANDROID)
29 #include "content/public/browser/android/devtools_auth.h" 29 #include "content/public/browser/android/devtools_auth.h"
30 #include "net/socket/unix_domain_server_socket_posix.h" 30 #include "net/socket/unix_domain_server_socket_posix.h"
31 #endif // defined(OS_ANDROID) 31 #endif // defined(OS_ANDROID)
32 32
33 using devtools_http_handler::DevToolsHttpHandler;
34
35 namespace chromecast { 33 namespace chromecast {
36 namespace shell { 34 namespace shell {
37 35
38 namespace { 36 namespace {
39 37
40 const char kFrontEndURL[] = 38 const char kFrontEndURL[] =
41 "https://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; 39 "https://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html";
42 const uint16_t kDefaultRemoteDebuggingPort = 9222; 40 const uint16_t kDefaultRemoteDebuggingPort = 9222;
43 41
44 const int kBackLog = 10; 42 const int kBackLog = 10;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 #endif 115 #endif
118 } 116 }
119 117
120 std::string GetFrontendUrl() { 118 std::string GetFrontendUrl() {
121 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); 119 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str());
122 } 120 }
123 121
124 } // namespace 122 } // namespace
125 123
126 RemoteDebuggingServer::RemoteDebuggingServer(bool start_immediately) 124 RemoteDebuggingServer::RemoteDebuggingServer(bool start_immediately)
127 : port_(kDefaultRemoteDebuggingPort) { 125 : port_(kDefaultRemoteDebuggingPort),
126 is_started_(false) {
128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 127 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
129 pref_enabled_.Init(prefs::kEnableRemoteDebugging, 128 pref_enabled_.Init(prefs::kEnableRemoteDebugging,
130 CastBrowserProcess::GetInstance()->pref_service(), 129 CastBrowserProcess::GetInstance()->pref_service(),
131 base::Bind(&RemoteDebuggingServer::OnEnabledChanged, 130 base::Bind(&RemoteDebuggingServer::OnEnabledChanged,
132 base::Unretained(this))); 131 base::Unretained(this)));
133 132
134 std::string port_str = 133 std::string port_str =
135 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 134 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
136 switches::kRemoteDebuggingPort); 135 switches::kRemoteDebuggingPort);
137 if (!port_str.empty()) { 136 if (!port_str.empty()) {
(...skipping 11 matching lines...) Expand all
149 OnEnabledChanged(); 148 OnEnabledChanged();
150 } 149 }
151 150
152 RemoteDebuggingServer::~RemoteDebuggingServer() { 151 RemoteDebuggingServer::~RemoteDebuggingServer() {
153 pref_enabled_.SetValue(false); 152 pref_enabled_.SetValue(false);
154 OnEnabledChanged(); 153 OnEnabledChanged();
155 } 154 }
156 155
157 void RemoteDebuggingServer::OnEnabledChanged() { 156 void RemoteDebuggingServer::OnEnabledChanged() {
158 bool enabled = *pref_enabled_ && port_ != 0; 157 bool enabled = *pref_enabled_ && port_ != 0;
159 if (enabled && !devtools_http_handler_) { 158 if (enabled && !is_started_) {
160 devtools_http_handler_.reset(new DevToolsHttpHandler( 159 content::DevToolsAgentHost::StartRemoteDebuggingServer(
161 CreateSocketFactory(port_), 160 CreateSocketFactory(port_),
162 GetFrontendUrl(), 161 GetFrontendUrl(),
163 new CastDevToolsDelegate(),
164 base::FilePath(), 162 base::FilePath(),
165 base::FilePath(), 163 base::FilePath(),
166 std::string(), 164 std::string(),
167 GetUserAgent())); 165 GetUserAgent());
168 LOG(INFO) << "Devtools started: port=" << port_; 166 LOG(INFO) << "Devtools started: port=" << port_;
169 } else if (!enabled && devtools_http_handler_) { 167 } else if (!enabled && is_started_) {
170 LOG(INFO) << "Stop devtools: port=" << port_; 168 LOG(INFO) << "Stop devtools: port=" << port_;
171 devtools_http_handler_.reset(); 169 is_started_ = false;
170 content::DevToolsAgentHost::StopRemoteDebuggingServer();
172 } 171 }
173 } 172 }
174 173
175 } // namespace shell 174 } // namespace shell
176 } // namespace chromecast 175 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698