Index: content/browser/android/devtools_server.cc |
diff --git a/content/browser/android/devtools_server.cc b/content/browser/android/devtools_server.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fa7b0913e35ef2a2c34b24a6124dfb1c12d0535f |
--- /dev/null |
+++ b/content/browser/android/devtools_server.cc |
@@ -0,0 +1,83 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/android/devtools_server.h" |
+ |
+#include <pwd.h> |
+ |
+#include <cstring> |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/logging.h" |
+#include "base/stringprintf.h" |
+#include "content/public/browser/devtools_http_handler.h" |
+#include "net/base/unix_domain_socket_posix.h" |
+#include "net/url_request/url_request_context_getter.h" |
+ |
+namespace { |
+ |
+const char kFrontEndURL[] = |
+ "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html"; |
John Grabowski
2012/06/11 20:17:02
Is this something for Google internal use, or for
mnaganov (inactive)
2012/06/11 21:32:44
It was already launched as CfA hit the market. Cur
|
+const char kSocketName[] = "chrome_devtools_remote"; |
+ |
+bool UserCanConnect(uid_t uid, gid_t gid) { |
+ struct passwd* creds = getpwuid(uid); |
+ if (!creds || !creds->pw_name) { |
+ LOG(WARNING) << "DevToolsServer: can't obtain creds for uid " << uid; |
+ return false; |
+ } |
+ if (gid == uid && |
+ (strcmp("root", creds->pw_name) == 0 || |
+ strcmp("shell", creds->pw_name) == 0)) { |
+ return true; |
+ } |
+ LOG(WARNING) << "DevToolsServer: connection attempt from " << creds->pw_name; |
+ return false; |
+} |
+ |
+} // namespace |
+ |
+// static |
+DevToolsServer* DevToolsServer::GetInstance() { |
+ return Singleton<DevToolsServer>::get(); |
+} |
+ |
+void DevToolsServer::Init( |
+ const std::string& frontend_version, |
+ net::URLRequestContextGetter* url_request_context, |
+ const DevToolsServer::DelegateCreator& delegate_creator) { |
+ frontend_url_ = StringPrintf(kFrontEndURL, frontend_version.c_str()); |
+ url_request_context_ = url_request_context; |
+ delegate_creator_ = delegate_creator; |
+} |
+ |
+void DevToolsServer::Start() { |
+ Stop(); |
+ DCHECK(is_initialized()); |
+ protocol_handler_ = content::DevToolsHttpHandler::Start( |
+ new net::UnixDomainSocketWithAbstractNamespaceFactory( |
+ kSocketName, base::Bind(&UserCanConnect)), |
+ frontend_url_, |
+ url_request_context_, |
+ delegate_creator_.Run()); |
+} |
+ |
+void DevToolsServer::Stop() { |
+ if (protocol_handler_) { |
+ // Note that the call to Stop() below takes care of |protocol_handler_| |
+ // deletion. |
+ protocol_handler_->Stop(); |
+ protocol_handler_ = NULL; |
+ } |
+} |
+ |
+DevToolsServer::DevToolsServer() |
+ : protocol_handler_(NULL), |
+ url_request_context_(NULL) { |
+} |
+ |
+DevToolsServer::~DevToolsServer() { |
+ Stop(); |
+} |