Chromium Code Reviews| Index: tools/android/forwarder2/host_forwarder_main.cc |
| diff --git a/tools/android/forwarder2/host_forwarder_main.cc b/tools/android/forwarder2/host_forwarder_main.cc |
| index 1071aa7dd42a82d7b0db8b92695c079c8d374ca7..131de1a4570fd002f5cdbb63d66e4edb6b7569df 100644 |
| --- a/tools/android/forwarder2/host_forwarder_main.cc |
| +++ b/tools/android/forwarder2/host_forwarder_main.cc |
| @@ -175,6 +175,8 @@ class HostControllersManager { |
| SendMessage( |
| !removed_elements ? "ERROR: could not unmap port" : "OK", |
| client_socket.get()); |
| + |
| + RemoveAdbPortForDeviceIfNeeded(device_serial); |
| return; |
| } |
| if (host_port < 0) { |
| @@ -217,6 +219,33 @@ class HostControllersManager { |
| linked_ptr<HostController>(host_controller.release()))); |
| } |
| + void RemoveAdbPortForDeviceIfNeeded(const std::string& device_serial) { |
| + base::hash_map<std::string, int>::const_iterator it = |
| + device_serial_to_adb_port_map_.find(device_serial); |
| + if (it == device_serial_to_adb_port_map_.end()) |
| + return; |
| + |
| + int port = it->second; |
| + const std::string prefix = base::StringPrintf("%d:", port); |
| + for (HostControllerMap::const_iterator others = controllers_->begin(); |
| + others != controllers_->end(); ++others) { |
| + if (others->first.find_first_of(prefix) == 0U) |
|
Philippe
2013/10/21 15:44:58
Not sure I read the find_first_of() documentation
Philippe
2013/10/21 15:53:21
Small correction in my last paragraph: s/others->f
bulach
2013/10/21 17:19:59
yeah, that's exactly what I wanted, sorry for the
Philippe
2013/10/21 17:25:24
No worries, seems that I wasn't right either with
|
| + return; |
| + } |
| + // No other port is being forwarded to this device: |
| + // - Remove it from our internal serial -> adb port map. |
| + // - Remove from "adb forward" command. |
| + device_serial_to_adb_port_map_.erase(device_serial); |
| + const std::string serial_part = device_serial.empty() ? |
| + std::string() : std::string("-s ") + device_serial; |
| + const std::string command = base::StringPrintf( |
| + "adb %s forward --remove tcp:%d", |
| + device_serial.empty() ? "" : serial_part.c_str(), |
|
Philippe
2013/10/21 15:44:58
Nit: I guess that you can apply the fix here that
bulach
2013/10/21 17:19:59
Done.
|
| + port); |
| + LOG(INFO) << command; |
| + system(command.c_str()); |
| + } |
| + |
| int GetAdbPortForDevice(const std::string& device_serial) { |
| base::hash_map<std::string, int>::const_iterator it = |
| device_serial_to_adb_port_map_.find(device_serial); |
| @@ -230,7 +259,7 @@ class HostControllersManager { |
| std::string() : std::string("-s ") + device_serial; |
| const std::string command = base::StringPrintf( |
| "adb %s forward tcp:%d localabstract:chrome_device_forwarder", |
| - device_serial.empty() ? "" : serial_part.c_str(), |
| + serial_part.c_str(), |
| port); |
| LOG(INFO) << command; |
| const int ret = system(command.c_str()); |