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

Side by Side Diff: chrome/browser/devtools/device/port_forwarding_controller.cc

Issue 596253003: DevTools: RemoteDevice and RemoteBrowser are now value types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pfc3
Patch Set: Rebased Created 6 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
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 #include "chrome/browser/devtools/device/port_forwarding_controller.h" 5 #include "chrome/browser/devtools/device/port_forwarding_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 best_browser = browser; 245 best_browser = browser;
246 newest_version = current_version; 246 newest_version = current_version;
247 } 247 }
248 } 248 }
249 return best_browser; 249 return best_browser;
250 } 250 }
251 251
252 } // namespace 252 } // namespace
253 253
254 class PortForwardingController::Connection 254 class PortForwardingController::Connection
255 : public DevToolsAndroidBridge::AndroidWebSocket::Delegate { 255 : public AndroidDeviceManager::AndroidWebSocket::Delegate {
256 public: 256 public:
257 Connection(Registry* registry, 257 Connection(Registry* registry,
258 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> device, 258 scoped_refptr<AndroidDeviceManager::Device> device,
259 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, 259 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser,
260 const ForwardingMap& forwarding_map); 260 const ForwardingMap& forwarding_map);
261 virtual ~Connection(); 261 virtual ~Connection();
262 262
263 const PortStatusMap& GetPortStatusMap(); 263 const PortStatusMap& GetPortStatusMap();
264 264
265 void UpdateForwardingMap(const ForwardingMap& new_forwarding_map); 265 void UpdateForwardingMap(const ForwardingMap& new_forwarding_map);
266 266
267 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser() { 267 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser() {
268 return browser_; 268 return browser_;
(...skipping 23 matching lines...) Expand all
292 static void UpdateSocketCountOnHandlerThread( 292 static void UpdateSocketCountOnHandlerThread(
293 base::WeakPtr<Connection> weak_connection, int port, int increment); 293 base::WeakPtr<Connection> weak_connection, int port, int increment);
294 void UpdateSocketCount(int port, int increment); 294 void UpdateSocketCount(int port, int increment);
295 295
296 // DevToolsAndroidBridge::AndroidWebSocket::Delegate implementation: 296 // DevToolsAndroidBridge::AndroidWebSocket::Delegate implementation:
297 virtual void OnSocketOpened() OVERRIDE; 297 virtual void OnSocketOpened() OVERRIDE;
298 virtual void OnFrameRead(const std::string& message) OVERRIDE; 298 virtual void OnFrameRead(const std::string& message) OVERRIDE;
299 virtual void OnSocketClosed() OVERRIDE; 299 virtual void OnSocketClosed() OVERRIDE;
300 300
301 PortForwardingController::Registry* registry_; 301 PortForwardingController::Registry* registry_;
302 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> device_; 302 scoped_refptr<AndroidDeviceManager::Device> device_;
303 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_; 303 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_;
304 scoped_ptr<DevToolsAndroidBridge::AndroidWebSocket> web_socket_; 304 scoped_ptr<AndroidDeviceManager::AndroidWebSocket> web_socket_;
305 int command_id_; 305 int command_id_;
306 bool connected_; 306 bool connected_;
307 ForwardingMap forwarding_map_; 307 ForwardingMap forwarding_map_;
308 CommandCallbackMap pending_responses_; 308 CommandCallbackMap pending_responses_;
309 PortStatusMap port_status_; 309 PortStatusMap port_status_;
310 base::WeakPtrFactory<Connection> weak_factory_; 310 base::WeakPtrFactory<Connection> weak_factory_;
311 311
312 DISALLOW_COPY_AND_ASSIGN(Connection); 312 DISALLOW_COPY_AND_ASSIGN(Connection);
313 }; 313 };
314 314
315 PortForwardingController::Connection::Connection( 315 PortForwardingController::Connection::Connection(
316 Registry* registry, 316 Registry* registry,
317 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> device, 317 scoped_refptr<AndroidDeviceManager::Device> device,
318 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, 318 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser,
319 const ForwardingMap& forwarding_map) 319 const ForwardingMap& forwarding_map)
320 : registry_(registry), 320 : registry_(registry),
321 device_(device), 321 device_(device),
322 browser_(browser), 322 browser_(browser),
323 command_id_(0), 323 command_id_(0),
324 connected_(false), 324 connected_(false),
325 forwarding_map_(forwarding_map), 325 forwarding_map_(forwarding_map),
326 weak_factory_(this) { 326 weak_factory_(this) {
327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
328 (*registry_)[device_->serial()] = this; 328 (*registry_)[device_->serial()] = this;
329 web_socket_.reset( 329 web_socket_.reset(
330 browser->CreateWebSocket(kDevToolsRemoteBrowserTarget, this)); 330 device_->CreateWebSocket(browser->socket(),
331 kDevToolsRemoteBrowserTarget, this));
331 } 332 }
332 333
333 PortForwardingController::Connection::~Connection() { 334 PortForwardingController::Connection::~Connection() {
335
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
335 DCHECK(registry_->find(device_->serial()) != registry_->end()); 337 DCHECK(registry_->find(device_->serial()) != registry_->end());
336 registry_->erase(device_->serial()); 338 registry_->erase(device_->serial());
337 } 339 }
338 340
339 void PortForwardingController::Connection::UpdateForwardingMap( 341 void PortForwardingController::Connection::UpdateForwardingMap(
340 const ForwardingMap& new_forwarding_map) { 342 const ForwardingMap& new_forwarding_map) {
341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
342 if (connected_) { 344 if (connected_) {
343 SerializeChanges(tethering::unbind::kName, 345 SerializeChanges(tethering::unbind::kName,
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 &PortForwardingController::OnPrefsChange, base::Unretained(this)); 531 &PortForwardingController::OnPrefsChange, base::Unretained(this));
530 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled, callback); 532 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled, callback);
531 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, callback); 533 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, callback);
532 OnPrefsChange(); 534 OnPrefsChange();
533 } 535 }
534 536
535 PortForwardingController::~PortForwardingController() {} 537 PortForwardingController::~PortForwardingController() {}
536 538
537 PortForwardingController::ForwardingStatus 539 PortForwardingController::ForwardingStatus
538 PortForwardingController::DeviceListChanged( 540 PortForwardingController::DeviceListChanged(
539 const DevToolsAndroidBridge::RemoteDevices& devices) { 541 const DevToolsAndroidBridge::CompleteDevices& complete_devices) {
540 ForwardingStatus status; 542 ForwardingStatus status;
541 if (forwarding_map_.empty()) 543 if (forwarding_map_.empty())
542 return status; 544 return status;
543 545
544 for (DevToolsAndroidBridge::RemoteDevices::const_iterator it = 546 for (const auto& pair : complete_devices) {
545 devices.begin(); it != devices.end(); ++it) { 547 scoped_refptr<AndroidDeviceManager::Device> device(pair.first);
546 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> device = *it; 548 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> remote_device(
547 if (!device->is_connected()) 549 pair.second);
550 if (!remote_device->is_connected())
548 continue; 551 continue;
549 Registry::iterator rit = registry_.find(device->serial()); 552 Registry::iterator rit = registry_.find(remote_device->serial());
550 if (rit == registry_.end()) { 553 if (rit == registry_.end()) {
551 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser = 554 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser(
552 FindBestBrowserForTethering(device->browsers()); 555 FindBestBrowserForTethering(remote_device->browsers()));
553 if (browser.get()) { 556 if (browser.get())
554 new Connection(&registry_, device, browser, forwarding_map_); 557 new Connection(&registry_, device, browser, forwarding_map_);
555 }
556 } else { 558 } else {
557 status.push_back(std::make_pair(rit->second->browser(), 559 status.push_back(std::make_pair(rit->second->browser(),
558 rit->second->GetPortStatusMap())); 560 rit->second->GetPortStatusMap()));
559 } 561 }
560 } 562 }
561 return status; 563 return status;
562 } 564 }
563 565
564 void PortForwardingController::OnPrefsChange() { 566 void PortForwardingController::OnPrefsChange() {
565 forwarding_map_.clear(); 567 forwarding_map_.clear();
(...skipping 20 matching lines...) Expand all
586 registry_copy.push_back(it->second); 588 registry_copy.push_back(it->second);
587 } 589 }
588 STLDeleteElements(&registry_copy); 590 STLDeleteElements(&registry_copy);
589 } 591 }
590 } 592 }
591 593
592 void PortForwardingController::UpdateConnections() { 594 void PortForwardingController::UpdateConnections() {
593 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) 595 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it)
594 it->second->UpdateForwardingMap(forwarding_map_); 596 it->second->UpdateForwardingMap(forwarding_map_);
595 } 597 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/device/port_forwarding_controller.h ('k') | chrome/browser/devtools/devtools_targets_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698