Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Unified Diff: content/browser/android/devtools_server.cc

Issue 10540094: Add RemoteDebuggingController.java and its (native) dependencies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move devtools_server.h to content/public Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
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..dfd5fa93b6cb8be3b768ac28490d1a240f1aa7d0
--- /dev/null
+++ b/content/browser/android/devtools_server.cc
@@ -0,0 +1,87 @@
+// 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/public/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";
+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
+
+namespace content {
+
+// 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();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698