| OLD | NEW |
| 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 16 matching lines...) Expand all Loading... |
| 27 #include "jni/DevToolsServer_jni.h" | 27 #include "jni/DevToolsServer_jni.h" |
| 28 #include "net/socket/unix_domain_socket_posix.h" | 28 #include "net/socket/unix_domain_socket_posix.h" |
| 29 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 const char kFrontEndURL[] = | 34 const char kFrontEndURL[] = |
| 35 "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html"; | 35 "http://chrome-devtools-frontend.appspot.com/static/%s/devtools.html"; |
| 36 const char kDefaultSocketName[] = "chrome_devtools_remote"; | 36 const char kDefaultSocketName[] = "chrome_devtools_remote"; |
| 37 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d"; | 37 const char kTetheringSocketName[] = "chrome_devtools_tethering_%d_%d"; |
| 38 | 38 |
| 39 // Delegate implementation for the devtools http handler on android. A new | 39 // Delegate implementation for the devtools http handler on android. A new |
| 40 // instance of this gets created each time devtools is enabled. | 40 // instance of this gets created each time devtools is enabled. |
| 41 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { | 41 class DevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
| 42 public: | 42 public: |
| 43 explicit DevToolsServerDelegate(bool use_bundled_frontend_resources) | 43 explicit DevToolsServerDelegate(bool use_bundled_frontend_resources) |
| 44 : use_bundled_frontend_resources_(use_bundled_frontend_resources), | 44 : use_bundled_frontend_resources_(use_bundled_frontend_resources), |
| 45 last_tethering_socket_(0) { | 45 last_tethering_socket_(0) { |
| 46 } | 46 } |
| 47 | 47 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 return kTargetTypeTab; | 85 return kTargetTypeTab; |
| 86 } | 86 } |
| 87 | 87 |
| 88 virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE { | 88 virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE { |
| 89 return ""; | 89 return ""; |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual scoped_refptr<net::StreamListenSocket> CreateSocketForTethering( | 92 virtual scoped_refptr<net::StreamListenSocket> CreateSocketForTethering( |
| 93 net::StreamListenSocket::Delegate* delegate, | 93 net::StreamListenSocket::Delegate* delegate, |
| 94 std::string* name) OVERRIDE { | 94 std::string* name) OVERRIDE { |
| 95 *name = base::StringPrintf(kTetheringSocketName, ++last_tethering_socket_); | 95 *name = base::StringPrintf( |
| 96 kTetheringSocketName, getpid(), ++last_tethering_socket_); |
| 96 return net::UnixDomainSocket::CreateAndListenWithAbstractNamespace( | 97 return net::UnixDomainSocket::CreateAndListenWithAbstractNamespace( |
| 97 *name, | 98 *name, |
| 99 "", |
| 98 delegate, | 100 delegate, |
| 99 base::Bind(&content::CanUserConnectToDevTools)); | 101 base::Bind(&content::CanUserConnectToDevTools)); |
| 100 } | 102 } |
| 101 | 103 |
| 102 private: | 104 private: |
| 103 static void PopulatePageThumbnails() { | 105 static void PopulatePageThumbnails() { |
| 104 Profile* profile = | 106 Profile* profile = |
| 105 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); | 107 ProfileManager::GetLastUsedProfile()->GetOriginalProfile(); |
| 106 history::TopSites* top_sites = profile->GetTopSites(); | 108 history::TopSites* top_sites = profile->GetTopSites(); |
| 107 if (top_sites) | 109 if (top_sites) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 143 |
| 142 void DevToolsServer::Start() { | 144 void DevToolsServer::Start() { |
| 143 if (protocol_handler_) | 145 if (protocol_handler_) |
| 144 return; | 146 return; |
| 145 | 147 |
| 146 chrome::VersionInfo version_info; | 148 chrome::VersionInfo version_info; |
| 147 | 149 |
| 148 protocol_handler_ = content::DevToolsHttpHandler::Start( | 150 protocol_handler_ = content::DevToolsHttpHandler::Start( |
| 149 new net::UnixDomainSocketWithAbstractNamespaceFactory( | 151 new net::UnixDomainSocketWithAbstractNamespaceFactory( |
| 150 socket_name_, | 152 socket_name_, |
| 153 base::StringPrintf("%s_%d", socket_name_.c_str(), getpid()), |
| 151 base::Bind(&content::CanUserConnectToDevTools)), | 154 base::Bind(&content::CanUserConnectToDevTools)), |
| 152 use_bundled_frontend_resources_ ? | 155 use_bundled_frontend_resources_ ? |
| 153 "" : | 156 "" : |
| 154 base::StringPrintf(kFrontEndURL, version_info.Version().c_str()), | 157 base::StringPrintf(kFrontEndURL, version_info.Version().c_str()), |
| 155 new DevToolsServerDelegate(use_bundled_frontend_resources_)); | 158 new DevToolsServerDelegate(use_bundled_frontend_resources_)); |
| 156 } | 159 } |
| 157 | 160 |
| 158 void DevToolsServer::Stop() { | 161 void DevToolsServer::Stop() { |
| 159 if (!protocol_handler_) | 162 if (!protocol_handler_) |
| 160 return; | 163 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 jobject obj, | 199 jobject obj, |
| 197 jint server, | 200 jint server, |
| 198 jboolean enabled) { | 201 jboolean enabled) { |
| 199 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); | 202 DevToolsServer* devtools_server = reinterpret_cast<DevToolsServer*>(server); |
| 200 if (enabled) { | 203 if (enabled) { |
| 201 devtools_server->Start(); | 204 devtools_server->Start(); |
| 202 } else { | 205 } else { |
| 203 devtools_server->Stop(); | 206 devtools_server->Stop(); |
| 204 } | 207 } |
| 205 } | 208 } |
| OLD | NEW |