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

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: Removed setters from RemoteBrowser 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 const std::string& socket,
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 private: 267 private:
268 friend struct content::BrowserThread::DeleteOnThread< 268 friend struct content::BrowserThread::DeleteOnThread<
269 content::BrowserThread::UI>; 269 content::BrowserThread::UI>;
(...skipping 18 matching lines...) Expand all
288 static void UpdateSocketCountOnHandlerThread( 288 static void UpdateSocketCountOnHandlerThread(
289 base::WeakPtr<Connection> weak_connection, int port, int increment); 289 base::WeakPtr<Connection> weak_connection, int port, int increment);
290 void UpdateSocketCount(int port, int increment); 290 void UpdateSocketCount(int port, int increment);
291 291
292 // DevToolsAndroidBridge::AndroidWebSocket::Delegate implementation: 292 // DevToolsAndroidBridge::AndroidWebSocket::Delegate implementation:
293 virtual void OnSocketOpened() OVERRIDE; 293 virtual void OnSocketOpened() OVERRIDE;
294 virtual void OnFrameRead(const std::string& message) OVERRIDE; 294 virtual void OnFrameRead(const std::string& message) OVERRIDE;
295 virtual void OnSocketClosed() OVERRIDE; 295 virtual void OnSocketClosed() OVERRIDE;
296 296
297 PortForwardingController::Registry* registry_; 297 PortForwardingController::Registry* registry_;
298 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> device_; 298 scoped_refptr<AndroidDeviceManager::Device> device_;
299 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_; 299 scoped_ptr<AndroidDeviceManager::AndroidWebSocket> web_socket_;
300 scoped_ptr<DevToolsAndroidBridge::AndroidWebSocket> web_socket_;
301 int command_id_; 300 int command_id_;
302 bool connected_; 301 bool connected_;
303 ForwardingMap forwarding_map_; 302 ForwardingMap forwarding_map_;
304 CommandCallbackMap pending_responses_; 303 CommandCallbackMap pending_responses_;
305 PortStatusMap port_status_; 304 PortStatusMap port_status_;
306 base::WeakPtrFactory<Connection> weak_factory_; 305 base::WeakPtrFactory<Connection> weak_factory_;
307 306
308 DISALLOW_COPY_AND_ASSIGN(Connection); 307 DISALLOW_COPY_AND_ASSIGN(Connection);
309 }; 308 };
310 309
311 PortForwardingController::Connection::Connection( 310 PortForwardingController::Connection::Connection(
312 Registry* registry, 311 Registry* registry,
313 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> device, 312 scoped_refptr<AndroidDeviceManager::Device> device,
314 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser, 313 const std::string& socket,
315 const ForwardingMap& forwarding_map) 314 const ForwardingMap& forwarding_map)
316 : registry_(registry), 315 : registry_(registry),
317 device_(device), 316 device_(device),
318 browser_(browser),
319 command_id_(0), 317 command_id_(0),
320 connected_(false), 318 connected_(false),
321 forwarding_map_(forwarding_map), 319 forwarding_map_(forwarding_map),
322 weak_factory_(this) { 320 weak_factory_(this) {
323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
324 (*registry_)[device_->serial()] = this; 322 (*registry_)[device_->serial()] = this;
325 web_socket_.reset( 323 web_socket_.reset(
326 browser->CreateWebSocket(kDevToolsRemoteBrowserTarget, this)); 324 device_->CreateWebSocket(socket, kDevToolsRemoteBrowserTarget, this));
327 } 325 }
328 326
329 PortForwardingController::Connection::~Connection() { 327 PortForwardingController::Connection::~Connection() {
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
331 DCHECK(registry_->find(device_->serial()) != registry_->end()); 329 DCHECK(registry_->find(device_->serial()) != registry_->end());
332 registry_->erase(device_->serial()); 330 registry_->erase(device_->serial());
333 } 331 }
334 332
335 void PortForwardingController::Connection::UpdateForwardingMap( 333 void PortForwardingController::Connection::UpdateForwardingMap(
336 const ForwardingMap& new_forwarding_map) { 334 const ForwardingMap& new_forwarding_map) {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 &PortForwardingController::OnPrefsChange, base::Unretained(this)); 523 &PortForwardingController::OnPrefsChange, base::Unretained(this));
526 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled, callback); 524 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingEnabled, callback);
527 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, callback); 525 pref_change_registrar_.Add(prefs::kDevToolsPortForwardingConfig, callback);
528 OnPrefsChange(); 526 OnPrefsChange();
529 } 527 }
530 528
531 PortForwardingController::~PortForwardingController() {} 529 PortForwardingController::~PortForwardingController() {}
532 530
533 PortForwardingController::DevicesStatus 531 PortForwardingController::DevicesStatus
534 PortForwardingController::DeviceListChanged( 532 PortForwardingController::DeviceListChanged(
535 const DevToolsAndroidBridge::RemoteDevices& devices) { 533 const DevToolsAndroidBridge::DeviceMap& device_map,
534 const DevToolsAndroidBridge::RemoteDevices& remote_devices) {
536 DevicesStatus status; 535 DevicesStatus status;
537 if (forwarding_map_.empty()) 536 if (forwarding_map_.empty())
538 return status; 537 return status;
539 538
540 for (DevToolsAndroidBridge::RemoteDevices::const_iterator it = 539 for (DevToolsAndroidBridge::RemoteDevices::const_iterator it =
541 devices.begin(); it != devices.end(); ++it) { 540 remote_devices.begin(); it != remote_devices.end(); ++it) {
542 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> device = *it; 541 scoped_refptr<DevToolsAndroidBridge::RemoteDevice> remote_device = *it;
543 if (!device->is_connected()) 542 if (!remote_device->is_connected())
544 continue; 543 continue;
545 Registry::iterator rit = registry_.find(device->serial()); 544 Registry::iterator rit = registry_.find(remote_device->serial());
546 if (rit == registry_.end()) { 545 if (rit == registry_.end()) {
547 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser = 546 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser =
548 FindBestBrowserForTethering(device->browsers()); 547 FindBestBrowserForTethering(remote_device->browsers());
549 if (browser.get()) { 548 if (browser.get()) {
550 new Connection(&registry_, device, browser, forwarding_map_); 549 DevToolsAndroidBridge::DeviceMap::const_iterator it =
550 device_map.find(remote_device->serial());
551 DCHECK(it != device_map.end());
552 new Connection(&registry_, it->second, browser->socket(),
553 forwarding_map_);
551 } 554 }
552 } else { 555 } else {
553 status[device->serial()] = (*rit).second->GetPortStatusMap(); 556 status[remote_device->serial()] = (*rit).second->GetPortStatusMap();
554 } 557 }
555 } 558 }
556 559
557 return status; 560 return status;
558 } 561 }
559 562
560 void PortForwardingController::OnPrefsChange() { 563 void PortForwardingController::OnPrefsChange() {
561 forwarding_map_.clear(); 564 forwarding_map_.clear();
562 565
563 if (pref_service_->GetBoolean(prefs::kDevToolsPortForwardingEnabled)) { 566 if (pref_service_->GetBoolean(prefs::kDevToolsPortForwardingEnabled)) {
(...skipping 18 matching lines...) Expand all
582 registry_copy.push_back(it->second); 585 registry_copy.push_back(it->second);
583 } 586 }
584 STLDeleteElements(&registry_copy); 587 STLDeleteElements(&registry_copy);
585 } 588 }
586 } 589 }
587 590
588 void PortForwardingController::UpdateConnections() { 591 void PortForwardingController::UpdateConnections() {
589 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) 592 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it)
590 it->second->UpdateForwardingMap(forwarding_map_); 593 it->second->UpdateForwardingMap(forwarding_map_);
591 } 594 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698