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

Unified Diff: chrome/browser/devtools/device/port_forwarding_controller.cc

Issue 500373004: DevTools: Make port forwarding part of DevToolsAndroidBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed. Rebased Created 6 years, 3 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
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 2fff9f28b3a313ebe096c2dac833f8705bd67984..6de8c30fb96cdb1cf19037e4076c6c88a7291ee2 100644
--- a/chrome/browser/devtools/device/port_forwarding_controller.cc
+++ b/chrome/browser/devtools/device/port_forwarding_controller.cc
@@ -531,8 +531,7 @@ void PortForwardingController::Connection::OnFrameRead(
PortForwardingController::PortForwardingController(Profile* profile)
: profile_(profile),
- pref_service_(profile->GetPrefs()),
- listening_(false) {
+ pref_service_(profile->GetPrefs()) {
pref_change_registrar_.Init(pref_service_);
base::Closure callback = base::Bind(
&PortForwardingController::OnPrefsChange, base::Unretained(this));
@@ -541,29 +540,14 @@ PortForwardingController::PortForwardingController(Profile* profile)
OnPrefsChange();
}
-
PortForwardingController::~PortForwardingController() {}
-void PortForwardingController::Shutdown() {
- // Existing connection will not be shut down. This might be confusing for
- // some users, but the opposite is more confusing.
- StopListening();
-}
-
-void PortForwardingController::AddListener(Listener* listener) {
- listeners_.push_back(listener);
-}
-
-void PortForwardingController::RemoveListener(Listener* listener) {
- Listeners::iterator it =
- std::find(listeners_.begin(), listeners_.end(), listener);
- DCHECK(it != listeners_.end());
- listeners_.erase(it);
-}
-
-void PortForwardingController::DeviceListChanged(
+PortForwardingController::DevicesStatus
+PortForwardingController::DeviceListChanged(
const DevToolsAndroidBridge::RemoteDevices& devices) {
DevicesStatus status;
+ if (forwarding_map_.empty())
+ return status;
for (DevToolsAndroidBridge::RemoteDevices::const_iterator it =
devices.begin(); it != devices.end(); ++it) {
@@ -582,7 +566,7 @@ void PortForwardingController::DeviceListChanged(
}
}
- NotifyListeners(status);
+ return status;
}
void PortForwardingController::OnPrefsChange() {
@@ -602,36 +586,12 @@ void PortForwardingController::OnPrefsChange() {
}
if (!forwarding_map_.empty()) {
- StartListening();
UpdateConnections();
} else {
- StopListening();
ShutdownConnections();
- NotifyListeners(DevicesStatus());
}
}
-void PortForwardingController::StartListening() {
- if (listening_)
- return;
- listening_ = true;
- DevToolsAndroidBridge* android_bridge =
- DevToolsAndroidBridge::Factory::GetForProfile(profile_);
- if (android_bridge)
- android_bridge->AddDeviceListListener(this);
-
-}
-
-void PortForwardingController::StopListening() {
- if (!listening_)
- return;
- listening_ = false;
- DevToolsAndroidBridge* android_bridge =
- DevToolsAndroidBridge::Factory::GetForProfile(profile_);
- if (android_bridge)
- android_bridge->RemoveDeviceListListener(this);
-}
-
void PortForwardingController::UpdateConnections() {
for (Registry::iterator it = registry_.begin(); it != registry_.end(); ++it)
it->second->UpdateForwardingMap(forwarding_map_);
@@ -642,36 +602,3 @@ void PortForwardingController::ShutdownConnections() {
it->second->Shutdown();
registry_.clear();
}
-
-void PortForwardingController::NotifyListeners(
- const DevicesStatus& status) const {
- Listeners copy(listeners_); // Iterate over copy.
- for (Listeners::const_iterator it = copy.begin(); it != copy.end(); ++it)
- (*it)->PortStatusChanged(status);
-}
-
-// static
-PortForwardingController::Factory*
-PortForwardingController::Factory::GetInstance() {
- return Singleton<PortForwardingController::Factory>::get();
-}
-
-// static
-PortForwardingController* PortForwardingController::Factory::GetForProfile(
- Profile* profile) {
- return static_cast<PortForwardingController*>(GetInstance()->
- GetServiceForBrowserContext(profile, true));
-}
-
-PortForwardingController::Factory::Factory()
- : BrowserContextKeyedServiceFactory(
- "PortForwardingController",
- BrowserContextDependencyManager::GetInstance()) {}
-
-PortForwardingController::Factory::~Factory() {}
-
-KeyedService* PortForwardingController::Factory::BuildServiceInstanceFor(
- content::BrowserContext* context) const {
- Profile* profile = Profile::FromBrowserContext(context);
- return new PortForwardingController(profile);
-}
« no previous file with comments | « chrome/browser/devtools/device/port_forwarding_controller.h ('k') | chrome/browser/devtools/devtools_targets_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698