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/tethering_adb_filter.h" | 5 #include "chrome/browser/devtools/port_forwarding_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/prefs/pref_change_registrar.h" |
13 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "chrome/browser/devtools/adb_client_socket.h" | 18 #include "chrome/browser/devtools/adb_client_socket.h" |
18 #include "chrome/browser/devtools/adb_web_socket.h" | 19 #include "chrome/browser/devtools/adb_web_socket.h" |
19 #include "chrome/browser/devtools/devtools_protocol.h" | 20 #include "chrome/browser/devtools/devtools_protocol.h" |
20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "net/base/address_list.h" | 23 #include "net/base/address_list.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 IsVersionLower(newest_version, current_version)) { | 255 IsVersionLower(newest_version, current_version)) { |
255 socket = browser->socket(); | 256 socket = browser->socket(); |
256 newest_version = current_version; | 257 newest_version = current_version; |
257 } | 258 } |
258 } | 259 } |
259 return socket; | 260 return socket; |
260 } | 261 } |
261 | 262 |
262 } // namespace | 263 } // namespace |
263 | 264 |
| 265 class TetheringAdbFilter : public base::RefCountedThreadSafe< |
| 266 TetheringAdbFilter, |
| 267 content::BrowserThread::DeleteOnUIThread> { |
| 268 public: |
| 269 typedef DevToolsAdbBridge::RemoteDevice::PortStatus PortStatus; |
| 270 typedef DevToolsAdbBridge::RemoteDevice::PortStatusMap PortStatusMap; |
| 271 |
| 272 TetheringAdbFilter(scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, |
| 273 base::MessageLoop* adb_message_loop, |
| 274 PrefService* pref_service, |
| 275 scoped_refptr<AdbWebSocket> web_socket); |
| 276 |
| 277 const PortStatusMap& GetPortStatusMap(); |
| 278 |
| 279 bool ProcessIncomingMessage(const std::string& message); |
| 280 |
| 281 private: |
| 282 friend struct content::BrowserThread::DeleteOnThread< |
| 283 content::BrowserThread::UI>; |
| 284 friend class base::DeleteHelper<TetheringAdbFilter>; |
| 285 |
| 286 virtual ~TetheringAdbFilter(); |
| 287 |
| 288 typedef std::map<int, std::string> ForwardingMap; |
| 289 |
| 290 typedef base::Callback<void(PortStatus)> CommandCallback; |
| 291 typedef std::map<int, CommandCallback> CommandCallbackMap; |
| 292 |
| 293 void OnPrefsChange(); |
| 294 |
| 295 void ChangeForwardingMap(ForwardingMap map); |
| 296 |
| 297 void SerializeChanges(const std::string& method, |
| 298 const ForwardingMap& old_map, |
| 299 const ForwardingMap& new_map); |
| 300 |
| 301 void SendCommand(const std::string& method, int port); |
| 302 bool ProcessResponse(const std::string& json); |
| 303 |
| 304 void ProcessBindResponse(int port, PortStatus status); |
| 305 void ProcessUnbindResponse(int port, PortStatus status); |
| 306 void UpdateSocketCount(int port, int increment); |
| 307 void UpdatePortStatusMap(); |
| 308 void UpdatePortStatusMapOnUIThread(const PortStatusMap& status_map); |
| 309 |
| 310 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device_; |
| 311 base::MessageLoop* adb_message_loop_; |
| 312 PrefChangeRegistrar pref_change_registrar_; |
| 313 scoped_refptr<AdbWebSocket> web_socket_; |
| 314 int command_id_; |
| 315 ForwardingMap forwarding_map_; |
| 316 CommandCallbackMap pending_responses_; |
| 317 PortStatusMap port_status_; |
| 318 PortStatusMap port_status_on_ui_thread_; |
| 319 |
| 320 DISALLOW_COPY_AND_ASSIGN(TetheringAdbFilter); |
| 321 }; |
| 322 |
264 TetheringAdbFilter::TetheringAdbFilter( | 323 TetheringAdbFilter::TetheringAdbFilter( |
265 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, | 324 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, |
266 base::MessageLoop* adb_message_loop, | 325 base::MessageLoop* adb_message_loop, |
267 PrefService* pref_service, | 326 PrefService* pref_service, |
268 scoped_refptr<AdbWebSocket> web_socket) | 327 scoped_refptr<AdbWebSocket> web_socket) |
269 : device_(device), | 328 : device_(device), |
270 adb_message_loop_(adb_message_loop), | 329 adb_message_loop_(adb_message_loop), |
271 web_socket_(web_socket), | 330 web_socket_(web_socket), |
272 command_id_(0) { | 331 command_id_(0) { |
273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 if (!socket.empty() || (*it)->serial().empty()) { | 644 if (!socket.empty() || (*it)->serial().empty()) { |
586 // Will delete itself when disconnected. | 645 // Will delete itself when disconnected. |
587 new Connection( | 646 new Connection( |
588 ®istry_, (*it)->device(), socket, bridge_, pref_service_); | 647 ®istry_, (*it)->device(), socket, bridge_, pref_service_); |
589 } | 648 } |
590 } else { | 649 } else { |
591 (*it)->set_port_status((*rit).second->port_status()); | 650 (*it)->set_port_status((*rit).second->port_status()); |
592 } | 651 } |
593 } | 652 } |
594 } | 653 } |
OLD | NEW |