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

Unified Diff: chrome/browser/devtools/android_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/android_device_provider.h
diff --git a/chrome/browser/devtools/android_device_provider.h b/chrome/browser/devtools/android_device_provider.h
new file mode 100644
index 0000000000000000000000000000000000000000..9cf69856b2bd5c9a01cfe60cf1205fdc5c11991e
--- /dev/null
+++ b/chrome/browser/devtools/android_device_provider.h
@@ -0,0 +1,94 @@
+// 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_ANDROID_DEVICE_PROVIDER_H_
+#define CHROME_BROWSER_DEVTOOLS_ANDROID_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 AndroidDeviceProvider
+ : public base::RefCountedThreadSafe<
+ AndroidDeviceProvider,
+ content::BrowserThread::DeleteOnUIThread> {
+ public:
+ typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices;
+ typedef base::Callback<void(const AndroidDevices&)> QueryDeviceCallback;
+
+ virtual void QueryDevices(const QueryDeviceCallback& callback) = 0;
+
+ static void CountDevices(bool discover_usb_devices,
+ const base::Callback<void(int)>& callback);
+
+ static scoped_refptr<AndroidDeviceProvider> GetAdbDeviceProvider();
+ static scoped_refptr<AndroidDeviceProvider>
+ GetUsbDeviceProvider(Profile* profile);
+
+ protected:
+ AndroidDeviceProvider();
+ virtual ~AndroidDeviceProvider();
+ void RunCallbackOnUIThread(const QueryDeviceCallback& callback,
+ const AndroidDevices& result);
+
+ friend struct
+ content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>;
+
+ friend class base::DeleteHelper<AndroidDeviceProvider>;
+
+ scoped_refptr<RefCountedAdbThread> adb_thread_;
+};
+
+#endif // CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_PROVIDER_H_

Powered by Google App Engine
This is Rietveld 408576698