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

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

Issue 644963003: [DevTools] Port forwarding doesn't keep USB connection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/websocket
Patch Set: 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
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<AndroidDeviceManager::Device> device_; 302 AndroidDeviceManager::Device* device_;
303 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_; 303 scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_;
304 scoped_ptr<AndroidDeviceManager::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<AndroidDeviceManager::Device> 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.get()),
dgozman 2014/10/21 11:54:02 I think you either need |device_| or |browser_|, b
vkuzkokov 2014/10/21 13:00:54 We store browser_ so that we could display on chro
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_)[browser->serial()] = this;
329 web_socket_.reset( 329 web_socket_.reset(
330 device_->CreateWebSocket(browser->socket(), 330 device_->CreateWebSocket(browser->socket(),
331 kDevToolsRemoteBrowserTarget, this)); 331 kDevToolsRemoteBrowserTarget, this));
332 } 332 }
333 333
334 PortForwardingController::Connection::~Connection() { 334 PortForwardingController::Connection::~Connection() {
335
336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
337 DCHECK(registry_->find(device_->serial()) != registry_->end()); 336 DCHECK(registry_->find(browser_->serial()) != registry_->end());
338 registry_->erase(device_->serial()); 337 registry_->erase(browser_->serial());
339 } 338 }
340 339
341 void PortForwardingController::Connection::UpdateForwardingMap( 340 void PortForwardingController::Connection::UpdateForwardingMap(
342 const ForwardingMap& new_forwarding_map) { 341 const ForwardingMap& new_forwarding_map) {
343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
344 if (connected_) { 343 if (connected_) {
345 SerializeChanges(tethering::unbind::kName, 344 SerializeChanges(tethering::unbind::kName,
346 new_forwarding_map, forwarding_map_); 345 new_forwarding_map, forwarding_map_);
347 SerializeChanges(tethering::bind::kName, 346 SerializeChanges(tethering::bind::kName,
348 forwarding_map_, new_forwarding_map); 347 forwarding_map_, new_forwarding_map);
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 registry_copy.push_back(it->second); 587 registry_copy.push_back(it->second);
589 } 588 }
590 STLDeleteElements(&registry_copy); 589 STLDeleteElements(&registry_copy);
591 } 590 }
592 } 591 }
593 592
594 void PortForwardingController::UpdateConnections() { 593 void PortForwardingController::UpdateConnections() {
595 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it) 594 for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it)
596 it->second->UpdateForwardingMap(forwarding_map_); 595 it->second->UpdateForwardingMap(forwarding_map_);
597 } 596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698