| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/devtools/devtools_adb_bridge.h" | 5 #include "chrome/browser/devtools/devtools_adb_bridge.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "content/public/browser/devtools_manager.h" | 31 #include "content/public/browser/devtools_manager.h" |
| 32 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
| 33 #include "net/server/web_socket.h" | 33 #include "net/server/web_socket.h" |
| 34 | 34 |
| 35 using content::BrowserThread; | 35 using content::BrowserThread; |
| 36 using net::WebSocket; | 36 using net::WebSocket; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 static const char kDevToolsAdbBridgeThreadName[] = "Chrome_DevToolsADBThread"; | 40 static const char kDevToolsAdbBridgeThreadName[] = "Chrome_DevToolsADBThread"; |
| 41 static const char kDevToolsChannelPattern[] = "devtools_remote"; | |
| 42 static const char kHostDevicesCommand[] = "host:devices"; | 41 static const char kHostDevicesCommand[] = "host:devices"; |
| 43 static const char kDeviceModelCommand[] = | 42 static const char kDeviceModelCommand[] = |
| 44 "host:transport:%s|shell:getprop ro.product.model"; | 43 "host:transport:%s|shell:getprop ro.product.model"; |
| 45 static const char kUnknownModel[] = "Unknown"; | 44 static const char kUnknownModel[] = "Unknown"; |
| 46 static const char kOpenedUnixSocketsCommand[] = | 45 static const char kOpenedUnixSocketsCommand[] = |
| 47 "host:transport:%s|shell:cat /proc/net/unix"; | 46 "host:transport:%s|shell:cat /proc/net/unix"; |
| 48 | 47 |
| 49 static const char kPageListRequest[] = "GET /json HTTP/1.1\r\n\r\n"; | 48 static const char kPageListRequest[] = "GET /json HTTP/1.1\r\n\r\n"; |
| 50 static const char kVersionRequest[] = "GET /json/version HTTP/1.1\r\n\r\n"; | 49 static const char kVersionRequest[] = "GET /json/version HTTP/1.1\r\n\r\n"; |
| 51 static const char kWebSocketUpgradeRequest[] = "GET %s HTTP/1.1\r\n" | 50 static const char kWebSocketUpgradeRequest[] = "GET %s HTTP/1.1\r\n" |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // 00000000: 00000002 00000000 00010000 0001 01 358606 @xxx_devtools_remote | 266 // 00000000: 00000002 00000000 00010000 0001 01 358606 @xxx_devtools_remote |
| 268 // 00000000: 00000002 00000000 00010000 0001 01 347300 @yyy_devtools_remote | 267 // 00000000: 00000002 00000000 00010000 0001 01 347300 @yyy_devtools_remote |
| 269 // | 268 // |
| 270 // We need to find records with paths starting from '@' (abstract socket) | 269 // We need to find records with paths starting from '@' (abstract socket) |
| 271 // and containing "devtools_remote". We have to extract the inode number | 270 // and containing "devtools_remote". We have to extract the inode number |
| 272 // in order to find the owning process name. | 271 // in order to find the owning process name. |
| 273 | 272 |
| 274 socket_to_package_.clear(); | 273 socket_to_package_.clear(); |
| 275 std::vector<std::string> entries; | 274 std::vector<std::string> entries; |
| 276 Tokenize(response, "\n", &entries); | 275 Tokenize(response, "\n", &entries); |
| 277 const std::string channel_pattern = kDevToolsChannelPattern; | 276 const std::string channel_pattern = |
| 277 base::StringPrintf(kDevToolsChannelNameFormat, ""); |
| 278 for (size_t i = 1; i < entries.size(); ++i) { | 278 for (size_t i = 1; i < entries.size(); ++i) { |
| 279 std::vector<std::string> fields; | 279 std::vector<std::string> fields; |
| 280 Tokenize(entries[i], " ", &fields); | 280 Tokenize(entries[i], " ", &fields); |
| 281 if (fields.size() < 8) | 281 if (fields.size() < 8) |
| 282 continue; | 282 continue; |
| 283 if (fields[3] != "00010000" || fields[5] != "01") | 283 if (fields[3] != "00010000" || fields[5] != "01") |
| 284 continue; | 284 continue; |
| 285 std::string path_field = fields[7]; | 285 std::string path_field = fields[7]; |
| 286 if (path_field.size() < 1 || path_field[0] != '@') | 286 if (path_field.size() < 1 || path_field[0] != '@') |
| 287 continue; | 287 continue; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 302 | 302 |
| 303 PagesCallback callback_; | 303 PagesCallback callback_; |
| 304 std::vector<std::string> serials_; | 304 std::vector<std::string> serials_; |
| 305 std::vector<std::string> sockets_; | 305 std::vector<std::string> sockets_; |
| 306 std::map<std::string, std::string> socket_to_package_; | 306 std::map<std::string, std::string> socket_to_package_; |
| 307 scoped_ptr<DevToolsAdbBridge::RemotePages> pages_; | 307 scoped_ptr<DevToolsAdbBridge::RemotePages> pages_; |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 } // namespace | 310 } // namespace |
| 311 | 311 |
| 312 const char kDevToolsChannelNameFormat[] = "%s_devtools_remote"; |
| 313 |
| 312 class AgentHostDelegate; | 314 class AgentHostDelegate; |
| 313 | 315 |
| 314 typedef std::map<std::string, AgentHostDelegate*> AgentHostDelegates; | 316 typedef std::map<std::string, AgentHostDelegate*> AgentHostDelegates; |
| 315 | 317 |
| 316 base::LazyInstance<AgentHostDelegates>::Leaky g_host_delegates = | 318 base::LazyInstance<AgentHostDelegates>::Leaky g_host_delegates = |
| 317 LAZY_INSTANCE_INITIALIZER; | 319 LAZY_INSTANCE_INITIALIZER; |
| 318 | 320 |
| 319 class AgentHostDelegate : public base::RefCountedThreadSafe<AgentHostDelegate>, | 321 class AgentHostDelegate : public base::RefCountedThreadSafe<AgentHostDelegate>, |
| 320 public content::DevToolsExternalAgentProxyDelegate { | 322 public content::DevToolsExternalAgentProxyDelegate { |
| 321 public: | 323 public: |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 if (!has_message_loop_) | 654 if (!has_message_loop_) |
| 653 return; | 655 return; |
| 654 | 656 |
| 655 scoped_refptr<AdbAttachCommand> command( | 657 scoped_refptr<AdbAttachCommand> command( |
| 656 new AdbAttachCommand(weak_factory_.GetWeakPtr(), serial, socket, | 658 new AdbAttachCommand(weak_factory_.GetWeakPtr(), serial, socket, |
| 657 debug_url, frontend_url)); | 659 debug_url, frontend_url)); |
| 658 adb_thread_->message_loop()->PostTask( | 660 adb_thread_->message_loop()->PostTask( |
| 659 FROM_HERE, | 661 FROM_HERE, |
| 660 base::Bind(&AdbAttachCommand::Run, command)); | 662 base::Bind(&AdbAttachCommand::Run, command)); |
| 661 } | 663 } |
| OLD | NEW |