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/shell/browser/devtools/remote_debugging_server.cc

Issue 454063004: Adds remote devtools support to cast_shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make sure to teardown dev_tools_ in PostMainMessageLoopRun Created 6 years, 4 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
(Empty)
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.
4
5 #include "chromecast/shell/browser/devtools/remote_debugging_server.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/strings/stringprintf.h"
12 #include "chromecast/common/chromecast_config.h"
13 #include "chromecast/common/pref_names.h"
14 #include "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h"
15 #include "content/public/browser/browser_context.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/devtools_http_handler.h"
18 #include "content/public/common/content_switches.h"
19 #include "content/public/common/user_agent.h"
20 #include "net/socket/tcp_listen_socket.h"
21
22 #if defined(OS_ANDROID)
23 #include "content/public/browser/android/devtools_auth.h"
24 #include "net/socket/unix_domain_socket_posix.h"
25 #endif // defined(OS_ANDROID)
26
27 namespace chromecast {
28 namespace shell {
29
30 namespace {
31
32 #if defined(OS_ANDROID)
33 const char kFrontEndURL[] =
34 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html";
35 #endif // defined(OS_ANDROID)
36 const int kDefaultRemoteDebuggingPort = 9222;
37
38 net::StreamListenSocketFactory* CreateSocketFactory(int port) {
39 #if defined(OS_ANDROID)
40 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
41 std::string socket_name = "content_shell_devtools_remote";
42 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) {
43 socket_name = command_line->GetSwitchValueASCII(
44 switches::kRemoteDebuggingSocketName);
45 }
46 return new net::UnixDomainSocketWithAbstractNamespaceFactory(
47 socket_name, "", base::Bind(&content::CanUserConnectToDevTools));
48 #else
49 return new net::TCPListenSocketFactory("0.0.0.0", port);
50 #endif // defined(OS_ANDROID)
51 }
52
53 std::string GetFrontendUrl() {
54 #if defined(OS_ANDROID)
55 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str());
56 #else
57 return std::string();
58 #endif // defined(OS_ANDROID)
59 }
60
61 } // namespace
62
63 RemoteDebuggingServer::RemoteDebuggingServer()
64 : devtools_http_handler_(NULL),
65 port_(0) {
66 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
67 pref_port_.Init(prefs::kRemoteDebuggingPort,
68 ChromecastConfig::GetInstance()->pref_service(),
69 base::Bind(&RemoteDebuggingServer::OnPortChanged,
70 base::Unretained(this)));
71
72 // Starts new dev tools, clearing port number saved in config.
73 // Remote debugging in production must be triggered only by config server.
74 pref_port_.SetValue(ShouldStartImmediately() ?
75 kDefaultRemoteDebuggingPort : 0);
76 OnPortChanged();
77 }
78
79 RemoteDebuggingServer::~RemoteDebuggingServer() {
80 pref_port_.SetValue(0);
81 OnPortChanged();
82 }
83
84 void RemoteDebuggingServer::OnPortChanged() {
85 int new_port = *pref_port_;
86 if (new_port < 0) {
87 new_port = 0;
88 }
89 VLOG(1) << "OnPortChanged called: old_port=" << port_
90 << ", new_port=" << new_port;
91
92 if (new_port == port_) {
93 VLOG(1) << "Port has not been changed. Ignore silently.";
94 return;
95 }
96
97 if (devtools_http_handler_) {
98 LOG(INFO) << "Stop old devtools: port=" << port_;
99 devtools_http_handler_->Stop();
byungchul 2014/08/14 20:43:54 please comment that Stop() destroys devtools_http_
gunsch 2014/08/14 21:28:49 Done.
100 devtools_http_handler_ = NULL;
101 }
102
103 port_ = new_port;
104 if (port_ > 0) {
105 devtools_http_handler_ = content::DevToolsHttpHandler::Start(
106 CreateSocketFactory(port_),
107 GetFrontendUrl(),
108 new CastDevToolsDelegate(),
109 base::FilePath());
110 LOG(INFO) << "Devtools started: port=" << port_;
111 }
112 }
113
114 } // namespace shell
115 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698