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

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

Issue 287643002: DevTools: Partially redesigned DevToolsAndroidBridge and AndroidDeviceManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Used scoped_ptr. Fixed DeviceHandle destruction Created 6 years, 7 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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 }; 100 };
101 101
102 class RemotePage { 102 class RemotePage {
103 public: 103 public:
104 virtual ~RemotePage() {} 104 virtual ~RemotePage() {}
105 virtual DevToolsTargetImpl* GetTarget() = 0; 105 virtual DevToolsTargetImpl* GetTarget() = 0;
106 virtual std::string GetFrontendURL() = 0; 106 virtual std::string GetFrontendURL() = 0;
107 }; 107 };
108 108
109 typedef base::Callback<void(RemotePage*)> RemotePageCallback; 109 typedef base::Callback<void(RemotePage*)> RemotePageCallback;
110 typedef base::Callback<void(int, const std::string&)> JsonRequestCallback;
111
112 class DeviceHandle : public base::RefCounted<DeviceHandle> {
pfeldman 2014/05/21 11:33:41 This does not need to be public.
113 public:
114 DeviceHandle(scoped_refptr<DevToolsAndroidBridge> android_bridge,
115 const std::string& serial);
116
117 std::string serial() const { return serial_; }
118
119 void SendJsonRequest(const std::string& socket,
120 const std::string& request,
121 const JsonRequestCallback& callback);
122
123 void OpenSocket(const std::string& socket_name,
124 const AndroidDeviceManager::SocketCallback& callback);
125
126 scoped_refptr<AndroidWebSocket> CreateWebSocket(
127 const std::string& socket,
128 const std::string& url,
129 DevToolsAndroidBridge::AndroidWebSocket::Delegate* delegate);
130
131 private:
132 friend class base::RefCounted<DeviceHandle>;
133 virtual ~DeviceHandle();
134
135 scoped_refptr<DevToolsAndroidBridge> android_bridge_;
pfeldman 2014/05/21 11:33:41 Introducing devtools_manager field along this one
136 const std::string serial_;
137 };
138
139 typedef std::map<std::string, scoped_refptr<DeviceHandle> > DeviceHandleMap;
110 140
111 class RemoteBrowser : public base::RefCounted<RemoteBrowser> { 141 class RemoteBrowser : public base::RefCounted<RemoteBrowser> {
112 public: 142 public:
113 RemoteBrowser( 143 RemoteBrowser(
114 scoped_refptr<DevToolsAndroidBridge> android_bridge, 144 scoped_refptr<DeviceHandle> device_handle,
115 const std::string& serial,
116 const AndroidDeviceManager::BrowserInfo& browser_info); 145 const AndroidDeviceManager::BrowserInfo& browser_info);
117 146
118 std::string serial() { return serial_; } 147 std::string serial() { return device_handle_->serial(); }
119 std::string socket() { return socket_; } 148 std::string socket() { return socket_; }
120 149
121 std::string display_name() { return display_name_; } 150 std::string display_name() { return display_name_; }
122 void set_display_name(const std::string& name) { display_name_ = name; } 151 void set_display_name(const std::string& name) { display_name_ = name; }
123 152
124 std::string version() { return version_; } 153 std::string version() { return version_; }
125 void set_version(const std::string& version) { version_ = version; } 154 void set_version(const std::string& version) { version_ = version; }
126 155
127 bool IsChrome() const; 156 bool IsChrome() const;
128 bool IsWebView() const; 157 bool IsWebView() const;
129 158
130 typedef std::vector<int> ParsedVersion; 159 typedef std::vector<int> ParsedVersion;
131 ParsedVersion GetParsedVersion() const; 160 ParsedVersion GetParsedVersion() const;
132 161
133 std::vector<RemotePage*> CreatePages(); 162 std::vector<RemotePage*> CreatePages();
134 void SetPageDescriptors(const base::ListValue&); 163 void SetPageDescriptors(const base::ListValue&);
135 164
136 typedef base::Callback<void(int, const std::string&)> JsonRequestCallback;
137 void SendJsonRequest(const std::string& request, 165 void SendJsonRequest(const std::string& request,
138 const JsonRequestCallback& callback); 166 const JsonRequestCallback& callback);
139 void SendProtocolCommand(const std::string& debug_url, 167 void SendProtocolCommand(const std::string& debug_url,
140 const std::string& method, 168 const std::string& method,
141 base::DictionaryValue* params, 169 base::DictionaryValue* params,
142 const base::Closure callback); 170 const base::Closure callback);
143 171
144 void Open(const std::string& url, 172 void Open(const std::string& url,
145 const RemotePageCallback& callback); 173 const RemotePageCallback& callback);
146 174
(...skipping 17 matching lines...) Expand all
164 void NavigatePageOnUIThread(const JsonRequestCallback& callback, 192 void NavigatePageOnUIThread(const JsonRequestCallback& callback,
165 int result, 193 int result,
166 const std::string& response, 194 const std::string& response,
167 const std::string& url); 195 const std::string& url);
168 196
169 void RespondToOpenOnUIThread( 197 void RespondToOpenOnUIThread(
170 const DevToolsAndroidBridge::RemotePageCallback& callback, 198 const DevToolsAndroidBridge::RemotePageCallback& callback,
171 int result, 199 int result,
172 const std::string& response); 200 const std::string& response);
173 201
174 scoped_refptr<DevToolsAndroidBridge> android_bridge_; 202 scoped_refptr<DeviceHandle> device_handle_;
175 const std::string serial_;
176 const std::string socket_; 203 const std::string socket_;
177 std::string display_name_; 204 std::string display_name_;
178 const AndroidDeviceManager::BrowserInfo::Type type_; 205 const AndroidDeviceManager::BrowserInfo::Type type_;
179 std::string version_; 206 std::string version_;
180 scoped_ptr<base::ListValue> page_descriptors_; 207 scoped_ptr<base::ListValue> page_descriptors_;
181 208
182 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser); 209 DISALLOW_COPY_AND_ASSIGN(RemoteBrowser);
183 }; 210 };
184 211
185 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers; 212 typedef std::vector<scoped_refptr<RemoteBrowser> > RemoteBrowsers;
186 213
187 class RemoteDevice : public base::RefCounted<RemoteDevice> { 214 class RemoteDevice : public base::RefCounted<RemoteDevice> {
188 public: 215 public:
189 RemoteDevice(scoped_refptr<DevToolsAndroidBridge> android_bridge, 216 RemoteDevice(scoped_refptr<DeviceHandle> device_handle,
190 const std::string& serial,
191 const AndroidDeviceManager::DeviceInfo& device_info, 217 const AndroidDeviceManager::DeviceInfo& device_info,
192 bool connected); 218 bool connected);
193 219
194 std::string serial() { return serial_; } 220 std::string serial() { return device_handle_->serial(); }
195 std::string model() { return model_; } 221 std::string model() { return model_; }
196 bool is_connected() { return connected_; } 222 bool is_connected() { return connected_; }
197 RemoteBrowsers& browsers() { return browsers_; } 223 RemoteBrowsers& browsers() { return browsers_; }
198 gfx::Size screen_size() { return screen_size_; } 224 gfx::Size screen_size() { return screen_size_; }
199 225
200 void OpenSocket(const std::string& socket_name, 226 void OpenSocket(const std::string& socket_name,
201 const AndroidDeviceManager::SocketCallback& callback); 227 const AndroidDeviceManager::SocketCallback& callback);
202 228
203 private: 229 private:
204 friend class base::RefCounted<RemoteDevice>; 230 friend class base::RefCounted<RemoteDevice>;
205 virtual ~RemoteDevice(); 231 virtual ~RemoteDevice();
206 232
207 scoped_refptr<DevToolsAndroidBridge> android_bridge_; 233 scoped_refptr<DeviceHandle> device_handle_;
208 std::string serial_;
209 std::string model_; 234 std::string model_;
210 bool connected_; 235 bool connected_;
211 RemoteBrowsers browsers_; 236 RemoteBrowsers browsers_;
212 gfx::Size screen_size_; 237 gfx::Size screen_size_;
213 238
214 DISALLOW_COPY_AND_ASSIGN(RemoteDevice); 239 DISALLOW_COPY_AND_ASSIGN(RemoteDevice);
215 }; 240 };
216 241
217 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices; 242 typedef std::vector<scoped_refptr<RemoteDevice> > RemoteDevices;
218 243
(...skipping 18 matching lines...) Expand all
237 void AddDeviceCountListener(DeviceCountListener* listener); 262 void AddDeviceCountListener(DeviceCountListener* listener);
238 void RemoveDeviceCountListener(DeviceCountListener* listener); 263 void RemoveDeviceCountListener(DeviceCountListener* listener);
239 264
240 void set_device_providers_for_test( 265 void set_device_providers_for_test(
241 const AndroidDeviceManager::DeviceProviders& device_providers) { 266 const AndroidDeviceManager::DeviceProviders& device_providers) {
242 device_providers_ = device_providers; 267 device_providers_ = device_providers;
243 } 268 }
244 269
245 static bool HasDevToolsWindow(const std::string& agent_id); 270 static bool HasDevToolsWindow(const std::string& agent_id);
246 271
272 void IsConnectedForTest(const std::string& serial,
273 const base::Callback<void(bool)>& callback);
274
247 private: 275 private:
248 friend struct content::BrowserThread::DeleteOnThread< 276 friend struct content::BrowserThread::DeleteOnThread<
249 content::BrowserThread::UI>; 277 content::BrowserThread::UI>;
250 friend class base::DeleteHelper<DevToolsAndroidBridge>; 278 friend class base::DeleteHelper<DevToolsAndroidBridge>;
251 279
252 class HandlerThread : public base::RefCountedThreadSafe<HandlerThread> { 280 class HandlerThread : public base::RefCountedThreadSafe<HandlerThread> {
253 public: 281 public:
254 static scoped_refptr<HandlerThread> GetInstance(); 282 static scoped_refptr<HandlerThread> GetInstance();
255 base::MessageLoop* message_loop(); 283 base::MessageLoop* message_loop();
256 284
(...skipping 12 matching lines...) Expand all
269 base::MessageLoop* device_message_loop() { 297 base::MessageLoop* device_message_loop() {
270 return handler_thread_->message_loop(); 298 return handler_thread_->message_loop();
271 } 299 }
272 300
273 AndroidDeviceManager* device_manager() { 301 AndroidDeviceManager* device_manager() {
274 return device_manager_.get(); 302 return device_manager_.get();
275 } 303 }
276 304
277 void CreatedDeviceManager(scoped_refptr<AndroidDeviceManager> device_manager); 305 void CreatedDeviceManager(scoped_refptr<AndroidDeviceManager> device_manager);
278 void RequestDeviceList(); 306 void RequestDeviceList();
279 void ReceivedDeviceList(RemoteDevices* devices); 307 void ReceivedDeviceList(scoped_ptr<RemoteDevices> devices,
308 scoped_ptr<DeviceHandleMap> used_device_handles,
309 scoped_ptr<DeviceHandleMap> all_device_handles);
280 310
281 void RequestDeviceCount(); 311 void RequestDeviceCount();
282 void ReceivedDeviceCount(int count); 312 void ReceivedDeviceCount(int count);
283 313
284 void CreateDeviceProviders(); 314 void CreateDeviceProviders();
285 315
286 Profile* profile_; 316 Profile* profile_;
287 scoped_refptr<HandlerThread> handler_thread_; 317 scoped_refptr<HandlerThread> handler_thread_;
288 scoped_refptr<AndroidDeviceManager> device_manager_; 318 scoped_refptr<AndroidDeviceManager> device_manager_;
289 319
290 typedef std::vector<DeviceListListener*> DeviceListListeners; 320 typedef std::vector<DeviceListListener*> DeviceListListeners;
291 DeviceListListeners device_list_listeners_; 321 DeviceListListeners device_list_listeners_;
322 DeviceHandleMap device_handles_;
292 323
293 typedef std::vector<DeviceCountListener*> DeviceCountListeners; 324 typedef std::vector<DeviceCountListener*> DeviceCountListeners;
294 DeviceCountListeners device_count_listeners_; 325 DeviceCountListeners device_count_listeners_;
295 326
296 AndroidDeviceManager::DeviceProviders device_providers_; 327 AndroidDeviceManager::DeviceProviders device_providers_;
297 PrefChangeRegistrar pref_change_registrar_; 328 PrefChangeRegistrar pref_change_registrar_;
298 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge); 329 DISALLOW_COPY_AND_ASSIGN(DevToolsAndroidBridge);
299 }; 330 };
300 331
301 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_ 332 #endif // CHROME_BROWSER_DEVTOOLS_DEVICE_DEVTOOLS_ANDROID_BRIDGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698