- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / devtools / android_device.h
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.
4
5 #ifndef CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_H_
6 #define CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_H_
7
8 #include <vector>
9
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"
17
18 class AndroidDevice : public base::RefCounted<AndroidDevice> {
19  public:
20   typedef base::Callback<void(int, const std::string&)> CommandCallback;
21   typedef base::Callback<void(int result, net::StreamSocket*)> SocketCallback;
22
23   AndroidDevice(const std::string& serial, bool is_connected);
24
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);
35
36   std::string serial() { return serial_; }
37   bool is_connected() { return is_connected_; }
38
39   std::string model() { return model_; }
40   void set_model(const std::string& model) { model_ = model; }
41
42  protected:
43   friend class base::RefCounted<AndroidDevice>;
44   virtual ~AndroidDevice();
45
46  private:
47   void OnHttpSocketOpened(const std::string& request,
48                           const CommandCallback& callback,
49                           int result,
50                           net::StreamSocket* socket);
51   void OnHttpSocketOpened2(const std::string& request,
52                            const SocketCallback& callback,
53                            int result,
54                            net::StreamSocket* socket);
55
56   std::string serial_;
57   bool is_connected_;
58   std::string model_;
59
60   DISALLOW_COPY_AND_ASSIGN(AndroidDevice);
61 };
62
63
64 class AndroidDeviceProvider
65     : public base::RefCountedThreadSafe<
66           AndroidDeviceProvider,
67           content::BrowserThread::DeleteOnUIThread> {
68  public:
69   typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices;
70   typedef base::Callback<void(const AndroidDevices&)> QueryDevicesCallback;
71
72   virtual void QueryDevices(const QueryDevicesCallback& callback) = 0;
73
74   static void CountDevices(bool discover_usb_devices,
75                            const  base::Callback<void(int)>& callback);
76
77   static scoped_refptr<AndroidDeviceProvider> GetAdbDeviceProvider();
78   static scoped_refptr<AndroidDeviceProvider>
79       GetUsbDeviceProvider(Profile* profile);
80
81  protected:
82   friend struct
83       content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>;
84   friend class base::DeleteHelper<AndroidDeviceProvider>;
85
86   AndroidDeviceProvider();
87   virtual ~AndroidDeviceProvider();
88   static void RunCallbackOnUIThread(const QueryDevicesCallback& callback,
89                                     const AndroidDevices& result);
90
91   scoped_refptr<RefCountedAdbThread> adb_thread_;
92 };
93
94 #endif  // CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_H_