| OLD | NEW |
| 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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 #if defined(OS_ANDROID) | 45 #if defined(OS_ANDROID) |
| 46 class UnixDomainServerSocketFactory | 46 class UnixDomainServerSocketFactory |
| 47 : public DevToolsHttpHandler::ServerSocketFactory { | 47 : public DevToolsHttpHandler::ServerSocketFactory { |
| 48 public: | 48 public: |
| 49 explicit UnixDomainServerSocketFactory(const std::string& socket_name) | 49 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 50 : socket_name_(socket_name) {} | 50 : socket_name_(socket_name) {} |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. | 53 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. |
| 54 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { | 54 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { |
| 55 scoped_ptr<net::UnixDomainServerSocket> socket( | 55 std::unique_ptr<net::UnixDomainServerSocket> socket( |
| 56 new net::UnixDomainServerSocket( | 56 new net::UnixDomainServerSocket( |
| 57 base::Bind(&content::CanUserConnectToDevTools), | 57 base::Bind(&content::CanUserConnectToDevTools), |
| 58 true /* use_abstract_namespace */)); | 58 true /* use_abstract_namespace */)); |
| 59 if (socket->BindAndListen(socket_name_, kBackLog) != net::OK) | 59 if (socket->BindAndListen(socket_name_, kBackLog) != net::OK) |
| 60 return scoped_ptr<net::ServerSocket>(); | 60 return std::unique_ptr<net::ServerSocket>(); |
| 61 | 61 |
| 62 return std::move(socket); | 62 return std::move(socket); |
| 63 } | 63 } |
| 64 | 64 |
| 65 std::string socket_name_; | 65 std::string socket_name_; |
| 66 | 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); | 67 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
| 68 }; | 68 }; |
| 69 #else | 69 #else |
| 70 class TCPServerSocketFactory | 70 class TCPServerSocketFactory |
| 71 : public DevToolsHttpHandler::ServerSocketFactory { | 71 : public DevToolsHttpHandler::ServerSocketFactory { |
| 72 public: | 72 public: |
| 73 TCPServerSocketFactory(const std::string& address, uint16_t port) | 73 TCPServerSocketFactory(const std::string& address, uint16_t port) |
| 74 : address_(address), port_(port) {} | 74 : address_(address), port_(port) {} |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. | 77 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. |
| 78 scoped_ptr<net::ServerSocket> CreateForHttpServer() override { | 78 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { |
| 79 scoped_ptr<net::ServerSocket> socket( | 79 std::unique_ptr<net::ServerSocket> socket( |
| 80 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | 80 new net::TCPServerSocket(nullptr, net::NetLog::Source())); |
| 81 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) | 81 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) |
| 82 return scoped_ptr<net::ServerSocket>(); | 82 return std::unique_ptr<net::ServerSocket>(); |
| 83 | 83 |
| 84 return socket; | 84 return socket; |
| 85 } | 85 } |
| 86 | 86 |
| 87 std::string address_; | 87 std::string address_; |
| 88 uint16_t port_; | 88 uint16_t port_; |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); | 90 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
| 91 }; | 91 }; |
| 92 #endif | 92 #endif |
| 93 | 93 |
| 94 scoped_ptr<DevToolsHttpHandler::ServerSocketFactory> CreateSocketFactory( | 94 std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory> CreateSocketFactory( |
| 95 uint16_t port) { | 95 uint16_t port) { |
| 96 #if defined(OS_ANDROID) | 96 #if defined(OS_ANDROID) |
| 97 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 97 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 98 std::string socket_name = "cast_shell_devtools_remote"; | 98 std::string socket_name = "cast_shell_devtools_remote"; |
| 99 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { | 99 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { |
| 100 socket_name = command_line->GetSwitchValueASCII( | 100 socket_name = command_line->GetSwitchValueASCII( |
| 101 switches::kRemoteDebuggingSocketName); | 101 switches::kRemoteDebuggingSocketName); |
| 102 } | 102 } |
| 103 return scoped_ptr<DevToolsHttpHandler::ServerSocketFactory>( | 103 return std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory>( |
| 104 new UnixDomainServerSocketFactory(socket_name)); | 104 new UnixDomainServerSocketFactory(socket_name)); |
| 105 #else | 105 #else |
| 106 return scoped_ptr<DevToolsHttpHandler::ServerSocketFactory>( | 106 return std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory>( |
| 107 new TCPServerSocketFactory("0.0.0.0", port)); | 107 new TCPServerSocketFactory("0.0.0.0", port)); |
| 108 #endif | 108 #endif |
| 109 } | 109 } |
| 110 | 110 |
| 111 std::string GetFrontendUrl() { | 111 std::string GetFrontendUrl() { |
| 112 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); | 112 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 } // namespace | 115 } // namespace |
| 116 | 116 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 GetUserAgent())); | 158 GetUserAgent())); |
| 159 LOG(INFO) << "Devtools started: port=" << port_; | 159 LOG(INFO) << "Devtools started: port=" << port_; |
| 160 } else if (!enabled && devtools_http_handler_) { | 160 } else if (!enabled && devtools_http_handler_) { |
| 161 LOG(INFO) << "Stop devtools: port=" << port_; | 161 LOG(INFO) << "Stop devtools: port=" << port_; |
| 162 devtools_http_handler_.reset(); | 162 devtools_http_handler_.reset(); |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace shell | 166 } // namespace shell |
| 167 } // namespace chromecast | 167 } // namespace chromecast |
| OLD | NEW |