1 // Copyright 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.
5 #ifndef CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_H_
6 #define CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_H_
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/devtools/adb/android_usb_device.h"
12 #include "chrome/browser/devtools/refcounted_adb_thread.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "crypto/rsa_private_key.h"
16 #include "net/socket/stream_socket.h"
18 class AndroidDevice : public base::RefCounted<AndroidDevice> {
20 typedef base::Callback<void(int, const std::string&)> CommandCallback;
21 typedef base::Callback<void(int result, net::StreamSocket*)> SocketCallback;
23 AndroidDevice(const std::string& serial, bool is_connected);
25 virtual void RunCommand(const std::string& command,
26 const CommandCallback& callback) = 0;
27 virtual void OpenSocket(const std::string& socket_name,
28 const SocketCallback& callback) = 0;
29 virtual void HttpQuery(const std::string& la_name,
30 const std::string& request,
31 const CommandCallback& callback);
32 void HttpUpgrade(const std::string& la_name,
33 const std::string& request,
34 const SocketCallback& callback);
36 std::string serial() { return serial_; }
37 bool is_connected() { return is_connected_; }
39 std::string model() { return model_; }
40 void set_model(const std::string& model) { model_ = model; }
43 friend class base::RefCounted<AndroidDevice>;
44 virtual ~AndroidDevice();
47 void OnHttpSocketOpened(const std::string& request,
48 const CommandCallback& callback,
50 net::StreamSocket* socket);
51 void OnHttpSocketOpened2(const std::string& request,
52 const SocketCallback& callback,
54 net::StreamSocket* socket);
60 DISALLOW_COPY_AND_ASSIGN(AndroidDevice);
64 class AndroidDeviceProvider
65 : public base::RefCountedThreadSafe<
66 AndroidDeviceProvider,
67 content::BrowserThread::DeleteOnUIThread> {
69 typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices;
70 typedef base::Callback<void(const AndroidDevices&)> QueryDevicesCallback;
72 virtual void QueryDevices(const QueryDevicesCallback& callback) = 0;
74 static void CountDevices(bool discover_usb_devices,
75 const base::Callback<void(int)>& callback);
77 static scoped_refptr<AndroidDeviceProvider> GetAdbDeviceProvider();
78 static scoped_refptr<AndroidDeviceProvider>
79 GetUsbDeviceProvider(Profile* profile);
83 content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>;
84 friend class base::DeleteHelper<AndroidDeviceProvider>;
86 AndroidDeviceProvider();
87 virtual ~AndroidDeviceProvider();
88 static void RunCallbackOnUIThread(const QueryDevicesCallback& callback,
89 const AndroidDevices& result);
91 scoped_refptr<RefCountedAdbThread> adb_thread_;
94 #endif // CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_H_