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

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: Address John's comment Created 8 years, 5 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..1fdd82c2ad784806cab7bd2b03b88f7541e7d53b
--- /dev/null
+++ b/content/browser/android/devtools_server.cc
@@ -0,0 +1,113 @@
+// 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 <string>
jam 2012/07/11 15:19:22 nit: in header for this file, so not needed
Philippe 2012/07/11 15:48:05 Done.
+
+#include "base/basictypes.h"
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/compiler_specific.h"
+#include "base/logging.h"
+#include "base/memory/singleton.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 content {
+
+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;
+}
+
+class DevToolsServerImpl : public DevToolsServer {
+ public:
+ static DevToolsServerImpl* GetInstance() {
+ return Singleton<DevToolsServerImpl>::get();
+ }
+
+ // DevToolsServer:
+ virtual void Init(const std::string& frontend_version,
+ net::URLRequestContextGetter* url_request_context,
+ const DelegateCreator& delegate_creator) OVERRIDE {
+ frontend_url_ = StringPrintf(kFrontEndURL, frontend_version.c_str());
+ url_request_context_ = url_request_context;
+ delegate_creator_ = delegate_creator;
+ }
+
+ virtual void Start() OVERRIDE {
+ Stop();
+ DCHECK(is_initialized());
+ protocol_handler_ = content::DevToolsHttpHandler::Start(
jam 2012/07/11 15:19:22 nit: here and below, don't need "content::"
Philippe 2012/07/11 15:48:05 Done.
+ new net::UnixDomainSocketWithAbstractNamespaceFactory(
+ kSocketName, base::Bind(&UserCanConnect)),
+ frontend_url_,
+ url_request_context_,
+ delegate_creator_.Run());
+ }
+
+ virtual void Stop() OVERRIDE {
+ if (protocol_handler_) {
+ // Note that the call to Stop() below takes care of |protocol_handler_|
+ // deletion.
+ protocol_handler_->Stop();
+ protocol_handler_ = NULL;
+ }
+ }
+
+ virtual bool is_initialized() const OVERRIDE {
+ return !frontend_url_.empty() && url_request_context_;
+ }
+
+ virtual bool is_started() const OVERRIDE {
+ return protocol_handler_;
+ }
+
+ private:
+ friend struct DefaultSingletonTraits<DevToolsServerImpl>;
+
+ DevToolsServerImpl() : protocol_handler_(NULL), url_request_context_(NULL) {}
+
+ virtual ~DevToolsServerImpl() {
+ Stop();
+ }
+
+ content::DevToolsHttpHandler* protocol_handler_;
+ std::string frontend_url_;
+ net::URLRequestContextGetter* url_request_context_;
+ DelegateCreator delegate_creator_;
+
+ DISALLOW_COPY_AND_ASSIGN(DevToolsServerImpl);
+};
+
+} // namespace
+
+// static
+DevToolsServer* DevToolsServer::GetInstance() {
+ return DevToolsServerImpl::GetInstance();
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698