Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / devtools / android_device.h
blob41d810eea1f575c2d51a59f3aab81d966a41ea20
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_
8 #include <vector>
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> {
19 public:
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; }
42 protected:
43 friend class base::RefCounted<AndroidDevice>;
44 virtual ~AndroidDevice();
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);
56 std::string serial_;
57 bool is_connected_;
58 std::string model_;
60 DISALLOW_COPY_AND_ASSIGN(AndroidDevice);
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;
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);
80 #if defined(DEBUG_DEVTOOLS)
81 static scoped_refptr<AndroidDeviceProvider> GetSelfAsDeviceProvider();
82 #endif
84 protected:
85 friend struct
86 content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>;
87 friend class base::DeleteHelper<AndroidDeviceProvider>;
89 AndroidDeviceProvider();
90 virtual ~AndroidDeviceProvider();
91 static void RunCallbackOnUIThread(const QueryDevicesCallback& callback,
92 const AndroidDevices& result);
94 scoped_refptr<RefCountedAdbThread> adb_thread_;
97 #endif // CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_H_