Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: chrome/browser/devtools/devtools_device_provider.h

Issue 26568004: Introduced AndroidDeviceProvider to simplify testing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed all the comments. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c60101ebaba523b46b5d60716d7a1d953567fbd5
--- /dev/null
+++ b/chrome/browser/devtools/devtools_device_provider.h
@@ -0,0 +1,117 @@
+// 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 <vector>
+
+#include "base/memory/ref_counted.h"
+#include "chrome/browser/devtools/adb/android_usb_device.h"
+#include "chrome/browser/devtools/refcounted_adb_thread.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"
+
+class AndroidDevice : public base::RefCounted<AndroidDevice> {
+ public:
+ typedef base::Callback<void(int, const std::string&)> CommandCallback;
+ typedef base::Callback<void(int result, net::StreamSocket*)> SocketCallback;
+
+ explicit AndroidDevice(const std::string& serial);
+
+ virtual void RunCommand(const std::string& command,
+ const CommandCallback& callback) = 0;
+ virtual void OpenSocket(const std::string& socket_name,
+ const SocketCallback& callback) = 0;
+ virtual bool IsConnected() = 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_; }
+ 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(AndroidDevice);
+};
+
+
+class DevToolsDeviceProvider
Vladislav Kaznacheev 2013/10/17 20:17:37 AndroidDeviceProvider is much more suitable name
Dmitry Zvorygin 2013/10/21 07:40:29 Done.
+ : public base::RefCountedThreadSafe<
+ DevToolsDeviceProvider,
+ content::BrowserThread::DeleteOnUIThread> {
+ public:
+ typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices;
+ typedef base::Callback<void(const AndroidDevices&)> QueryDeviceCallback;
+
+
Vladislav Kaznacheev 2013/10/17 20:17:37 extra blank line
Dmitry Zvorygin 2013/10/21 07:40:29 Done.
+ virtual void QueryDevices(const QueryDeviceCallback& callback) = 0;
+
+ protected:
+ virtual ~DevToolsDeviceProvider();
+ void RunCallbackOnUIThread(const QueryDeviceCallback& callback,
+ const AndroidDevices& result);
+
+ friend struct
+ content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>;
+
+ friend class base::DeleteHelper<DevToolsDeviceProvider>;
+};
+
+class UsbDeviceProvider: public DevToolsDeviceProvider {
Vladislav Kaznacheev 2013/10/17 20:17:37 It could be a good idea to hide the two implementa
Dmitry Zvorygin 2013/10/21 07:40:29 Done.
+ public:
+ explicit UsbDeviceProvider(Profile* profile,
+ scoped_refptr<RefCountedAdbThread> adb_thread);
+
+ virtual void QueryDevices(const QueryDeviceCallback& callback) OVERRIDE;
+ private:
+ virtual ~UsbDeviceProvider();
+ void WrapDevicesOnAdbThread(const QueryDeviceCallback& callback,
+ const AndroidUsbDevices& devices);
+ void EnumeratedDevices(const QueryDeviceCallback& callback,
+ const AndroidUsbDevices& devices);
+
+ 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 QueryDevicesOnAdbThread(const QueryDeviceCallback& callback);
+ 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_

Powered by Google App Engine
This is Rietveld 408576698