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 #ifndef CHROME_BROWSER_DEVTOOLS_TETHERING_ADB_FILTER_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_TETHERING_ADB_FILTER_H_ |
6 #define CHROME_BROWSER_DEVTOOLS_TETHERING_ADB_FILTER_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_TETHERING_ADB_FILTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/prefs/pref_change_registrar.h" | 13 #include "base/prefs/pref_change_registrar.h" |
14 #include "chrome/browser/devtools/adb_web_socket.h" | 14 #include "chrome/browser/devtools/adb_web_socket.h" |
15 #include "chrome/browser/devtools/devtools_adb_bridge.h" | 15 #include "chrome/browser/devtools/devtools_adb_bridge.h" |
16 | 16 |
17 class PrefService; | 17 class PrefService; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class MessageLoop; | 20 class MessageLoop; |
21 } | 21 } |
22 | 22 |
23 class TetheringAdbFilter { | 23 class TetheringAdbFilter { |
24 public: | 24 public: |
| 25 typedef DevToolsAdbBridge::RemoteDevice::PortStatus PortStatus; |
| 26 typedef DevToolsAdbBridge::RemoteDevice::PortStatusMap PortStatusMap; |
| 27 |
25 TetheringAdbFilter(scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, | 28 TetheringAdbFilter(scoped_refptr<DevToolsAdbBridge::AndroidDevice> device, |
26 base::MessageLoop* adb_message_loop, | 29 base::MessageLoop* adb_message_loop, |
27 PrefService* pref_service, | 30 PrefService* pref_service, |
28 scoped_refptr<AdbWebSocket> web_socket); | 31 scoped_refptr<AdbWebSocket> web_socket); |
29 ~TetheringAdbFilter(); | 32 ~TetheringAdbFilter(); |
30 | 33 |
| 34 const PortStatusMap& GetPortStatusMap(); |
| 35 |
31 bool ProcessIncomingMessage(const std::string& message); | 36 bool ProcessIncomingMessage(const std::string& message); |
32 | 37 |
33 private: | 38 private: |
34 typedef std::map<int, std::string> ForwardingMap; | 39 typedef std::map<int, std::string> ForwardingMap; |
35 | 40 |
| 41 typedef base::Callback<void(PortStatus)> CommandCallback; |
| 42 typedef std::map<int, CommandCallback> CommandCallbackMap; |
| 43 |
36 void OnPrefsChange(); | 44 void OnPrefsChange(); |
37 | 45 |
38 void ChangeForwardingMap(ForwardingMap map); | 46 void ChangeForwardingMap(ForwardingMap map); |
39 | 47 |
40 void SerializeChanges(const std::string& method, | 48 void SerializeChanges(const std::string& method, |
41 const ForwardingMap& old_map, | 49 const ForwardingMap& old_map, |
42 const ForwardingMap& new_map); | 50 const ForwardingMap& new_map); |
43 | 51 |
44 void SendCommand(const std::string& method, int port); | 52 void SendCommand(const std::string& method, int port); |
| 53 bool ProcessResponse(const std::string& json); |
| 54 |
| 55 void ProcessBindResponse(int port, PortStatus status); |
| 56 void ProcessUnbindResponse(int port, PortStatus status); |
| 57 void UpdateSocketCount(int port, int increment); |
| 58 void UpdatePortStatusMap(); |
| 59 void UpdatePortStatusMapOnUIThread(const PortStatusMap& status_map); |
45 | 60 |
46 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device_; | 61 scoped_refptr<DevToolsAdbBridge::AndroidDevice> device_; |
47 base::MessageLoop* adb_message_loop_; | 62 base::MessageLoop* adb_message_loop_; |
48 PrefChangeRegistrar pref_change_registrar_; | 63 PrefChangeRegistrar pref_change_registrar_; |
49 scoped_refptr<AdbWebSocket> web_socket_; | 64 scoped_refptr<AdbWebSocket> web_socket_; |
50 int command_id_; | 65 int command_id_; |
51 ForwardingMap forwarding_map_; | 66 ForwardingMap forwarding_map_; |
| 67 CommandCallbackMap pending_responses_; |
| 68 PortStatusMap port_status_; |
| 69 PortStatusMap port_status_on_ui_thread_; |
52 base::WeakPtrFactory<TetheringAdbFilter> weak_factory_; | 70 base::WeakPtrFactory<TetheringAdbFilter> weak_factory_; |
53 | 71 |
54 DISALLOW_COPY_AND_ASSIGN(TetheringAdbFilter); | 72 DISALLOW_COPY_AND_ASSIGN(TetheringAdbFilter); |
55 }; | 73 }; |
56 | 74 |
57 class PortForwardingController { | 75 class PortForwardingController { |
58 public: | 76 public: |
59 PortForwardingController( | 77 PortForwardingController( |
60 base::MessageLoop* adb_message_loop, | 78 base::MessageLoop* adb_message_loop, |
61 PrefService* pref_service); | 79 PrefService* pref_service); |
62 | 80 |
63 virtual ~PortForwardingController(); | 81 virtual ~PortForwardingController(); |
64 | 82 |
65 void UpdateDeviceList(const DevToolsAdbBridge::RemoteDevices& devices); | 83 void UpdateDeviceList(const DevToolsAdbBridge::RemoteDevices& devices); |
66 | 84 |
67 private: | 85 private: |
68 class Connection; | 86 class Connection; |
69 typedef std::map<std::string, Connection*> Registry; | 87 typedef std::map<std::string, Connection*> Registry; |
70 | 88 |
71 base::MessageLoop* adb_message_loop_; | 89 base::MessageLoop* adb_message_loop_; |
72 PrefService* pref_service_; | 90 PrefService* pref_service_; |
73 Registry registry_; | 91 Registry registry_; |
74 }; | 92 }; |
75 | 93 |
76 #endif // CHROME_BROWSER_DEVTOOLS_TETHERING_ADB_FILTER_H_ | 94 #endif // CHROME_BROWSER_DEVTOOLS_TETHERING_ADB_FILTER_H_ |
OLD | NEW |