| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 (DevToolsAndroidBridge::CompleteDevices::const_iterator it = |
| 545 devices.begin(); it != devices.end(); ++it) { | 547 complete_devices.begin(); it != complete_devices.end(); ++it) { |
| 546 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> device = *it; | 548 scoped_refptr<AndroidDeviceManager::Device> device(it->first); |
| 547 if (!device->is_connected()) | 549 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> remote_device( |
| 550 it->second); |
| 551 if (!remote_device->is_connected()) |
| 548 continue; | 552 continue; |
| 549 Registry::iterator rit = registry_.find(device->serial()); | 553 Registry::iterator rit = registry_.find(remote_device->serial()); |
| 550 if (rit == registry_.end()) { | 554 if (rit == registry_.end()) { |
| 551 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser = | 555 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser( |
| 552 FindBestBrowserForTethering(device->browsers()); | 556 FindBestBrowserForTethering(remote_device->browsers())); |
| 553 if (browser.get()) { | 557 if (browser.get()) |
| 554 new Connection(®istry_, device, browser, forwarding_map_); | 558 new Connection(®istry_, device, browser, forwarding_map_); |
| 555 } | |
| 556 } else { | 559 } else { |
| 557 status.push_back(std::make_pair(rit->second->browser(), | 560 status.push_back(std::make_pair(rit->second->browser(), |
| 558 rit->second->GetPortStatusMap())); | 561 rit->second->GetPortStatusMap())); |
| 559 } | 562 } |
| 560 } | 563 } |
| 561 return status; | 564 return status; |
| 562 } | 565 } |
| 563 | 566 |
| 564 void PortForwardingController::OnPrefsChange() { | 567 void PortForwardingController::OnPrefsChange() { |
| 565 forwarding_map_.clear(); | 568 forwarding_map_.clear(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 586 registry_copy.push_back(it->second); | 589 registry_copy.push_back(it->second); |
| 587 } | 590 } |
| 588 STLDeleteElements(®istry_copy); | 591 STLDeleteElements(®istry_copy); |
| 589 } | 592 } |
| 590 } | 593 } |
| 591 | 594 |
| 592 void PortForwardingController::UpdateConnections() { | 595 void PortForwardingController::UpdateConnections() { |
| 593 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) | 596 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) |
| 594 it->second->UpdateForwardingMap(forwarding_map_); | 597 it->second->UpdateForwardingMap(forwarding_map_); |
| 595 } | 598 } |
| OLD | NEW |