| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <signal.h> | 6 #include <signal.h> |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <sys/wait.h> | 8 #include <sys/wait.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 HostControllersManager() | 86 HostControllersManager() |
| 87 : controllers_(new HostControllerMap()), | 87 : controllers_(new HostControllerMap()), |
| 88 has_failed_(false), | 88 has_failed_(false), |
| 89 weak_ptr_factory_(this) { | 89 weak_ptr_factory_(this) { |
| 90 } | 90 } |
| 91 | 91 |
| 92 ~HostControllersManager() { | 92 ~HostControllersManager() { |
| 93 if (!thread_.get()) | 93 if (!thread_.get()) |
| 94 return; | 94 return; |
| 95 // Delete the controllers on the thread they were created on. | 95 // Delete the controllers on the thread they were created on. |
| 96 thread_->message_loop_proxy()->DeleteSoon( | 96 thread_->task_runner()->DeleteSoon(FROM_HERE, controllers_.release()); |
| 97 FROM_HERE, controllers_.release()); | |
| 98 } | 97 } |
| 99 | 98 |
| 100 void HandleRequest(const std::string& adb_path, | 99 void HandleRequest(const std::string& adb_path, |
| 101 const std::string& device_serial, | 100 const std::string& device_serial, |
| 102 int device_port, | 101 int device_port, |
| 103 int host_port, | 102 int host_port, |
| 104 scoped_ptr<Socket> client_socket) { | 103 scoped_ptr<Socket> client_socket) { |
| 105 // Lazy initialize so that the CLI process doesn't get this thread created. | 104 // Lazy initialize so that the CLI process doesn't get this thread created. |
| 106 InitOnce(); | 105 InitOnce(); |
| 107 thread_->message_loop_proxy()->PostTask( | 106 thread_->task_runner()->PostTask( |
| 108 FROM_HERE, | 107 FROM_HERE, |
| 109 base::Bind(&HostControllersManager::HandleRequestOnInternalThread, | 108 base::Bind(&HostControllersManager::HandleRequestOnInternalThread, |
| 110 base::Unretained(this), adb_path, device_serial, device_port, | 109 base::Unretained(this), adb_path, device_serial, device_port, |
| 111 host_port, base::Passed(&client_socket))); | 110 host_port, base::Passed(&client_socket))); |
| 112 } | 111 } |
| 113 | 112 |
| 114 bool has_failed() const { return has_failed_; } | 113 bool has_failed() const { return has_failed_; } |
| 115 | 114 |
| 116 private: | 115 private: |
| 117 typedef base::hash_map< | 116 typedef base::hash_map< |
| (...skipping 18 matching lines...) Expand all Loading... |
| 136 const base::WeakPtr<HostControllersManager>& manager_ptr, | 135 const base::WeakPtr<HostControllersManager>& manager_ptr, |
| 137 scoped_ptr<HostController> host_controller) { | 136 scoped_ptr<HostController> host_controller) { |
| 138 HostController* const controller = host_controller.release(); | 137 HostController* const controller = host_controller.release(); |
| 139 HostControllersManager* const manager = manager_ptr.get(); | 138 HostControllersManager* const manager = manager_ptr.get(); |
| 140 if (!manager) { | 139 if (!manager) { |
| 141 // Note that |controller| is not leaked in this case since the host | 140 // Note that |controller| is not leaked in this case since the host |
| 142 // controllers manager owns the controllers. If the manager was deleted | 141 // controllers manager owns the controllers. If the manager was deleted |
| 143 // then all the controllers (including |controller|) were also deleted. | 142 // then all the controllers (including |controller|) were also deleted. |
| 144 return; | 143 return; |
| 145 } | 144 } |
| 146 DCHECK(manager->thread_->message_loop_proxy()->RunsTasksOnCurrentThread()); | 145 DCHECK(manager->thread_->task_runner()->RunsTasksOnCurrentThread()); |
| 147 // Note that this will delete |controller| which is owned by the map. | 146 // Note that this will delete |controller| which is owned by the map. |
| 148 DeleteRefCountedValueInMap( | 147 DeleteRefCountedValueInMap( |
| 149 MakeHostControllerMapKey( | 148 MakeHostControllerMapKey( |
| 150 controller->adb_port(), controller->device_port()), | 149 controller->adb_port(), controller->device_port()), |
| 151 manager->controllers_.get()); | 150 manager->controllers_.get()); |
| 152 } | 151 } |
| 153 | 152 |
| 154 void HandleRequestOnInternalThread(const std::string& adb_path, | 153 void HandleRequestOnInternalThread(const std::string& adb_path, |
| 155 const std::string& device_serial, | 154 const std::string& device_serial, |
| 156 int device_port, | 155 int device_port, |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 457 |
| 459 return client_delegate.has_failed() || daemon_delegate.has_failed(); | 458 return client_delegate.has_failed() || daemon_delegate.has_failed(); |
| 460 } | 459 } |
| 461 | 460 |
| 462 } // namespace | 461 } // namespace |
| 463 } // namespace forwarder2 | 462 } // namespace forwarder2 |
| 464 | 463 |
| 465 int main(int argc, char** argv) { | 464 int main(int argc, char** argv) { |
| 466 return forwarder2::RunHostForwarder(argc, argv); | 465 return forwarder2::RunHostForwarder(argc, argv); |
| 467 } | 466 } |
| OLD | NEW |