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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/public/browser/android/devtools_server.h"
6
7 #include <pwd.h>
8
9 #include <cstring>
10
11 #include "base/bind.h"
12 #include "base/callback.h"
13 #include "base/logging.h"
14 #include "base/stringprintf.h"
15 #include "content/public/browser/devtools_http_handler.h"
16 #include "net/base/unix_domain_socket_posix.h"
17 #include "net/url_request/url_request_context_getter.h"
18
19 namespace {
20
21 const char kFrontEndURL[] =
22 "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html";
23 const char kSocketName[] = "chrome_devtools_remote";
24
25 bool UserCanConnect(uid_t uid, gid_t gid) {
26 struct passwd* creds = getpwuid(uid);
27 if (!creds || !creds->pw_name) {
28 LOG(WARNING) << "DevToolsServer: can't obtain creds for uid " << uid;
29 return false;
30 }
31 if (gid == uid &&
32 (strcmp("root", creds->pw_name) == 0 ||
33 strcmp("shell", creds->pw_name) == 0)) {
34 return true;
35 }
36 LOG(WARNING) << "DevToolsServer: connection attempt from " << creds->pw_name;
37 return false;
38 }
39
40 } // namespace
41
42 namespace content {
43
44 // static
45 DevToolsServer* DevToolsServer::GetInstance() {
46 return Singleton<DevToolsServer>::get();
47 }
48
49 void DevToolsServer::Init(
50 const std::string& frontend_version,
51 net::URLRequestContextGetter* url_request_context,
52 const DevToolsServer::DelegateCreator& delegate_creator) {
53 frontend_url_ = StringPrintf(kFrontEndURL, frontend_version.c_str());
54 url_request_context_ = url_request_context;
55 delegate_creator_ = delegate_creator;
56 }
57
58 void DevToolsServer::Start() {
59 Stop();
60 DCHECK(is_initialized());
61 protocol_handler_ = content::DevToolsHttpHandler::Start(
62 new net::UnixDomainSocketWithAbstractNamespaceFactory(
63 kSocketName, base::Bind(&UserCanConnect)),
64 frontend_url_,
65 url_request_context_,
66 delegate_creator_.Run());
67 }
68
69 void DevToolsServer::Stop() {
70 if (protocol_handler_) {
71 // Note that the call to Stop() below takes care of |protocol_handler_|
72 // deletion.
73 protocol_handler_->Stop();
74 protocol_handler_ = NULL;
75 }
76 }
77
78 DevToolsServer::DevToolsServer()
79 : protocol_handler_(NULL),
80 url_request_context_(NULL) {
81 }
82
83 DevToolsServer::~DevToolsServer() {
84 Stop();
85 }
86
87 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698