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" |
11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
15 | 15 |
16 namespace net { | 16 namespace net { |
17 class StreamSocket; | 17 class StreamSocket; |
18 } | 18 } |
19 | 19 |
20 class AndroidDeviceManager | 20 class AndroidDeviceManager |
21 : public base::RefCountedThreadSafe< | 21 : public base::RefCountedThreadSafe< |
22 AndroidDeviceManager, | 22 AndroidDeviceManager, |
23 content::BrowserThread::DeleteOnUIThread>, | 23 content::BrowserThread::DeleteOnUIThread>, |
24 public base::NonThreadSafe { | 24 public base::NonThreadSafe { |
25 public: | 25 public: |
26 typedef base::Callback<void(int, const std::string&)> CommandCallback; | 26 typedef base::Callback<void(int, const std::string&)> CommandCallback; |
27 typedef base::Callback<void(int result, net::StreamSocket*)> SocketCallback; | 27 typedef base::Callback<void(int result, scoped_ptr<net::StreamSocket>)> |
| 28 SocketCallback; |
28 typedef base::Callback<void(const std::vector<std::string>&)> SerialsCallback; | 29 typedef base::Callback<void(const std::vector<std::string>&)> SerialsCallback; |
29 | 30 |
30 struct BrowserInfo { | 31 struct BrowserInfo { |
31 BrowserInfo(); | 32 BrowserInfo(); |
32 | 33 |
33 enum Type { | 34 enum Type { |
34 kTypeChrome, | 35 kTypeChrome, |
35 kTypeWebView, | 36 kTypeWebView, |
36 kTypeOther | 37 kTypeOther |
37 }; | 38 }; |
38 | 39 |
39 std::string socket_name; | 40 std::string socket_name; |
40 std::string display_name; | 41 std::string display_name; |
41 Type type; | 42 Type type; |
42 }; | 43 }; |
43 | 44 |
44 struct DeviceInfo { | 45 struct DeviceInfo { |
45 DeviceInfo(); | 46 DeviceInfo(); |
46 ~DeviceInfo(); | 47 ~DeviceInfo(); |
47 | 48 |
48 std::string model; | 49 std::string model; |
49 bool connected; | 50 bool connected; |
50 gfx::Size screen_size; | 51 gfx::Size screen_size; |
51 std::vector<BrowserInfo> browser_info; | 52 std::vector<BrowserInfo> browser_info; |
52 }; | 53 }; |
53 | 54 |
54 typedef base::Callback<void(const DeviceInfo&)> DeviceInfoCallback; | 55 typedef base::Callback<void(const DeviceInfo&)> DeviceInfoCallback; |
55 | 56 |
56 class AndroidWebSocket : public base::RefCountedThreadSafe<AndroidWebSocket> { | 57 class AndroidWebSocket { |
57 public: | 58 public: |
58 class Delegate { | 59 class Delegate { |
59 public: | 60 public: |
60 virtual void OnSocketOpened() = 0; | 61 virtual void OnSocketOpened() = 0; |
61 virtual void OnFrameRead(const std::string& message) = 0; | 62 virtual void OnFrameRead(const std::string& message) = 0; |
62 virtual void OnSocketClosed(bool closed_by_device) = 0; | 63 virtual void OnSocketClosed() = 0; |
63 | 64 |
64 protected: | 65 protected: |
65 virtual ~Delegate() {} | 66 virtual ~Delegate() {} |
66 }; | 67 }; |
67 | 68 |
68 AndroidWebSocket() {} | |
69 | |
70 virtual void Connect() = 0; | |
71 virtual void Disconnect() = 0; | |
72 virtual void SendFrame(const std::string& message) = 0; | |
73 virtual void ClearDelegate() = 0; | |
74 | |
75 protected: | |
76 virtual ~AndroidWebSocket() {} | 69 virtual ~AndroidWebSocket() {} |
77 | 70 |
78 private: | 71 virtual void SendFrame(const std::string& message) = 0; |
79 friend class base::RefCountedThreadSafe<AndroidWebSocket>; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(AndroidWebSocket); | |
82 }; | 72 }; |
83 | 73 |
84 class DeviceProvider; | 74 class DeviceProvider; |
85 | 75 |
86 class Device : public base::RefCountedThreadSafe<Device>, | 76 class Device : public base::RefCountedThreadSafe<Device>, |
87 public base::NonThreadSafe { | 77 public base::NonThreadSafe { |
88 public: | 78 public: |
89 typedef AndroidDeviceManager::DeviceInfoCallback DeviceInfoCallback; | 79 typedef AndroidDeviceManager::DeviceInfoCallback DeviceInfoCallback; |
90 typedef AndroidDeviceManager::CommandCallback CommandCallback; | 80 typedef AndroidDeviceManager::CommandCallback CommandCallback; |
91 typedef AndroidDeviceManager::SocketCallback SocketCallback; | 81 typedef AndroidDeviceManager::SocketCallback SocketCallback; |
92 | 82 |
93 void QueryDeviceInfo(const DeviceInfoCallback& callback); | 83 void QueryDeviceInfo(const DeviceInfoCallback& callback); |
94 | 84 |
95 void OpenSocket(const std::string& socket_name, | 85 void OpenSocket(const std::string& socket_name, |
96 const SocketCallback& callback); | 86 const SocketCallback& callback); |
97 | 87 |
98 void SendJsonRequest(const std::string& socket_name, | 88 void SendJsonRequest(const std::string& socket_name, |
99 const std::string& request, | 89 const std::string& request, |
100 const CommandCallback& callback); | 90 const CommandCallback& callback); |
101 | 91 |
102 void HttpUpgrade(const std::string& socket_name, | 92 void HttpUpgrade(const std::string& socket_name, |
103 const std::string& url, | 93 const std::string& url, |
104 const SocketCallback& callback); | 94 const SocketCallback& callback); |
105 | 95 |
106 scoped_refptr<AndroidWebSocket> CreateWebSocket( | 96 AndroidWebSocket* CreateWebSocket( |
107 const std::string& socket_name, | 97 const std::string& socket_name, |
108 const std::string& url, | 98 const std::string& url, |
109 AndroidWebSocket::Delegate* delegate); | 99 AndroidWebSocket::Delegate* delegate); |
110 | 100 |
111 std::string serial() { return serial_; } | 101 std::string serial() { return serial_; } |
112 | 102 |
113 private: | 103 private: |
114 friend class AndroidDeviceManager; | 104 friend class AndroidDeviceManager; |
115 Device(scoped_refptr<base::MessageLoopProxy> device_message_loop, | 105 Device(scoped_refptr<base::MessageLoopProxy> device_message_loop, |
116 scoped_refptr<DeviceProvider> provider, | 106 scoped_refptr<DeviceProvider> provider, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 DeviceDescriptors* descriptors); | 198 DeviceDescriptors* descriptors); |
209 | 199 |
210 typedef std::map<std::string, base::WeakPtr<Device> > DeviceWeakMap; | 200 typedef std::map<std::string, base::WeakPtr<Device> > DeviceWeakMap; |
211 | 201 |
212 scoped_refptr<HandlerThread> handler_thread_; | 202 scoped_refptr<HandlerThread> handler_thread_; |
213 DeviceProviders providers_; | 203 DeviceProviders providers_; |
214 DeviceWeakMap devices_; | 204 DeviceWeakMap devices_; |
215 }; | 205 }; |
216 | 206 |
217 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_ANDROID_DEVICE_MANAGER_H_ | 207 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_ANDROID_DEVICE_MANAGER_H_ |
OLD | NEW |