Index: chrome/browser/devtools/devtools_device_provider.h |
diff --git a/chrome/browser/devtools/devtools_device_provider.h b/chrome/browser/devtools/devtools_device_provider.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0abb8572be723299a5663a0686d458fed8aaaef4 |
--- /dev/null |
+++ b/chrome/browser/devtools/devtools_device_provider.h |
@@ -0,0 +1,133 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DEVICE_PROVIDER_H_ |
+#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DEVICE_PROVIDER_H_ |
+ |
+#include "base/memory/ref_counted.h" |
+#include "chrome/browser/devtools/adb/android_usb_device.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "crypto/rsa_private_key.h" |
+#include "net/socket/stream_socket.h" |
+ |
+typedef base::Callback<void(int, const std::string&)> CommandCallback; |
+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
|
+ |
+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.
|
+ public: |
+ static scoped_refptr<RefCountedAdbThread> GetInstance(); |
+ base::MessageLoop* message_loop(); |
+ |
+ private: |
+ friend class base::RefCounted<RefCountedAdbThread>; |
+ static RefCountedAdbThread* instance_; |
+ static void StopThread(base::Thread* thread); |
+ |
+ RefCountedAdbThread(); |
+ virtual ~RefCountedAdbThread(); |
+ base::Thread* thread_; |
+}; |
+ |
+class AndroidDevice : public base::RefCounted<AndroidDevice> { |
+ public: |
+ explicit AndroidDevice(const std::string& serial, |
+ scoped_refptr<RefCountedAdbThread> adb_thread); |
+ |
+ virtual void RunCommand(const std::string& command, |
+ const CommandCallback& callback) = 0; |
+ virtual void OpenSocket(const std::string& socket_name, |
+ const SocketCallback& callback) = 0; |
+ void HttpQuery(const std::string& la_name, |
+ const std::string& request, |
+ const CommandCallback& callback); |
+ void HttpUpgrade(const std::string& la_name, |
+ const std::string& request, |
+ const SocketCallback& callback); |
+ |
+ std::string serial() { return serial_; } |
+ |
+ std::string model() { return model_; } |
+ |
+ base::MessageLoop* message_loop() { return adb_thread_->message_loop(); } |
+ |
+ void set_model(const std::string& model) { model_ = model; } |
+ |
+ protected: |
+ friend class base::RefCounted<AndroidDevice>; |
+ virtual ~AndroidDevice(); |
+ |
+ private: |
+ void OnHttpSocketOpened(const std::string& request, |
+ const CommandCallback& callback, |
+ int result, |
+ net::StreamSocket* socket); |
+ void OnHttpSocketOpened2(const std::string& request, |
+ const SocketCallback& callback, |
+ int result, |
+ net::StreamSocket* socket); |
+ |
+ std::string serial_; |
+ std::string model_; |
+ |
+ scoped_refptr<RefCountedAdbThread> adb_thread_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AndroidDevice); |
+}; |
+ |
+typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices; |
+typedef base::Callback<void(const AndroidDevices&)> QueryDeviceCallback; |
+ |
+class DevToolsDeviceProvider |
+ : public base::RefCountedThreadSafe< |
+ DevToolsDeviceProvider, |
+ content::BrowserThread::DeleteOnUIThread> { |
+ |
+ public: |
+ typedef base::Callback<void(int, |
+ const AndroidDevices&)> QueryDevicesCallback; |
+ |
+ virtual void QueryDevices(const QueryDeviceCallback& callback) = 0; |
+ |
+ protected: |
+ virtual ~DevToolsDeviceProvider() {} |
+ |
+ friend struct |
+ content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>; |
+ |
+ friend class base::DeleteHelper<DevToolsDeviceProvider>; |
+}; |
+ |
+class UsbDeviceProvider: public DevToolsDeviceProvider { |
+ public: |
+ explicit UsbDeviceProvider(Profile* profile, |
+ scoped_refptr<RefCountedAdbThread> adb_thread); |
+ |
+ virtual void QueryDevices(const QueryDeviceCallback& callback) OVERRIDE; |
+ private: |
+ virtual ~UsbDeviceProvider(); |
+ void EnumeratedDevices(const QueryDeviceCallback& callback, |
+ const AndroidUsbDevices& devices); |
+ void RunCallbackOnAdbThread(const QueryDeviceCallback& callback, |
+ const AndroidDevices& result); |
+ |
+ scoped_refptr<RefCountedAdbThread> adb_thread_; |
+ scoped_ptr<crypto::RSAPrivateKey> rsa_key_; |
+}; |
+ |
+class AdbDeviceProvider: public DevToolsDeviceProvider { |
+ public: |
+ explicit AdbDeviceProvider(scoped_refptr<RefCountedAdbThread> adb_thread); |
+ |
+ virtual void QueryDevices(const QueryDeviceCallback& callback) OVERRIDE; |
+ private: |
+ void ReceivedAdbDevices(const QueryDeviceCallback& callback, int result, |
+ const std::string& response); |
+ |
+ virtual ~AdbDeviceProvider(); |
+ |
+ scoped_refptr<RefCountedAdbThread> adb_thread_; |
+}; |
+ |
+#endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DEVICE_PROVIDER_H_ |