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