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

Side by Side Diff: chrome/browser/android/dev_tools_server.cc

Issue 680943002: [DevTools] Migrate DevToolsHttpHandlerDelegate::CreateSocketForTethering to StreamSocket (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/dev_tools_server.h" 5 #include "chrome/browser/android/dev_tools_server.h"
6 6
7 #include <pwd.h> 7 #include <pwd.h>
8 #include <cstring> 8 #include <cstring>
9 9
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // corresponding string on the client side. Since debugging an older version of 60 // corresponding string on the client side. Since debugging an older version of
61 // Chrome for Android from a newer version of desktop Chrome is a very common 61 // Chrome for Android from a newer version of desktop Chrome is a very common
62 // scenario, the client code will have to be modified to recognize both the old 62 // scenario, the client code will have to be modified to recognize both the old
63 // and the new format. 63 // and the new format.
64 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote"; 64 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote";
65 65
66 const char kFrontEndURL[] = 66 const char kFrontEndURL[] =
67 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; 67 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html";
68 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; 68 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d";
69 69
70 const int kBackLog = 10;
71
70 bool AuthorizeSocketAccessWithDebugPermission( 72 bool AuthorizeSocketAccessWithDebugPermission(
71 const net::UnixDomainServerSocket::Credentials& credentials) { 73 const net::UnixDomainServerSocket::Credentials& credentials) {
72 JNIEnv* env = base::android::AttachCurrentThread(); 74 JNIEnv* env = base::android::AttachCurrentThread();
73 return Java_DevToolsServer_checkDebugPermission( 75 return Java_DevToolsServer_checkDebugPermission(
74 env, base::android::GetApplicationContext(), 76 env, base::android::GetApplicationContext(),
75 credentials.process_id, credentials.user_id) || 77 credentials.process_id, credentials.user_id) ||
76 content::CanUserConnectToDevTools(credentials); 78 content::CanUserConnectToDevTools(credentials);
77 } 79 }
78 80
79 // Delegate implementation for the devtools http handler on android. A new 81 // Delegate implementation for the devtools http handler on android. A new
80 // instance of this gets created each time devtools is enabled. 82 // instance of this gets created each time devtools is enabled.
81 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { 83 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate {
82 public: 84 public:
83 explicit DevToolsServerDelegate( 85 explicit DevToolsServerDelegate(
84 const net::UnixDomainServerSocket::AuthCallback& auth_callback) 86 const net::UnixDomainServerSocket::AuthCallback& auth_callback)
85 : last_tethering_socket_(0), 87 : last_tethering_socket_(0),
86 auth_callback_(auth_callback) { 88 auth_callback_(auth_callback) {
87 } 89 }
88 90
89 virtual std::string GetDiscoveryPageHTML() override { 91 std::string GetDiscoveryPageHTML() override {
90 // TopSites updates itself after a delay. Ask TopSites to update itself 92 // TopSites updates itself after a delay. Ask TopSites to update itself
91 // when we're about to show the remote debugging landing page. 93 // when we're about to show the remote debugging landing page.
92 content::BrowserThread::PostTask( 94 content::BrowserThread::PostTask(
93 content::BrowserThread::UI, 95 content::BrowserThread::UI,
94 FROM_HERE, 96 FROM_HERE,
95 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails)); 97 base::Bind(&DevToolsServerDelegate::PopulatePageThumbnails));
96 return ResourceBundle::GetSharedInstance().GetRawDataResource( 98 return ResourceBundle::GetSharedInstance().GetRawDataResource(
97 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); 99 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string();
98 } 100 }
99 101
100 virtual bool BundlesFrontendResources() override { 102 bool BundlesFrontendResources() override {
101 return false; 103 return false;
102 } 104 }
103 105
104 virtual base::FilePath GetDebugFrontendDir() override { 106 base::FilePath GetDebugFrontendDir() override {
105 return base::FilePath(); 107 return base::FilePath();
106 } 108 }
107 109
108 virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( 110 scoped_ptr<net::ServerSocket>
109 net::StreamListenSocket::Delegate* delegate, 111 CreateSocketForTethering(std::string* name) override {
110 std::string* name) override {
111 *name = base::StringPrintf( 112 *name = base::StringPrintf(
112 kTetheringSocketName, getpid(), ++last_tethering_socket_); 113 kTetheringSocketName, getpid(), ++last_tethering_socket_);
113 return net::deprecated::UnixDomainListenSocket:: 114 scoped_ptr<net::UnixDomainServerSocket> socket(
114 CreateAndListenWithAbstractNamespace( 115 new net::UnixDomainServerSocket(auth_callback_, true));
115 *name, "", delegate, auth_callback_); 116 if (socket->ListenWithAddressAndPort(*name, 0, kBackLog) != net::OK)
117 return scoped_ptr<net::ServerSocket>();
118
119 return socket.Pass();
116 } 120 }
117 121
118 private: 122 private:
119 static void PopulatePageThumbnails() { 123 static void PopulatePageThumbnails() {
120 Profile* profile = 124 Profile* profile =
121 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); 125 ProfileManager::GetLastUsedProfile()->GetOriginalProfile();
122 history::TopSites* top_sites = profile->GetTopSites(); 126 history::TopSites* top_sites = profile->GetTopSites();
123 if (top_sites) 127 if (top_sites)
124 top_sites->SyncWithHistory(); 128 top_sites->SyncWithHistory();
125 } 129 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 jlong server, 252 jlong server,
249 jboolean enabled, 253 jboolean enabled,
250 jboolean allow_debug_permission) { 254 jboolean allow_debug_permission) {
251 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); 255 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server);
252 if (enabled) { 256 if (enabled) {
253 devtools_server->Start(allow_debug_permission); 257 devtools_server->Start(allow_debug_permission);
254 } else { 258 } else {
255 devtools_server->Stop(); 259 devtools_server->Stop();
256 } 260 }
257 } 261 }
OLDNEW
« no previous file with comments | « android_webview/native/aw_dev_tools_server.cc ('k') | chrome/browser/devtools/browser_list_tabcontents_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698