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

Side by Side Diff: chrome/browser/devtools/device/adb/adb_client_socket.cc

Issue 505783002: Revert of DevTools: Removed refcounting from AndroidWebSocket (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months 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 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/adb/adb_client_socket.h" 5 #include "chrome/browser/devtools/device/adb/adb_client_socket.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 #include "net/socket/tcp_client_socket.h" 14 #include "net/socket/tcp_client_socket.h"
15 15
16 namespace { 16 namespace {
17 17
18 const int kBufferSize = 16 * 1024; 18 const int kBufferSize = 16 * 1024;
19 const char kOkayResponse[] = "OKAY"; 19 const char kOkayResponse[] = "OKAY";
20 const char kHostTransportCommand[] = "host:transport:%s"; 20 const char kHostTransportCommand[] = "host:transport:%s";
21 const char kLocalhost[] = "127.0.0.1"; 21 const char kLocalhost[] = "127.0.0.1";
22 22
23 typedef base::Callback<void(int, const std::string&)> CommandCallback;
24 typedef base::Callback<void(int, net::StreamSocket*)> SocketCallback;
25
23 std::string EncodeMessage(const std::string& message) { 26 std::string EncodeMessage(const std::string& message) {
24 static const char kHexChars[] = "0123456789ABCDEF"; 27 static const char kHexChars[] = "0123456789ABCDEF";
25 28
26 size_t length = message.length(); 29 size_t length = message.length();
27 std::string result(4, '\0'); 30 std::string result(4, '\0');
28 char b = reinterpret_cast<const char*>(&length)[1]; 31 char b = reinterpret_cast<const char*>(&length)[1];
29 result[0] = kHexChars[(b >> 4) & 0xf]; 32 result[0] = kHexChars[(b >> 4) & 0xf];
30 result[1] = kHexChars[b & 0xf]; 33 result[1] = kHexChars[b & 0xf];
31 b = reinterpret_cast<const char*>(&length)[0]; 34 b = reinterpret_cast<const char*>(&length)[0];
32 result[2] = kHexChars[(b >> 4) & 0xf]; 35 result[2] = kHexChars[(b >> 4) & 0xf];
(...skipping 30 matching lines...) Expand all
63 if (!CheckNetResultOrDie(result)) 66 if (!CheckNetResultOrDie(result))
64 return; 67 return;
65 SendCommand(socket_name_, true, 68 SendCommand(socket_name_, true,
66 base::Bind(&AdbTransportSocket::OnSocketAvailable, 69 base::Bind(&AdbTransportSocket::OnSocketAvailable,
67 base::Unretained(this))); 70 base::Unretained(this)));
68 } 71 }
69 72
70 void OnSocketAvailable(int result, const std::string& response) { 73 void OnSocketAvailable(int result, const std::string& response) {
71 if (!CheckNetResultOrDie(result)) 74 if (!CheckNetResultOrDie(result))
72 return; 75 return;
73 callback_.Run(net::OK, socket_.Pass()); 76 callback_.Run(net::OK, socket_.release());
74 delete this; 77 delete this;
75 } 78 }
76 79
77 bool CheckNetResultOrDie(int result) { 80 bool CheckNetResultOrDie(int result) {
78 if (result >= 0) 81 if (result >= 0)
79 return true; 82 return true;
80 callback_.Run(result, make_scoped_ptr<net::StreamSocket>(NULL)); 83 callback_.Run(result, NULL);
81 delete this; 84 delete this;
82 return false; 85 return false;
83 } 86 }
84 87
85 std::string serial_; 88 std::string serial_;
86 std::string socket_name_; 89 std::string socket_name_;
87 SocketCallback callback_; 90 SocketCallback callback_;
88 }; 91 };
89 92
90 class AdbQuerySocket : AdbClientSocket { 93 class AdbQuerySocket : AdbClientSocket {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 base::Unretained(this), 287 base::Unretained(this),
285 callback, 288 callback,
286 new_response, 289 new_response,
287 response_buffer, 290 response_buffer,
288 bytes_left)); 291 bytes_left));
289 if (result > 0) 292 if (result > 0)
290 OnResponseData(callback, new_response, response_buffer, bytes_left, result); 293 OnResponseData(callback, new_response, response_buffer, bytes_left, result);
291 else if (result != net::ERR_IO_PENDING) 294 else if (result != net::ERR_IO_PENDING)
292 callback.Run(net::OK, new_response); 295 callback.Run(net::OK, new_response);
293 } 296 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/device/adb/adb_client_socket.h ('k') | chrome/browser/devtools/device/android_device_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698