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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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_DEVTOOLS_DEVICE_PROVIDER_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DEVICE_PROVIDER_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 explicit AndroidDevice(const std::string& serial);
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 bool IsConnected() = 0;
30 void HttpQuery(const std::string& la_name,
31 const std::string& request,
32 const CommandCallback& callback);
33 void HttpUpgrade(const std::string& la_name,
34 const std::string& request,
35 const SocketCallback& callback);
36
37 std::string serial() { return serial_; }
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 std::string model_;
58
59 DISALLOW_COPY_AND_ASSIGN(AndroidDevice);
60 };
61
62
63 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.
64 : public base::RefCountedThreadSafe<
65 DevToolsDeviceProvider,
66 content::BrowserThread::DeleteOnUIThread> {
67 public:
68 typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices;
69 typedef base::Callback<void(const AndroidDevices&)> QueryDeviceCallback;
70
71
Vladislav Kaznacheev 2013/10/17 20:17:37 extra blank line
Dmitry Zvorygin 2013/10/21 07:40:29 Done.
72 virtual void QueryDevices(const QueryDeviceCallback& callback) = 0;
73
74 protected:
75 virtual ~DevToolsDeviceProvider();
76 void RunCallbackOnUIThread(const QueryDeviceCallback& callback,
77 const AndroidDevices& result);
78
79 friend struct
80 content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>;
81
82 friend class base::DeleteHelper<DevToolsDeviceProvider>;
83 };
84
85 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.
86 public:
87 explicit UsbDeviceProvider(Profile* profile,
88 scoped_refptr<RefCountedAdbThread> adb_thread);
89
90 virtual void QueryDevices(const QueryDeviceCallback& callback) OVERRIDE;
91 private:
92 virtual ~UsbDeviceProvider();
93 void WrapDevicesOnAdbThread(const QueryDeviceCallback& callback,
94 const AndroidUsbDevices& devices);
95 void EnumeratedDevices(const QueryDeviceCallback& callback,
96 const AndroidUsbDevices& devices);
97
98 scoped_refptr<RefCountedAdbThread> adb_thread_;
99 scoped_ptr<crypto::RSAPrivateKey> rsa_key_;
100 };
101
102 class AdbDeviceProvider: public DevToolsDeviceProvider {
103 public:
104 explicit AdbDeviceProvider(scoped_refptr<RefCountedAdbThread> adb_thread);
105
106 virtual void QueryDevices(const QueryDeviceCallback& callback) OVERRIDE;
107 private:
108 void QueryDevicesOnAdbThread(const QueryDeviceCallback& callback);
109 void ReceivedAdbDevices(const QueryDeviceCallback& callback, int result,
110 const std::string& response);
111
112 virtual ~AdbDeviceProvider();
113
114 scoped_refptr<RefCountedAdbThread> adb_thread_;
115 };
116
117 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_DEVICE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698