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

Side by Side 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 minor 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_ANDROID_DEVICE_PROVIDER_H_
6 #define CHROME_BROWSER_DEVTOOLS_ANDROID_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 AndroidDeviceProvider
64 : public base::RefCountedThreadSafe<
65 AndroidDeviceProvider,
66 content::BrowserThread::DeleteOnUIThread> {
67 public:
68 typedef std::vector<scoped_refptr<AndroidDevice> > AndroidDevices;
69 typedef base::Callback<void(const AndroidDevices&)> QueryDeviceCallback;
Vladislav Kaznacheev 2013/10/22 08:34:35 QueryDevicesCallback name makes more sense
Dmitry Zvorygin 2013/10/22 09:07:56 Done.
70
71 virtual void QueryDevices(const QueryDeviceCallback& callback) = 0;
72
73 static void CountDevices(bool discover_usb_devices,
74 const base::Callback<void(int)>& callback);
75
76 static scoped_refptr<AndroidDeviceProvider> GetAdbDeviceProvider();
77 static scoped_refptr<AndroidDeviceProvider>
78 GetUsbDeviceProvider(Profile* profile);
79
80 protected:
81 AndroidDeviceProvider();
82 virtual ~AndroidDeviceProvider();
83 void RunCallbackOnUIThread(const QueryDeviceCallback& callback,
84 const AndroidDevices& result);
85
86 friend struct
Vladislav Kaznacheev 2013/10/22 08:34:35 Please put the friend declarations right at the to
Dmitry Zvorygin 2013/10/22 09:07:56 Done.
87 content::BrowserThread::DeleteOnThread<content::BrowserThread::UI>;
88
89 friend class base::DeleteHelper<AndroidDeviceProvider>;
90
91 scoped_refptr<RefCountedAdbThread> adb_thread_;
92 };
93
94 #endif // CHROME_BROWSER_DEVTOOLS_ANDROID_DEVICE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698