OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/devtools/remote_debugging_server.h" | 5 #include "chrome/browser/devtools/remote_debugging_server.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/devtools/devtools_window.h" | 15 #include "chrome/browser/devtools/devtools_window.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/common/chrome_content_client.h" | 19 #include "chrome/common/chrome_content_client.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "components/version_info/version_info.h" | 21 #include "components/version_info/version_info.h" |
22 #include "content/public/browser/devtools_agent_host.h" | 22 #include "content/public/browser/devtools_agent_host.h" |
23 #include "content/public/browser/devtools_frontend_host.h" | 23 #include "content/public/browser/devtools_frontend_host.h" |
24 #include "content/public/browser/devtools_socket_factory.h" | 24 #include "content/public/browser/devtools_socket_factory.h" |
25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 26 #include "net/log/net_log_source.h" |
26 #include "net/socket/tcp_server_socket.h" | 27 #include "net/socket/tcp_server_socket.h" |
27 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; | 32 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; |
32 | 33 |
33 const uint16_t kMinTetheringPort = 9333; | 34 const uint16_t kMinTetheringPort = 9333; |
34 const uint16_t kMaxTetheringPort = 9444; | 35 const uint16_t kMaxTetheringPort = 9444; |
35 const int kBackLog = 10; | 36 const int kBackLog = 10; |
36 | 37 |
37 class TCPServerSocketFactory | 38 class TCPServerSocketFactory |
38 : public content::DevToolsSocketFactory { | 39 : public content::DevToolsSocketFactory { |
39 public: | 40 public: |
40 TCPServerSocketFactory(const std::string& address, uint16_t port) | 41 TCPServerSocketFactory(const std::string& address, uint16_t port) |
41 : address_(address), | 42 : address_(address), |
42 port_(port), | 43 port_(port), |
43 last_tethering_port_(kMinTetheringPort) {} | 44 last_tethering_port_(kMinTetheringPort) {} |
44 | 45 |
45 private: | 46 private: |
46 std::unique_ptr<net::ServerSocket> CreateLocalHostServerSocket(int port) { | 47 std::unique_ptr<net::ServerSocket> CreateLocalHostServerSocket(int port) { |
47 std::unique_ptr<net::ServerSocket> socket( | 48 std::unique_ptr<net::ServerSocket> socket( |
48 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | 49 new net::TCPServerSocket(nullptr, net::NetLogSource())); |
49 if (socket->ListenWithAddressAndPort( | 50 if (socket->ListenWithAddressAndPort( |
50 "127.0.0.1", port, kBackLog) == net::OK) | 51 "127.0.0.1", port, kBackLog) == net::OK) |
51 return socket; | 52 return socket; |
52 if (socket->ListenWithAddressAndPort("::1", port, kBackLog) == net::OK) | 53 if (socket->ListenWithAddressAndPort("::1", port, kBackLog) == net::OK) |
53 return socket; | 54 return socket; |
54 return std::unique_ptr<net::ServerSocket>(); | 55 return std::unique_ptr<net::ServerSocket>(); |
55 } | 56 } |
56 | 57 |
57 // content::DevToolsSocketFactory. | 58 // content::DevToolsSocketFactory. |
58 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { | 59 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { |
59 std::unique_ptr<net::ServerSocket> socket( | 60 std::unique_ptr<net::ServerSocket> socket( |
60 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | 61 new net::TCPServerSocket(nullptr, net::NetLogSource())); |
61 if (address_.empty()) | 62 if (address_.empty()) |
62 return CreateLocalHostServerSocket(port_); | 63 return CreateLocalHostServerSocket(port_); |
63 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) == net::OK) | 64 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) == net::OK) |
64 return socket; | 65 return socket; |
65 return std::unique_ptr<net::ServerSocket>(); | 66 return std::unique_ptr<net::ServerSocket>(); |
66 } | 67 } |
67 | 68 |
68 std::unique_ptr<net::ServerSocket> CreateForTethering( | 69 std::unique_ptr<net::ServerSocket> CreateForTethering( |
69 std::string* name) override { | 70 std::string* name) override { |
70 if (!g_tethering_enabled.Get()) | 71 if (!g_tethering_enabled.Get()) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 version_info::GetProductNameAndVersionForUserAgent(), | 116 version_info::GetProductNameAndVersionForUserAgent(), |
116 ::GetUserAgent()); | 117 ::GetUserAgent()); |
117 } | 118 } |
118 | 119 |
119 RemoteDebuggingServer::~RemoteDebuggingServer() { | 120 RemoteDebuggingServer::~RemoteDebuggingServer() { |
120 // Ensure Profile is alive, because the whole DevTools subsystem | 121 // Ensure Profile is alive, because the whole DevTools subsystem |
121 // accesses it during shutdown. | 122 // accesses it during shutdown. |
122 DCHECK(g_browser_process->profile_manager()); | 123 DCHECK(g_browser_process->profile_manager()); |
123 content::DevToolsAgentHost::StopRemoteDebuggingServer(); | 124 content::DevToolsAgentHost::StopRemoteDebuggingServer(); |
124 } | 125 } |
OLD | NEW |