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

Side by Side Diff: chrome/browser/devtools/device/devtools_android_bridge.h

Issue 2253683002: [DevTools] Introduce a target discovery preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments were addressed. Created 4 years, 4 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
« no previous file with comments | « no previous file | chrome/browser/devtools/device/devtools_android_bridge.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ 6 #define CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 19 matching lines...) Expand all
30 class Thread; 30 class Thread;
31 } // namespace base 31 } // namespace base
32 32
33 namespace content { 33 namespace content {
34 class BrowserContext; 34 class BrowserContext;
35 } 35 }
36 36
37 class DevToolsTargetImpl; 37 class DevToolsTargetImpl;
38 class PortForwardingController; 38 class PortForwardingController;
39 class Profile; 39 class Profile;
40 class TCPDeviceProvider;
40 41
41 class DevToolsAndroidBridge : public KeyedService { 42 class DevToolsAndroidBridge : public KeyedService {
42 public: 43 public:
43 class Factory : public BrowserContextKeyedServiceFactory { 44 class Factory : public BrowserContextKeyedServiceFactory {
44 public: 45 public:
45 // Returns singleton instance of DevToolsAndroidBridge. 46 // Returns singleton instance of DevToolsAndroidBridge.
46 static Factory* GetInstance(); 47 static Factory* GetInstance();
47 48
48 // Returns DevToolsAndroidBridge associated with |profile|. 49 // Returns DevToolsAndroidBridge associated with |profile|.
49 static DevToolsAndroidBridge* GetForProfile(Profile* profile); 50 static DevToolsAndroidBridge* GetForProfile(Profile* profile);
50 51
51 private: 52 private:
52 friend struct base::DefaultSingletonTraits<Factory>; 53 friend struct base::DefaultSingletonTraits<Factory>;
53 54
54 Factory(); 55 Factory();
55 ~Factory() override; 56 ~Factory() override;
56 57
57 // BrowserContextKeyedServiceFactory overrides: 58 // BrowserContextKeyedServiceFactory overrides:
58 KeyedService* BuildServiceInstanceFor( 59 KeyedService* BuildServiceInstanceFor(
59 content::BrowserContext* context) const override; 60 content::BrowserContext* context) const override;
60 DISALLOW_COPY_AND_ASSIGN(Factory); 61 DISALLOW_COPY_AND_ASSIGN(Factory);
61 }; 62 };
62 63
63 typedef std::pair<std::string, std::string> BrowserId; 64 using BrowserId = std::pair<std::string, std::string>;
64 65
65 class RemotePage : public base::RefCounted<RemotePage> { 66 class RemotePage : public base::RefCounted<RemotePage> {
66 public: 67 public:
67 const std::string& serial() { return browser_id_.first; } 68 const std::string& serial() { return browser_id_.first; }
68 const std::string& socket() { return browser_id_.second; } 69 const std::string& socket() { return browser_id_.second; }
69 const std::string& frontend_url() { return frontend_url_; } 70 const std::string& frontend_url() { return frontend_url_; }
70 71
71 private: 72 private:
72 friend class base::RefCounted<RemotePage>; 73 friend class base::RefCounted<RemotePage>;
73 friend class DevToolsAndroidBridge; 74 friend class DevToolsAndroidBridge;
74 75
75 RemotePage(const BrowserId& browser_id, const base::DictionaryValue& dict); 76 RemotePage(const BrowserId& browser_id, const base::DictionaryValue& dict);
76 77
77 virtual ~RemotePage(); 78 virtual ~RemotePage();
78 79
79 BrowserId browser_id_; 80 BrowserId browser_id_;
80 std::string frontend_url_; 81 std::string frontend_url_;
81 std::unique_ptr<base::DictionaryValue> dict_; 82 std::unique_ptr<base::DictionaryValue> dict_;
82 83
83 DISALLOW_COPY_AND_ASSIGN(RemotePage); 84 DISALLOW_COPY_AND_ASSIGN(RemotePage);
84 }; 85 };
85 86
86 typedef std::vector<scoped_refptr<RemotePage> > RemotePages; 87 using RemotePages = std::vector<scoped_refptr<RemotePage> >;
87 typedef base::Callback<void(int, const std::string&)> JsonRequestCallback; 88 using JsonRequestCallback = base::Callback<void(int, const std::string&)>;
88 89
89 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { 90 class RemoteBrowser : public base::RefCounted<RemoteBrowser> {
90 public: 91 public:
91 const std::string& serial() { return browser_id_.first; } 92 const std::string& serial() { return browser_id_.first; }
92 const std::string& socket() { return browser_id_.second; } 93 const std::string& socket() { return browser_id_.second; }
93 const std::string& display_name() { return display_name_; } 94 const std::string& display_name() { return display_name_; }
94 const std::string& user() { return user_; } 95 const std::string& user() { return user_; }
95 const std::string& version() { return version_; } 96 const std::string& version() { return version_; }
96 const RemotePages& pages() { return pages_; } 97 const RemotePages& pages() { return pages_; }
97 98
98 bool IsChrome(); 99 bool IsChrome();
99 std::string GetId(); 100 std::string GetId();
100 101
101 typedef std::vector<int> ParsedVersion; 102 using ParsedVersion = std::vector<int>;
102 ParsedVersion GetParsedVersion(); 103 ParsedVersion GetParsedVersion();
103 104
104 private: 105 private:
105 friend class base::RefCounted<RemoteBrowser>; 106 friend class base::RefCounted<RemoteBrowser>;
106 friend class DevToolsAndroidBridge; 107 friend class DevToolsAndroidBridge;
107 108
108 RemoteBrowser(const std::string& serial, 109 RemoteBrowser(const std::string& serial,
109 const AndroidDeviceManager::BrowserInfo& browser_info); 110 const AndroidDeviceManager::BrowserInfo& browser_info);
110 111
111 virtual ~RemoteBrowser(); 112 virtual ~RemoteBrowser();
112 113
113 BrowserId browser_id_; 114 BrowserId browser_id_;
114 std::string display_name_; 115 std::string display_name_;
115 std::string user_; 116 std::string user_;
116 AndroidDeviceManager::BrowserInfo::Type type_; 117 AndroidDeviceManager::BrowserInfo::Type type_;
117 std::string version_; 118 std::string version_;
118 RemotePages pages_; 119 RemotePages pages_;
119 120
120 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); 121 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser);
121 }; 122 };
122 123
123 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; 124 using RemoteBrowsers = std::vector<scoped_refptr<RemoteBrowser> >;
124 125
125 class RemoteDevice : public base::RefCounted<RemoteDevice> { 126 class RemoteDevice : public base::RefCounted<RemoteDevice> {
126 public: 127 public:
127 std::string serial() { return serial_; } 128 std::string serial() { return serial_; }
128 std::string model() { return model_; } 129 std::string model() { return model_; }
129 bool is_connected() { return connected_; } 130 bool is_connected() { return connected_; }
130 RemoteBrowsers& browsers() { return browsers_; } 131 RemoteBrowsers& browsers() { return browsers_; }
131 gfx::Size screen_size() { return screen_size_; } 132 gfx::Size screen_size() { return screen_size_; }
132 133
133 private: 134 private:
134 friend class base::RefCounted<RemoteDevice>; 135 friend class base::RefCounted<RemoteDevice>;
135 friend class DevToolsAndroidBridge; 136 friend class DevToolsAndroidBridge;
136 137
137 RemoteDevice(const std::string& serial, 138 RemoteDevice(const std::string& serial,
138 const AndroidDeviceManager::DeviceInfo& device_info); 139 const AndroidDeviceManager::DeviceInfo& device_info);
139 140
140 virtual ~RemoteDevice(); 141 virtual ~RemoteDevice();
141 142
142 std::string serial_; 143 std::string serial_;
143 std::string model_; 144 std::string model_;
144 bool connected_; 145 bool connected_;
145 RemoteBrowsers browsers_; 146 RemoteBrowsers browsers_;
146 gfx::Size screen_size_; 147 gfx::Size screen_size_;
147 148
148 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); 149 DISALLOW_COPY_AND_ASSIGN(RemoteDevice);
149 }; 150 };
150 151
151 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; 152 using RemoteDevices = std::vector<scoped_refptr<RemoteDevice> >;
152 153
153 class DeviceListListener { 154 class DeviceListListener {
154 public: 155 public:
155 virtual void DeviceListChanged(const RemoteDevices& devices) = 0; 156 virtual void DeviceListChanged(const RemoteDevices& devices) = 0;
156 protected: 157 protected:
157 virtual ~DeviceListListener() {} 158 virtual ~DeviceListListener() {}
158 }; 159 };
159 160
160 explicit DevToolsAndroidBridge(Profile* profile); 161 explicit DevToolsAndroidBridge(Profile* profile);
161 void AddDeviceListListener(DeviceListListener* listener); 162 void AddDeviceListListener(DeviceListListener* listener);
162 void RemoveDeviceListListener(DeviceListListener* listener); 163 void RemoveDeviceListListener(DeviceListListener* listener);
163 164
164 class DeviceCountListener { 165 class DeviceCountListener {
165 public: 166 public:
166 virtual void DeviceCountChanged(int count) = 0; 167 virtual void DeviceCountChanged(int count) = 0;
167 protected: 168 protected:
168 virtual ~DeviceCountListener() {} 169 virtual ~DeviceCountListener() {}
169 }; 170 };
170 171
171 void AddDeviceCountListener(DeviceCountListener* listener); 172 void AddDeviceCountListener(DeviceCountListener* listener);
172 void RemoveDeviceCountListener(DeviceCountListener* listener); 173 void RemoveDeviceCountListener(DeviceCountListener* listener);
173 174
174 typedef int PortStatus; 175 using PortStatus = int;
175 typedef std::map<int, PortStatus> PortStatusMap; 176 using PortStatusMap = std::map<int, PortStatus>;
176 typedef std::pair<scoped_refptr<RemoteBrowser>, PortStatusMap> 177 using BrowserStatus = std::pair<scoped_refptr<RemoteBrowser>, PortStatusMap>;
177 BrowserStatus; 178 using ForwardingStatus = std::vector<BrowserStatus>;
178 typedef std::vector<BrowserStatus> ForwardingStatus;
179 179
180 class PortForwardingListener { 180 class PortForwardingListener {
181 public: 181 public:
182 typedef DevToolsAndroidBridge::PortStatusMap PortStatusMap; 182 using PortStatusMap = DevToolsAndroidBridge::PortStatusMap;
183 typedef DevToolsAndroidBridge::BrowserStatus BrowserStatus; 183 using BrowserStatus = DevToolsAndroidBridge::BrowserStatus;
184 typedef DevToolsAndroidBridge::ForwardingStatus ForwardingStatus; 184 using ForwardingStatus = DevToolsAndroidBridge::ForwardingStatus;
185 185
186 virtual void PortStatusChanged(const ForwardingStatus&) = 0; 186 virtual void PortStatusChanged(const ForwardingStatus&) = 0;
187 protected: 187 protected:
188 virtual ~PortForwardingListener() {} 188 virtual ~PortForwardingListener() {}
189 }; 189 };
190 190
191 void AddPortForwardingListener(PortForwardingListener* listener); 191 void AddPortForwardingListener(PortForwardingListener* listener);
192 void RemovePortForwardingListener(PortForwardingListener* listener); 192 void RemovePortForwardingListener(PortForwardingListener* listener);
193 193
194 void set_device_providers_for_test( 194 void set_device_providers_for_test(
195 const AndroidDeviceManager::DeviceProviders& device_providers) { 195 const AndroidDeviceManager::DeviceProviders& device_providers) {
196 device_manager_->SetDeviceProviders(device_providers); 196 device_manager_->SetDeviceProviders(device_providers);
197 } 197 }
198 198
199 void set_task_scheduler_for_test( 199 void set_task_scheduler_for_test(
200 base::Callback<void(const base::Closure&)> scheduler) { 200 base::Callback<void(const base::Closure&)> scheduler) {
201 task_scheduler_ = scheduler; 201 task_scheduler_ = scheduler;
202 } 202 }
203 203
204 bool HasDevToolsWindow(const std::string& agent_id); 204 bool HasDevToolsWindow(const std::string& agent_id);
205 205
206 // Creates new target instance owned by caller. 206 // Creates new target instance owned by caller.
207 DevToolsTargetImpl* CreatePageTarget(scoped_refptr<RemotePage> browser); 207 DevToolsTargetImpl* CreatePageTarget(scoped_refptr<RemotePage> browser);
208 208
209 typedef base::Callback<void(scoped_refptr<RemotePage>)> RemotePageCallback; 209 using RemotePageCallback = base::Callback<void(scoped_refptr<RemotePage>)>;
210 void OpenRemotePage(scoped_refptr<RemoteBrowser> browser, 210 void OpenRemotePage(scoped_refptr<RemoteBrowser> browser,
211 const std::string& url); 211 const std::string& url);
212 212
213 scoped_refptr<content::DevToolsAgentHost> GetBrowserAgentHost( 213 scoped_refptr<content::DevToolsAgentHost> GetBrowserAgentHost(
214 scoped_refptr<RemoteBrowser> browser); 214 scoped_refptr<RemoteBrowser> browser);
215 215
216 void SendJsonRequest(const std::string& browser_id_str, 216 void SendJsonRequest(const std::string& browser_id_str,
217 const std::string& url, 217 const std::string& url,
218 const JsonRequestCallback& callback); 218 const JsonRequestCallback& callback);
219 219
220 using TCPProviderCallback =
221 base::Callback<void(scoped_refptr<TCPDeviceProvider>)>;
222 void set_tcp_provider_callback_for_test(TCPProviderCallback callback);
220 private: 223 private:
221 friend struct content::BrowserThread::DeleteOnThread< 224 friend struct content::BrowserThread::DeleteOnThread<
222 content::BrowserThread::UI>; 225 content::BrowserThread::UI>;
223 friend class base::DeleteHelper<DevToolsAndroidBridge>; 226 friend class base::DeleteHelper<DevToolsAndroidBridge>;
224 227
225 friend class PortForwardingController; 228 friend class PortForwardingController;
226 229
227 class AgentHostDelegate; 230 class AgentHostDelegate;
228 class DiscoveryRequest; 231 class DiscoveryRequest;
229 class RemotePageTarget; 232 class RemotePageTarget;
230 233
231 ~DevToolsAndroidBridge() override; 234 ~DevToolsAndroidBridge() override;
232 235
233 void StartDeviceListPolling(); 236 void StartDeviceListPolling();
234 void StopDeviceListPolling(); 237 void StopDeviceListPolling();
235 bool NeedsDeviceListPolling(); 238 bool NeedsDeviceListPolling();
236 239
237 typedef std::pair<scoped_refptr<AndroidDeviceManager::Device>, 240 using CompleteDevice = std::pair<scoped_refptr<AndroidDeviceManager::Device>,
238 scoped_refptr<RemoteDevice>> CompleteDevice; 241 scoped_refptr<RemoteDevice>>;
239 typedef std::vector<CompleteDevice> CompleteDevices; 242 using CompleteDevices = std::vector<CompleteDevice>;
240 typedef base::Callback<void(const CompleteDevices&)> DeviceListCallback; 243 using DeviceListCallback = base::Callback<void(const CompleteDevices&)>;
241 244
242 void RequestDeviceList(const DeviceListCallback& callback); 245 void RequestDeviceList(const DeviceListCallback& callback);
243 void ReceivedDeviceList(const CompleteDevices& complete_devices); 246 void ReceivedDeviceList(const CompleteDevices& complete_devices);
244 247
245 void StartDeviceCountPolling(); 248 void StartDeviceCountPolling();
246 void StopDeviceCountPolling(); 249 void StopDeviceCountPolling();
247 void RequestDeviceCount(const base::Callback<void(int)>& callback); 250 void RequestDeviceCount(const base::Callback<void(int)>& callback);
248 void ReceivedDeviceCount(int count); 251 void ReceivedDeviceCount(int count);
249 252
250 static void ScheduleTaskDefault(const base::Closure& task); 253 static void ScheduleTaskDefault(const base::Closure& task);
(...skipping 13 matching lines...) Expand all
264 scoped_refptr<AndroidDeviceManager::Device> FindDevice( 267 scoped_refptr<AndroidDeviceManager::Device> FindDevice(
265 const std::string& serial); 268 const std::string& serial);
266 269
267 base::WeakPtr<DevToolsAndroidBridge> AsWeakPtr() { 270 base::WeakPtr<DevToolsAndroidBridge> AsWeakPtr() {
268 return weak_factory_.GetWeakPtr(); 271 return weak_factory_.GetWeakPtr();
269 } 272 }
270 273
271 Profile* const profile_; 274 Profile* const profile_;
272 const std::unique_ptr<AndroidDeviceManager> device_manager_; 275 const std::unique_ptr<AndroidDeviceManager> device_manager_;
273 276
274 typedef std::map<std::string, scoped_refptr<AndroidDeviceManager::Device>> 277 using DeviceMap =
275 DeviceMap; 278 std::map<std::string, scoped_refptr<AndroidDeviceManager::Device> >;
276 DeviceMap device_map_; 279 DeviceMap device_map_;
277 280
278 typedef std::map<std::string, AgentHostDelegate*> AgentHostDelegates; 281 using AgentHostDelegates = std::map<std::string, AgentHostDelegate*>;
279 AgentHostDelegates host_delegates_; 282 AgentHostDelegates host_delegates_;
280 283
281 typedef std::vector<DeviceListListener*> DeviceListListeners; 284 using DeviceListListeners = std::vector<DeviceListListener*>;
282 DeviceListListeners device_list_listeners_; 285 DeviceListListeners device_list_listeners_;
283 base::CancelableCallback<void(const CompleteDevices&)> device_list_callback_; 286 base::CancelableCallback<void(const CompleteDevices&)> device_list_callback_;
284 287
285 typedef std::vector<DeviceCountListener*> DeviceCountListeners; 288 using DeviceCountListeners = std::vector<DeviceCountListener*>;
286 DeviceCountListeners device_count_listeners_; 289 DeviceCountListeners device_count_listeners_;
287 base::CancelableCallback<void(int)> device_count_callback_; 290 base::CancelableCallback<void(int)> device_count_callback_;
288 base::Callback<void(const base::Closure&)> task_scheduler_; 291 base::Callback<void(const base::Closure&)> task_scheduler_;
289 292
290 typedef std::vector<PortForwardingListener*> PortForwardingListeners; 293 using PortForwardingListeners = std::vector<PortForwardingListener*>;
291 PortForwardingListeners port_forwarding_listeners_; 294 PortForwardingListeners port_forwarding_listeners_;
292 std::unique_ptr<PortForwardingController> port_forwarding_controller_; 295 std::unique_ptr<PortForwardingController> port_forwarding_controller_;
293 296
294 PrefChangeRegistrar pref_change_registrar_; 297 PrefChangeRegistrar pref_change_registrar_;
295 298
299 TCPProviderCallback tcp_provider_callback_;
300
296 base::WeakPtrFactory<DevToolsAndroidBridge> weak_factory_; 301 base::WeakPtrFactory<DevToolsAndroidBridge> weak_factory_;
297 302
298 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); 303 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge);
299 }; 304 };
300 305
301 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ 306 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/devtools/device/devtools_android_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698