Index: chrome/browser/android/dev_tools_server.cc |
diff --git a/chrome/browser/android/dev_tools_server.cc b/chrome/browser/android/dev_tools_server.cc |
index acdb6b589d5bd7225c51eeb82d05122367aeb6f8..3cb011552249256010800fbbe43180b90e0bb1fa 100644 |
--- a/chrome/browser/android/dev_tools_server.cc |
+++ b/chrome/browser/android/dev_tools_server.cc |
@@ -40,7 +40,9 @@ |
#include "content/public/common/user_agent.h" |
#include "grit/browser_resources.h" |
#include "jni/DevToolsServer_jni.h" |
+#include "net/base/net_errors.h" |
#include "net/socket/unix_domain_listen_socket_posix.h" |
+#include "net/socket/unix_domain_server_socket_posix.h" |
#include "net/url_request/url_request_context_getter.h" |
#include "ui/base/resource/resource_bundle.h" |
@@ -389,6 +391,44 @@ class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
DISALLOW_COPY_AND_ASSIGN(DevToolsServerDelegate); |
}; |
+// Factory for UnixDomainServerSocket. It tries a fallback socket when |
+// original socket doesn't work. |
+class UnixDomainServerSocketFactory |
+ : public content::DevToolsHttpHandler::ServerSocketFactory { |
+ public: |
+ explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
+ : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
+ |
+ private: |
+ // content::DevToolsHttpHandler::ServerSocketFactory. |
+ virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
+ return scoped_ptr<net::ServerSocket>( |
+ new net::UnixDomainServerSocket( |
+ base::Bind(&content::CanUserConnectToDevTools), |
+ true)); |
+ } |
+ |
+ virtual scoped_ptr<net::ServerSocket> CreateAndListen() const OVERRIDE { |
+ scoped_ptr<net::ServerSocket> socket = Create(); |
+ if (!socket) |
+ return scoped_ptr<net::ServerSocket>(); |
+ |
+ if (socket->ListenWithAddressAndPort(address_, port_, backlog_) == net::OK) |
+ return socket.Pass(); |
+ |
+ // Tries a fallback socket name. |
+ const std::string fallback_address( |
+ base::StringPrintf("%s_%d", address_.c_str(), getpid())); |
+ if (socket->ListenWithAddressAndPort(fallback_address, port_, backlog_) |
+ == net::OK) |
+ return socket.Pass(); |
+ |
+ return scoped_ptr<net::ServerSocket>(); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
+}; |
+ |
} // namespace |
DevToolsServer::DevToolsServer() |
@@ -423,11 +463,10 @@ void DevToolsServer::Start() { |
if (protocol_handler_) |
return; |
+ scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> factory( |
+ new UnixDomainServerSocketFactory(socket_name_)); |
protocol_handler_ = content::DevToolsHttpHandler::Start( |
- new net::deprecated::UnixDomainListenSocketWithAbstractNamespaceFactory( |
- socket_name_, |
- base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()), |
- base::Bind(&content::CanUserConnectToDevTools)), |
+ factory.Pass(), |
base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()), |
new DevToolsServerDelegate(), |
base::FilePath()); |