OLD | NEW |
---|---|
(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/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"; | |
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
| |
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 // static | |
43 DevToolsServer* DevToolsServer::GetInstance() { | |
44 return Singleton<DevToolsServer>::get(); | |
45 } | |
46 | |
47 void DevToolsServer::Init( | |
48 const std::string& frontend_version, | |
49 net::URLRequestContextGetter* url_request_context, | |
50 const DevToolsServer::DelegateCreator& delegate_creator) { | |
51 frontend_url_ = StringPrintf(kFrontEndURL, frontend_version.c_str()); | |
52 url_request_context_ = url_request_context; | |
53 delegate_creator_ = delegate_creator; | |
54 } | |
55 | |
56 void DevToolsServer::Start() { | |
57 Stop(); | |
58 DCHECK(is_initialized()); | |
59 protocol_handler_ = content::DevToolsHttpHandler::Start( | |
60 new net::UnixDomainSocketWithAbstractNamespaceFactory( | |
61 kSocketName, base::Bind(&UserCanConnect)), | |
62 frontend_url_, | |
63 url_request_context_, | |
64 delegate_creator_.Run()); | |
65 } | |
66 | |
67 void DevToolsServer::Stop() { | |
68 if (protocol_handler_) { | |
69 // Note that the call to Stop() below takes care of |protocol_handler_| | |
70 // deletion. | |
71 protocol_handler_->Stop(); | |
72 protocol_handler_ = NULL; | |
73 } | |
74 } | |
75 | |
76 DevToolsServer::DevToolsServer() | |
77 : protocol_handler_(NULL), | |
78 url_request_context_(NULL) { | |
79 } | |
80 | |
81 DevToolsServer::~DevToolsServer() { | |
82 Stop(); | |
83 } | |
OLD | NEW |