OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DEVICE_PROVIDER_H_ | |
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DEVICE_PROVIDER_H_ | |
7 | |
8 #include "base/memory/ref_counted.h" | |
9 #include "chrome/browser/devtools/adb/android_usb_device.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "content/public/browser/browser_thread.h" | |
12 #include "crypto/rsa_private_key.h" | |
13 #include "net/socket/stream_socket.h" | |
14 | |
15 typedef base::Callback<void(int, const std::string&)> CommandCallback; | |
16 typedef base::Callback<void(int result, net::StreamSocket*)> SocketCallback; | |
Vladislav Kaznacheev
2013/10/16 11:27:04
Please do not declare these in a global namespace
Dmitry Zvorygin
2013/10/17 16:19:37
Done.
You have had them previously declared in gl
| |
17 | |
18 class RefCountedAdbThread : public base::RefCounted<RefCountedAdbThread> { | |
Vladislav Kaznacheev
2013/10/16 11:27:04
This deserves a separate header
Dmitry Zvorygin
2013/10/17 16:19:37
Done.
| |
19 public: | |
20 static scoped_refptr<RefCountedAdbThread> GetInstance(); | |
21 base::MessageLoop* message_loop(); | |
22 | |
23 private: | |
24 friend class base::RefCounted<RefCountedAdbThread>; | |
25 static RefCountedAdbThread* instance_; | |
26 static void StopThread(base::Thread* thread); | |
27 | |
28 RefCountedAdbThread(); | |
29 virtual ~RefCountedAdbThread(); | |
30 base::Thread* thread_; | |
31 }; | |
32 | |
33 class AndroidDevice : public base::RefCounted<AndroidDevice> { | |
34 public: | |
35 explicit AndroidDevice(const std::string& serial, | |
36 scoped_refptr<RefCountedAdbThread> adb_thread); | |
37 | |
38 virtual void RunCommand(const std::string& command, | |
39 const CommandCallback& callback) = 0; | |
40 virtual void OpenSocket(const std::string& socket_name, | |
41 const SocketCallback& callback) = 0; | |
42 void HttpQuery(const std::string& la_name, | |
43 const std::string& request, | |
44 const CommandCallback& callback); | |
45 void HttpUpgrade(const std::string& la_name, | |
46 const std::string& request, | |
47 const SocketCallback& callback); | |
48 | |
49 std::string serial() { return serial_; } | |
50 | |
51 std::string model() { return model_; } | |
52 | |
53 base::MessageLoop* message_loop() { return adb_thread_->message_loop(); } | |
54 | |
55 void set_model(const std::string& model) { model_ = model; } | |
56 | |
57 protected: | |
58 friend class base::RefCounted<AndroidDevice>; | |
59 virtual ~AndroidDevice(); | |
60 | |
61 private: | |
62 void OnHttpSocketOpened(const std::string& request, | |
63 const CommandCallback& callback, | |
64 int result, | |
65 net::StreamSocket* socket); | |
66 void OnHttpSocketOpened2(const std::string& request, | |
67 const SocketCallback& callback, | |
68 int result, | |
69 net::StreamSocket* socket); | |
70 | |
71 std::string serial_; | |
72 std::string model_; | |
73 | |
74 scoped_refptr<RefCountedAdbThread> adb_thread_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(AndroidDevice); | |
77 }; | |
78 | |
79 typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices; | |
80 typedef base::Callback<void(const AndroidDevices&)> QueryDeviceCallback; | |
81 | |
82 class DevToolsDeviceProvider | |
83 : public base::RefCountedThreadSafe< | |
84 DevToolsDeviceProvider, | |
85 content::BrowserThread::DeleteOnUIThread> { | |
86 | |
87 public: | |
88 typedef base::Callback<void(int, | |
89 const AndroidDevices&)> QueryDevicesCallback; | |
90 | |
91 virtual void QueryDevices(const QueryDeviceCallback& callback) = 0; | |
92 | |
93 protected: | |
94 virtual ~DevToolsDeviceProvider() {} | |
95 | |
96 friend struct | |
97 content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>; | |
98 | |
99 friend class base::DeleteHelper<DevToolsDeviceProvider>; | |
100 }; | |
101 | |
102 class UsbDeviceProvider: public DevToolsDeviceProvider { | |
103 public: | |
104 explicit UsbDeviceProvider(Profile* profile, | |
105 scoped_refptr<RefCountedAdbThread> adb_thread); | |
106 | |
107 virtual void QueryDevices(const QueryDeviceCallback& callback) OVERRIDE; | |
108 private: | |
109 virtual ~UsbDeviceProvider(); | |
110 void EnumeratedDevices(const QueryDeviceCallback& callback, | |
111 const AndroidUsbDevices& devices); | |
112 void RunCallbackOnAdbThread(const QueryDeviceCallback& callback, | |
113 const AndroidDevices& result); | |
114 | |
115 scoped_refptr<RefCountedAdbThread> adb_thread_; | |
116 scoped_ptr<crypto::RSAPrivateKey> rsa_key_; | |
117 }; | |
118 | |
119 class AdbDeviceProvider: public DevToolsDeviceProvider { | |
120 public: | |
121 explicit AdbDeviceProvider(scoped_refptr<RefCountedAdbThread> adb_thread); | |
122 | |
123 virtual void QueryDevices(const QueryDeviceCallback& callback) OVERRIDE; | |
124 private: | |
125 void ReceivedAdbDevices(const QueryDeviceCallback& callback, int result, | |
126 const std::string& response); | |
127 | |
128 virtual ~AdbDeviceProvider(); | |
129 | |
130 scoped_refptr<RefCountedAdbThread> adb_thread_; | |
131 }; | |
132 | |
133 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DEVICE_PROVIDER_H_ | |
OLD | NEW |