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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/devtools/device/port_forwarding_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/devtools/device/port_forwarding_controller.cc
diff --git a/chrome/browser/devtools/device/port_forwarding_controller.cc b/chrome/browser/devtools/device/port_forwarding_controller.cc
index d19e9fffb36def4ee251d25ceabd1e8f1a6bb1b4..eb82daa84674f95662eb7b26f73f90416f4b38d1 100644
--- a/chrome/browser/devtools/device/port_forwarding_controller.cc
+++ b/chrome/browser/devtools/device/port_forwarding_controller.cc
@@ -254,8 +254,7 @@ FindBestBrowserForTethering(
class PortForwardingController::Connection
: public AndroidDeviceManager::AndroidWebSocket::Delegate {
public:
- Connection(Registry* registry,
- scoped_refptr<AndroidDeviceManager::Device> device,
+ Connection(PortForwardingController* controller,
scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser,
const ForwardingMap& forwarding_map);
~Connection() override;
@@ -273,9 +272,7 @@ class PortForwardingController::Connection
content::BrowserThread::UI>;
friend class base::DeleteHelper<Connection>;
-
typedef std::map<int, std::string> ForwardingMap;
-
typedef base::Callback<void(PortStatus)> CommandCallback;
typedef std::map<int, CommandCallback> CommandCallbackMap;
@@ -298,8 +295,7 @@ class PortForwardingController::Connection
void OnFrameRead(const std::string& message) override;
void OnSocketClosed() override;
- PortForwardingController::Registry* registry_;
- scoped_refptr<AndroidDeviceManager::Device> device_;
+ PortForwardingController* controller_;
scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_;
scoped_ptr<AndroidDeviceManager::AndroidWebSocket> web_socket_;
int command_id_;
@@ -313,29 +309,30 @@ class PortForwardingController::Connection
};
PortForwardingController::Connection::Connection(
- Registry* registry,
- scoped_refptr<AndroidDeviceManager::Device> device,
+ PortForwardingController* controller,
scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser,
const ForwardingMap& forwarding_map)
- : registry_(registry),
- device_(device),
+ : controller_(controller),
browser_(browser),
command_id_(0),
connected_(false),
forwarding_map_(forwarding_map),
weak_factory_(this) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- (*registry_)[device_->serial()] = this;
+ controller_->registry_[browser->serial()] = this;
+ scoped_refptr<AndroidDeviceManager::Device> device(
+ controller_->bridge_->FindDevice(browser->serial()));
+ DCHECK(device.get());
web_socket_.reset(
- device_->CreateWebSocket(browser->socket(),
- kDevToolsRemoteBrowserTarget, this));
+ device->CreateWebSocket(browser->socket(),
+ kDevToolsRemoteBrowserTarget, this));
}
PortForwardingController::Connection::~Connection() {
-
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(registry_->find(device_->serial()) != registry_->end());
- registry_->erase(device_->serial());
+ DCHECK(controller_->registry_.find(browser_->serial()) !=
+ controller_->registry_.end());
+ controller_->registry_.erase(browser_->serial());
}
void PortForwardingController::Connection::UpdateForwardingMap(
@@ -515,7 +512,10 @@ void PortForwardingController::Connection::OnFrameRead(
base::Bind(&Connection::UpdateSocketCountOnHandlerThread,
weak_factory_.GetWeakPtr(), port);
- device_->OpenSocket(
+ scoped_refptr<AndroidDeviceManager::Device> device(
+ controller_->bridge_->FindDevice(browser_->serial()));
+ DCHECK(device.get());
+ device->OpenSocket(
connection_id.c_str(),
base::Bind(&SocketTunnel::StartTunnel,
destination_host,
@@ -523,8 +523,11 @@ void PortForwardingController::Connection::OnFrameRead(
callback));
}
-PortForwardingController::PortForwardingController(Profile* profile)
+PortForwardingController::PortForwardingController(
+ Profile* profile,
+ DevToolsAndroidBridge* bridge)
: profile_(profile),
+ bridge_(bridge),
pref_service_(profile->GetPrefs()) {
pref_change_registrar_.Init(pref_service_);
base::Closure callback = base::Bind(
@@ -538,23 +541,20 @@ PortForwardingController::~PortForwardingController() {}
PortForwardingController::ForwardingStatus
PortForwardingController::DeviceListChanged(
- const DevToolsAndroidBridge::CompleteDevices& complete_devices) {
+ const DevToolsAndroidBridge::RemoteDevices& devices) {
ForwardingStatus status;
if (forwarding_map_.empty())
return status;
- for (const auto& pair : complete_devices) {
- scoped_refptr<AndroidDeviceManager::Device> device(pair.first);
- scoped_refptr<DevToolsAndroidBridge::RemoteDevice> remote_device(
- pair.second);
- if (!remote_device->is_connected())
+ for (const auto& device : devices) {
+ if (!device->is_connected())
continue;
- Registry::iterator rit = registry_.find(remote_device->serial());
+ Registry::iterator rit = registry_.find(device->serial());
if (rit == registry_.end()) {
scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser(
- FindBestBrowserForTethering(remote_device->browsers()));
+ FindBestBrowserForTethering(device->browsers()));
if (browser.get())
- new Connection(&registry_, device, browser, forwarding_map_);
+ new Connection(this, browser, forwarding_map_);
} else {
status.push_back(std::make_pair(rit->second->browser(),
rit->second->GetPortStatusMap()));
« no previous file with comments | « chrome/browser/devtools/device/port_forwarding_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698