| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/device/usb/android_usb_socket.h" | 5 #include "chrome/browser/devtools/device/usb/android_usb_socket.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 10 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 11 | 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 const int kMaxPayload = 4096; | 16 const int kMaxPayload = 4096; |
| 15 | 17 |
| 16 } // namespace | 18 } // namespace |
| 17 | 19 |
| 18 AndroidUsbSocket::AndroidUsbSocket(scoped_refptr<AndroidUsbDevice> device, | 20 AndroidUsbSocket::AndroidUsbSocket(scoped_refptr<AndroidUsbDevice> device, |
| 19 uint32 socket_id, | 21 uint32_t socket_id, |
| 20 const std::string& command, | 22 const std::string& command, |
| 21 base::Closure delete_callback) | 23 base::Closure delete_callback) |
| 22 : device_(device), | 24 : device_(device), |
| 23 command_(command), | 25 command_(command), |
| 24 local_id_(socket_id), | 26 local_id_(socket_id), |
| 25 remote_id_(0), | 27 remote_id_(0), |
| 26 is_connected_(false), | 28 is_connected_(false), |
| 27 delete_callback_(delete_callback), | 29 delete_callback_(delete_callback), |
| 28 weak_factory_(this) { | 30 weak_factory_(this) {} |
| 29 } | |
| 30 | 31 |
| 31 AndroidUsbSocket::~AndroidUsbSocket() { | 32 AndroidUsbSocket::~AndroidUsbSocket() { |
| 32 DCHECK(CalledOnValidThread()); | 33 DCHECK(CalledOnValidThread()); |
| 33 if (is_connected_) | 34 if (is_connected_) |
| 34 Disconnect(); | 35 Disconnect(); |
| 35 if (!delete_callback_.is_null()) | 36 if (!delete_callback_.is_null()) |
| 36 delete_callback_.Run(); | 37 delete_callback_.Run(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void AndroidUsbSocket::HandleIncoming(scoped_ptr<AdbMessage> message) { | 40 void AndroidUsbSocket::HandleIncoming(scoped_ptr<AdbMessage> message) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 length = kMaxPayload; | 142 length = kMaxPayload; |
| 142 | 143 |
| 143 DCHECK(write_callback_.is_null()); | 144 DCHECK(write_callback_.is_null()); |
| 144 write_callback_ = callback; | 145 write_callback_ = callback; |
| 145 write_length_ = length; | 146 write_length_ = length; |
| 146 device_->Send(AdbMessage::kCommandWRTE, local_id_, remote_id_, | 147 device_->Send(AdbMessage::kCommandWRTE, local_id_, remote_id_, |
| 147 std::string(buffer->data(), length)); | 148 std::string(buffer->data(), length)); |
| 148 return net::ERR_IO_PENDING; | 149 return net::ERR_IO_PENDING; |
| 149 } | 150 } |
| 150 | 151 |
| 151 int AndroidUsbSocket::SetReceiveBufferSize(int32 size) { | 152 int AndroidUsbSocket::SetReceiveBufferSize(int32_t size) { |
| 152 NOTIMPLEMENTED(); | 153 NOTIMPLEMENTED(); |
| 153 return net::ERR_NOT_IMPLEMENTED; | 154 return net::ERR_NOT_IMPLEMENTED; |
| 154 } | 155 } |
| 155 | 156 |
| 156 int AndroidUsbSocket::SetSendBufferSize(int32 size) { | 157 int AndroidUsbSocket::SetSendBufferSize(int32_t size) { |
| 157 NOTIMPLEMENTED(); | 158 NOTIMPLEMENTED(); |
| 158 return net::ERR_NOT_IMPLEMENTED; | 159 return net::ERR_NOT_IMPLEMENTED; |
| 159 } | 160 } |
| 160 | 161 |
| 161 int AndroidUsbSocket::Connect(const net::CompletionCallback& callback) { | 162 int AndroidUsbSocket::Connect(const net::CompletionCallback& callback) { |
| 162 DCHECK(CalledOnValidThread()); | 163 DCHECK(CalledOnValidThread()); |
| 163 DCHECK(!callback.is_null()); | 164 DCHECK(!callback.is_null()); |
| 164 if (!device_.get()) | 165 if (!device_.get()) |
| 165 return net::ERR_FAILED; | 166 return net::ERR_FAILED; |
| 166 | 167 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 read_buffer_ = read_buffer_.substr(bytes_to_copy); | 257 read_buffer_ = read_buffer_.substr(bytes_to_copy); |
| 257 else | 258 else |
| 258 read_buffer_ = std::string(); | 259 read_buffer_ = std::string(); |
| 259 base::ResetAndReturn(&read_callback_).Run(bytes_to_copy); | 260 base::ResetAndReturn(&read_callback_).Run(bytes_to_copy); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void AndroidUsbSocket::RespondToWriter(int result) { | 263 void AndroidUsbSocket::RespondToWriter(int result) { |
| 263 if (!write_callback_.is_null()) | 264 if (!write_callback_.is_null()) |
| 264 base::ResetAndReturn(&write_callback_).Run(result); | 265 base::ResetAndReturn(&write_callback_).Run(result); |
| 265 } | 266 } |
| OLD | NEW |