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

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

Issue 2361613002: DevTools: untangle device discovery request from the devtools android bridge. (Closed)
Patch Set: make device hosts profile-independent, plump browser context for inspect. Created 4 years, 3 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
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 Factory(); 54 Factory();
55 ~Factory() override; 55 ~Factory() override;
56 56
57 // BrowserContextKeyedServiceFactory overrides: 57 // BrowserContextKeyedServiceFactory overrides:
58 KeyedService* BuildServiceInstanceFor( 58 KeyedService* BuildServiceInstanceFor(
59 content::BrowserContext* context) const override; 59 content::BrowserContext* context) const override;
60 DISALLOW_COPY_AND_ASSIGN(Factory); 60 DISALLOW_COPY_AND_ASSIGN(Factory);
61 }; 61 };
62 62
63 using BrowserId = std::pair<std::string, std::string>;
64
65 class RemotePage : public base::RefCounted<RemotePage> { 63 class RemotePage : public base::RefCounted<RemotePage> {
66 public: 64 public:
67 const std::string& serial() { return browser_id_.first; } 65 scoped_refptr<AndroidDeviceManager::Device> device() { return device_; }
68 const std::string& socket() { return browser_id_.second; } 66 const std::string& socket() { return browser_id_; }
69 const std::string& frontend_url() { return frontend_url_; } 67 const std::string& frontend_url() { return frontend_url_; }
68 scoped_refptr<content::DevToolsAgentHost> CreateTarget();
70 69
71 private: 70 private:
72 friend class base::RefCounted<RemotePage>; 71 friend class base::RefCounted<RemotePage>;
73 friend class DevToolsAndroidBridge; 72 friend class DevToolsAndroidBridge;
74 73
75 RemotePage(const BrowserId& browser_id, const base::DictionaryValue& dict); 74 RemotePage(scoped_refptr<AndroidDeviceManager::Device> device,
75 const std::string& browser_id,
76 const base::DictionaryValue& dict);
76 77
77 virtual ~RemotePage(); 78 virtual ~RemotePage();
78 79
79 BrowserId browser_id_; 80 scoped_refptr<AndroidDeviceManager::Device> device_;
dgozman 2016/09/22 17:13:59 Now everyone retains the device?
81 std::string browser_id_;
80 std::string frontend_url_; 82 std::string frontend_url_;
81 std::unique_ptr<base::DictionaryValue> dict_; 83 std::unique_ptr<base::DictionaryValue> dict_;
82 84
83 DISALLOW_COPY_AND_ASSIGN(RemotePage); 85 DISALLOW_COPY_AND_ASSIGN(RemotePage);
84 }; 86 };
85 87
86 using RemotePages = std::vector<scoped_refptr<RemotePage> >; 88 using RemotePages = std::vector<scoped_refptr<RemotePage> >;
87 using JsonRequestCallback = base::Callback<void(int, const std::string&)>; 89 using JsonRequestCallback = base::Callback<void(int, const std::string&)>;
88 90
89 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { 91 class RemoteBrowser : public base::RefCounted<RemoteBrowser> {
90 public: 92 public:
91 const std::string& serial() { return browser_id_.first; } 93 const std::string& serial() { return serial_; }
92 const std::string& socket() { return browser_id_.second; } 94 const std::string& socket() { return browser_id_; }
93 const std::string& display_name() { return display_name_; } 95 const std::string& display_name() { return display_name_; }
94 const std::string& user() { return user_; } 96 const std::string& user() { return user_; }
95 const std::string& version() { return version_; } 97 const std::string& version() { return version_; }
96 const RemotePages& pages() { return pages_; } 98 const RemotePages& pages() { return pages_; }
97 99
98 bool IsChrome(); 100 bool IsChrome();
99 std::string GetId(); 101 std::string GetId();
100 102
101 using ParsedVersion = std::vector<int>; 103 using ParsedVersion = std::vector<int>;
102 ParsedVersion GetParsedVersion(); 104 ParsedVersion GetParsedVersion();
103 105
104 private: 106 private:
105 friend class base::RefCounted<RemoteBrowser>; 107 friend class base::RefCounted<RemoteBrowser>;
106 friend class DevToolsAndroidBridge; 108 friend class DevToolsAndroidBridge;
107 109
108 RemoteBrowser(const std::string& serial, 110 RemoteBrowser(const std::string& serial,
109 const AndroidDeviceManager::BrowserInfo& browser_info); 111 const AndroidDeviceManager::BrowserInfo& browser_info);
110 112
111 virtual ~RemoteBrowser(); 113 virtual ~RemoteBrowser();
112 114
113 BrowserId browser_id_; 115 std::string serial_;
116 std::string browser_id_;
114 std::string display_name_; 117 std::string display_name_;
115 std::string user_; 118 std::string user_;
116 AndroidDeviceManager::BrowserInfo::Type type_; 119 AndroidDeviceManager::BrowserInfo::Type type_;
117 std::string version_; 120 std::string version_;
118 RemotePages pages_; 121 RemotePages pages_;
119 122
120 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); 123 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser);
121 }; 124 };
122 125
123 using RemoteBrowsers = std::vector<scoped_refptr<RemoteBrowser> >; 126 using RemoteBrowsers = std::vector<scoped_refptr<RemoteBrowser> >;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 void set_device_providers_for_test( 196 void set_device_providers_for_test(
194 const AndroidDeviceManager::DeviceProviders& device_providers) { 197 const AndroidDeviceManager::DeviceProviders& device_providers) {
195 device_manager_->SetDeviceProviders(device_providers); 198 device_manager_->SetDeviceProviders(device_providers);
196 } 199 }
197 200
198 void set_task_scheduler_for_test( 201 void set_task_scheduler_for_test(
199 base::Callback<void(const base::Closure&)> scheduler) { 202 base::Callback<void(const base::Closure&)> scheduler) {
200 task_scheduler_ = scheduler; 203 task_scheduler_ = scheduler;
201 } 204 }
202 205
203 bool HasDevToolsWindow(const std::string& agent_id);
204
205 // Creates new target instance owned by caller.
206 scoped_refptr<content::DevToolsAgentHost>
207 CreatePageTarget(scoped_refptr<RemotePage> browser);
208
209 using RemotePageCallback = base::Callback<void(scoped_refptr<RemotePage>)>; 206 using RemotePageCallback = base::Callback<void(scoped_refptr<RemotePage>)>;
210 void OpenRemotePage(scoped_refptr<RemoteBrowser> browser, 207 void OpenRemotePage(scoped_refptr<RemoteBrowser> browser,
211 const std::string& url); 208 const std::string& url);
212 209
213 scoped_refptr<content::DevToolsAgentHost> GetBrowserAgentHost( 210 scoped_refptr<content::DevToolsAgentHost> GetBrowserAgentHost(
214 scoped_refptr<RemoteBrowser> browser); 211 scoped_refptr<RemoteBrowser> browser);
215 212
216 void SendJsonRequest(const std::string& browser_id_str, 213 void SendJsonRequest(const std::string& browser_id_str,
217 const std::string& url, 214 const std::string& url,
218 const JsonRequestCallback& callback); 215 const JsonRequestCallback& callback);
(...skipping 27 matching lines...) Expand all
246 243
247 void StartDeviceCountPolling(); 244 void StartDeviceCountPolling();
248 void StopDeviceCountPolling(); 245 void StopDeviceCountPolling();
249 void RequestDeviceCount(const base::Callback<void(int)>& callback); 246 void RequestDeviceCount(const base::Callback<void(int)>& callback);
250 void ReceivedDeviceCount(int count); 247 void ReceivedDeviceCount(int count);
251 248
252 static void ScheduleTaskDefault(const base::Closure& task); 249 static void ScheduleTaskDefault(const base::Closure& task);
253 250
254 void CreateDeviceProviders(); 251 void CreateDeviceProviders();
255 252
256 void SendJsonRequest(const BrowserId& browser_id,
257 const std::string& url,
258 const JsonRequestCallback& callback);
259
260 void SendProtocolCommand(const BrowserId& browser_id,
261 const std::string& target_path,
262 const std::string& method,
263 std::unique_ptr<base::DictionaryValue> params,
264 const base::Closure callback);
265
266 AndroidDeviceManager::AndroidWebSocket* CreateWebSocket(
267 const BrowserId& browser_id,
268 const std::string& url,
269 AndroidDeviceManager::AndroidWebSocket::Delegate* delegate);
270
271 base::WeakPtr<DevToolsAndroidBridge> AsWeakPtr() { 253 base::WeakPtr<DevToolsAndroidBridge> AsWeakPtr() {
272 return weak_factory_.GetWeakPtr(); 254 return weak_factory_.GetWeakPtr();
273 } 255 }
274 256
275 Profile* const profile_; 257 Profile* const profile_;
276 const std::unique_ptr<AndroidDeviceManager> device_manager_; 258 const std::unique_ptr<AndroidDeviceManager> device_manager_;
277 259
278 using DeviceMap = 260 using DeviceMap =
279 std::map<std::string, scoped_refptr<AndroidDeviceManager::Device> >; 261 std::map<std::string, scoped_refptr<AndroidDeviceManager::Device> >;
280 DeviceMap device_map_; 262 DeviceMap device_map_;
281 263
282 using AgentHostDelegates = std::map<std::string, AgentHostDelegate*>;
283 AgentHostDelegates host_delegates_;
284
285 using DeviceListListeners = std::vector<DeviceListListener*>; 264 using DeviceListListeners = std::vector<DeviceListListener*>;
286 DeviceListListeners device_list_listeners_; 265 DeviceListListeners device_list_listeners_;
287 base::CancelableCallback<void(const CompleteDevices&)> device_list_callback_; 266 base::CancelableCallback<void(const CompleteDevices&)> device_list_callback_;
288 267
289 using DeviceCountListeners = std::vector<DeviceCountListener*>; 268 using DeviceCountListeners = std::vector<DeviceCountListener*>;
290 DeviceCountListeners device_count_listeners_; 269 DeviceCountListeners device_count_listeners_;
291 base::CancelableCallback<void(int)> device_count_callback_; 270 base::CancelableCallback<void(int)> device_count_callback_;
292 base::Callback<void(const base::Closure&)> task_scheduler_; 271 base::Callback<void(const base::Closure&)> task_scheduler_;
293 272
294 using PortForwardingListeners = std::vector<PortForwardingListener*>; 273 using PortForwardingListeners = std::vector<PortForwardingListener*>;
295 PortForwardingListeners port_forwarding_listeners_; 274 PortForwardingListeners port_forwarding_listeners_;
296 std::unique_ptr<PortForwardingController> port_forwarding_controller_; 275 std::unique_ptr<PortForwardingController> port_forwarding_controller_;
297 276
298 PrefChangeRegistrar pref_change_registrar_; 277 PrefChangeRegistrar pref_change_registrar_;
299 278
300 TCPProviderCallback tcp_provider_callback_; 279 TCPProviderCallback tcp_provider_callback_;
301 280
302 base::WeakPtrFactory<DevToolsAndroidBridge> weak_factory_; 281 base::WeakPtrFactory<DevToolsAndroidBridge> weak_factory_;
303 282
304 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); 283 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge);
305 }; 284 };
306 285
307 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ 286 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698