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 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_ANDROID_DEVICE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_ANDROID_DEVICE_MANAGER_H_ |
6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_ANDROID_DEVICE_MANAGER_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_ANDROID_DEVICE_MANAGER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 DeviceInfo(); | 46 DeviceInfo(); |
47 ~DeviceInfo(); | 47 ~DeviceInfo(); |
48 | 48 |
49 std::string model; | 49 std::string model; |
50 bool connected; | 50 bool connected; |
51 gfx::Size screen_size; | 51 gfx::Size screen_size; |
52 std::vector<BrowserInfo> browser_info; | 52 std::vector<BrowserInfo> browser_info; |
53 }; | 53 }; |
54 | 54 |
55 typedef base::Callback<void(const DeviceInfo&)> DeviceInfoCallback; | 55 typedef base::Callback<void(const DeviceInfo&)> DeviceInfoCallback; |
| 56 class Device; |
56 | 57 |
57 class AndroidWebSocket { | 58 class AndroidWebSocket { |
58 public: | 59 public: |
59 class Delegate { | 60 class Delegate { |
60 public: | 61 public: |
61 virtual void OnSocketOpened() = 0; | 62 virtual void OnSocketOpened() = 0; |
62 virtual void OnFrameRead(const std::string& message) = 0; | 63 virtual void OnFrameRead(const std::string& message) = 0; |
63 virtual void OnSocketClosed() = 0; | 64 virtual void OnSocketClosed() = 0; |
64 | 65 |
65 protected: | 66 protected: |
66 virtual ~Delegate() {} | 67 virtual ~Delegate() {} |
67 }; | 68 }; |
68 | 69 |
69 virtual ~AndroidWebSocket() {} | 70 ~AndroidWebSocket(); |
70 | 71 |
71 virtual void SendFrame(const std::string& message) = 0; | 72 void SendFrame(const std::string& message); |
| 73 |
| 74 private: |
| 75 friend class Device; |
| 76 class WebSocketImpl; |
| 77 |
| 78 AndroidWebSocket( |
| 79 scoped_refptr<Device> device, |
| 80 const std::string& socket_name, |
| 81 const std::string& url, |
| 82 AndroidWebSocket::Delegate* delegate); |
| 83 void Connected(int result, scoped_ptr<net::StreamSocket> socket); |
| 84 void OnFrameRead(const std::string& message); |
| 85 void OnSocketClosed(); |
| 86 |
| 87 scoped_refptr<Device> device_; |
| 88 WebSocketImpl* socket_impl_; |
| 89 Delegate* delegate_; |
| 90 base::WeakPtrFactory<AndroidWebSocket> weak_factory_; |
| 91 DISALLOW_COPY_AND_ASSIGN(AndroidWebSocket); |
72 }; | 92 }; |
73 | 93 |
74 class DeviceProvider; | 94 class DeviceProvider; |
75 | 95 |
76 class Device : public base::RefCountedThreadSafe<Device>, | 96 class Device : public base::RefCountedThreadSafe<Device>, |
77 public base::NonThreadSafe { | 97 public base::NonThreadSafe { |
78 public: | 98 public: |
79 typedef AndroidDeviceManager::DeviceInfoCallback DeviceInfoCallback; | |
80 typedef AndroidDeviceManager::CommandCallback CommandCallback; | |
81 typedef AndroidDeviceManager::SocketCallback SocketCallback; | |
82 | |
83 void QueryDeviceInfo(const DeviceInfoCallback& callback); | 99 void QueryDeviceInfo(const DeviceInfoCallback& callback); |
84 | 100 |
85 void OpenSocket(const std::string& socket_name, | 101 void OpenSocket(const std::string& socket_name, |
86 const SocketCallback& callback); | 102 const SocketCallback& callback); |
87 | 103 |
88 void SendJsonRequest(const std::string& socket_name, | 104 void SendJsonRequest(const std::string& socket_name, |
89 const std::string& request, | 105 const std::string& request, |
90 const CommandCallback& callback); | 106 const CommandCallback& callback); |
91 | 107 |
92 void HttpUpgrade(const std::string& socket_name, | 108 void HttpUpgrade(const std::string& socket_name, |
93 const std::string& url, | 109 const std::string& url, |
94 const SocketCallback& callback); | 110 const SocketCallback& callback); |
95 | |
96 AndroidWebSocket* CreateWebSocket( | 111 AndroidWebSocket* CreateWebSocket( |
97 const std::string& socket_name, | 112 const std::string& socket_name, |
98 const std::string& url, | 113 const std::string& url, |
99 AndroidWebSocket::Delegate* delegate); | 114 AndroidWebSocket::Delegate* delegate); |
100 | 115 |
101 std::string serial() { return serial_; } | 116 std::string serial() { return serial_; } |
102 | 117 |
103 private: | 118 private: |
| 119 friend class base::RefCountedThreadSafe<Device>; |
104 friend class AndroidDeviceManager; | 120 friend class AndroidDeviceManager; |
| 121 friend class AndroidWebSocket; |
| 122 |
105 Device(scoped_refptr<base::MessageLoopProxy> device_message_loop, | 123 Device(scoped_refptr<base::MessageLoopProxy> device_message_loop, |
106 scoped_refptr<DeviceProvider> provider, | 124 scoped_refptr<DeviceProvider> provider, |
107 const std::string& serial); | 125 const std::string& serial); |
108 | 126 |
109 friend class base::RefCountedThreadSafe<Device>; | |
110 virtual ~Device(); | 127 virtual ~Device(); |
111 | 128 |
112 scoped_refptr<base::MessageLoopProxy> device_message_loop_; | 129 scoped_refptr<base::MessageLoopProxy> device_message_loop_; |
113 scoped_refptr<DeviceProvider> provider_; | 130 scoped_refptr<DeviceProvider> provider_; |
114 std::string serial_; | 131 std::string serial_; |
115 base::WeakPtrFactory<Device> weak_factory_; | 132 base::WeakPtrFactory<Device> weak_factory_; |
116 | 133 |
117 DISALLOW_COPY_AND_ASSIGN(Device); | 134 DISALLOW_COPY_AND_ASSIGN(Device); |
118 }; | 135 }; |
119 | 136 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 DeviceDescriptors* descriptors); | 215 DeviceDescriptors* descriptors); |
199 | 216 |
200 typedef std::map<std::string, base::WeakPtr<Device> > DeviceWeakMap; | 217 typedef std::map<std::string, base::WeakPtr<Device> > DeviceWeakMap; |
201 | 218 |
202 scoped_refptr<HandlerThread> handler_thread_; | 219 scoped_refptr<HandlerThread> handler_thread_; |
203 DeviceProviders providers_; | 220 DeviceProviders providers_; |
204 DeviceWeakMap devices_; | 221 DeviceWeakMap devices_; |
205 }; | 222 }; |
206 | 223 |
207 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_ANDROID_DEVICE_MANAGER_H_ | 224 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_ANDROID_DEVICE_MANAGER_H_ |
OLD | NEW |