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/adb/android_usb_device.h" | 5 #include "chrome/browser/devtools/adb/android_usb_device.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/barrier_closure.h" | 9 #include "base/barrier_closure.h" |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/devtools/adb/android_rsa.h" | 17 #include "chrome/browser/devtools/adb/android_rsa.h" |
17 #include "chrome/browser/devtools/adb/android_usb_socket.h" | 18 #include "chrome/browser/devtools/adb/android_usb_socket.h" |
18 #include "chrome/browser/usb/usb_device.h" | 19 #include "chrome/browser/usb/usb_device.h" |
19 #include "chrome/browser/usb/usb_interface.h" | 20 #include "chrome/browser/usb/usb_interface.h" |
20 #include "chrome/browser/usb/usb_service.h" | 21 #include "chrome/browser/usb/usb_service.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "crypto/rsa_private_key.h" | 23 #include "crypto/rsa_private_key.h" |
23 #include "net/base/ip_endpoint.h" | 24 #include "net/base/ip_endpoint.h" |
24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
25 #include "net/socket/stream_socket.h" | 26 #include "net/socket/stream_socket.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if (inbound_address == 0 || outbound_address == 0) | 92 if (inbound_address == 0 || outbound_address == 0) |
92 return NULL; | 93 return NULL; |
93 | 94 |
94 if (!usb_handle->ClaimInterface(interface_id)) | 95 if (!usb_handle->ClaimInterface(interface_id)) |
95 return NULL; | 96 return NULL; |
96 | 97 |
97 base::string16 serial; | 98 base::string16 serial; |
98 if (!usb_handle->GetSerial(&serial) || serial.empty()) | 99 if (!usb_handle->GetSerial(&serial) || serial.empty()) |
99 return NULL; | 100 return NULL; |
100 | 101 |
101 return new AndroidUsbDevice(rsa_key, usb_handle, UTF16ToASCII(serial), | 102 return new AndroidUsbDevice(rsa_key, usb_handle, base::UTF16ToASCII(serial), |
102 inbound_address, outbound_address, zero_mask); | 103 inbound_address, outbound_address, zero_mask); |
103 } | 104 } |
104 | 105 |
105 uint32 Checksum(const std::string& data) { | 106 uint32 Checksum(const std::string& data) { |
106 unsigned char* x = (unsigned char*)data.data(); | 107 unsigned char* x = (unsigned char*)data.data(); |
107 int count = data.length(); | 108 int count = data.length(); |
108 uint32 sum = 0; | 109 uint32 sum = 0; |
109 while (count-- > 0) | 110 while (count-- > 0) |
110 sum += *x++; | 111 sum += *x++; |
111 return sum; | 112 return sum; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 591 } |
591 | 592 |
592 BrowserThread::PostTask( | 593 BrowserThread::PostTask( |
593 BrowserThread::FILE, FROM_HERE, | 594 BrowserThread::FILE, FROM_HERE, |
594 base::Bind(&ReleaseInterface, usb_device_)); | 595 base::Bind(&ReleaseInterface, usb_device_)); |
595 } | 596 } |
596 | 597 |
597 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { | 598 void AndroidUsbDevice::SocketDeleted(uint32 socket_id) { |
598 sockets_.erase(socket_id); | 599 sockets_.erase(socket_id); |
599 } | 600 } |
OLD | NEW |