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

Side by Side Diff: content/browser/android/devtools_server.cc

Issue 10832112: Simplify devtools code on android and enable devtools for android content_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Pavel's comments Created 8 years, 4 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/basictypes.h"
12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/compiler_specific.h"
15 #include "base/logging.h"
16 #include "base/memory/singleton.h"
17 #include "base/stringprintf.h"
18 #include "content/public/browser/devtools_http_handler.h"
19 #include "net/base/unix_domain_socket_posix.h"
20 #include "net/url_request/url_request_context_getter.h"
21
22 namespace content {
23
24 namespace {
25
26 const char kFrontEndURL[] =
27 "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html";
28 const char kSocketName[] = "chrome_devtools_remote";
29
30 bool UserCanConnect(uid_t uid, gid_t gid) {
31 struct passwd* creds = getpwuid(uid);
32 if (!creds || !creds->pw_name) {
33 LOG(WARNING) << "DevToolsServer: can't obtain creds for uid " << uid;
34 return false;
35 }
36 if (gid == uid &&
37 (strcmp("root", creds->pw_name) == 0 ||
38 strcmp("shell", creds->pw_name) == 0)) {
39 return true;
40 }
41 LOG(WARNING) << "DevToolsServer: connection attempt from " << creds->pw_name;
42 return false;
43 }
44
45 class DevToolsServerImpl : public DevToolsServer {
46 public:
47 static DevToolsServerImpl* GetInstance() {
48 return Singleton<DevToolsServerImpl>::get();
49 }
50
51 // DevToolsServer:
52 virtual void Init(const std::string& frontend_version,
53 net::URLRequestContextGetter* url_request_context,
54 const DelegateCreator& delegate_creator) OVERRIDE {
55 frontend_url_ = StringPrintf(kFrontEndURL, frontend_version.c_str());
56 url_request_context_ = url_request_context;
57 delegate_creator_ = delegate_creator;
58 }
59
60 virtual void Start() OVERRIDE {
61 Stop();
62 DCHECK(IsInitialized());
63 protocol_handler_ = DevToolsHttpHandler::Start(
64 new net::UnixDomainSocketWithAbstractNamespaceFactory(
65 kSocketName, base::Bind(&UserCanConnect)),
66 frontend_url_,
67 url_request_context_,
68 delegate_creator_.Run());
69 }
70
71 virtual void Stop() OVERRIDE {
72 if (protocol_handler_) {
73 // Note that the call to Stop() below takes care of |protocol_handler_|
74 // deletion.
75 protocol_handler_->Stop();
76 protocol_handler_ = NULL;
77 }
78 }
79
80 virtual bool IsInitialized() const OVERRIDE {
81 return !frontend_url_.empty() && url_request_context_;
82 }
83
84 virtual bool IsStarted() const OVERRIDE {
85 return protocol_handler_;
86 }
87
88 private:
89 friend struct DefaultSingletonTraits<DevToolsServerImpl>;
90
91 DevToolsServerImpl() : protocol_handler_(NULL), url_request_context_(NULL) {}
92
93 virtual ~DevToolsServerImpl() {
94 Stop();
95 }
96
97 DevToolsHttpHandler* protocol_handler_;
98 std::string frontend_url_;
99 net::URLRequestContextGetter* url_request_context_;
100 DelegateCreator delegate_creator_;
101
102 DISALLOW_COPY_AND_ASSIGN(DevToolsServerImpl);
103 };
104
105 } // namespace
106
107 // static
108 DevToolsServer* DevToolsServer::GetInstance() {
109 return DevToolsServerImpl::GetInstance();
110 }
111
112 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/devtools_auth.cc ('k') | content/browser/android/remote_debugging_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698