| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (!g_notifier->Notify() || s_kill_handler_count > 2) | 78 if (!g_notifier->Notify() || s_kill_handler_count > 2) |
| 79 exit(1); | 79 exit(1); |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Manages HostController instances. There is one HostController instance for | 82 // Manages HostController instances. There is one HostController instance for |
| 83 // each connection being forwarded. Note that forwarding can happen with many | 83 // each connection being forwarded. Note that forwarding can happen with many |
| 84 // devices (identified with a serial id). | 84 // devices (identified with a serial id). |
| 85 class HostControllersManager { | 85 class HostControllersManager { |
| 86 public: | 86 public: |
| 87 HostControllersManager() | 87 HostControllersManager() |
| 88 : weak_ptr_factory_(this), | 88 : controllers_(new HostControllerMap()), |
| 89 controllers_(new HostControllerMap()), | 89 has_failed_(false), |
| 90 has_failed_(false) { | 90 weak_ptr_factory_(this) { |
| 91 } | 91 } |
| 92 | 92 |
| 93 ~HostControllersManager() { | 93 ~HostControllersManager() { |
| 94 if (!thread_.get()) | 94 if (!thread_.get()) |
| 95 return; | 95 return; |
| 96 // Delete the controllers on the thread they were created on. | 96 // Delete the controllers on the thread they were created on. |
| 97 thread_->message_loop_proxy()->DeleteSoon( | 97 thread_->message_loop_proxy()->DeleteSoon( |
| 98 FROM_HERE, controllers_.release()); | 98 FROM_HERE, controllers_.release()); |
| 99 } | 99 } |
| 100 | 100 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 284 } |
| 285 | 285 |
| 286 bool SendMessage(const std::string& msg, Socket* client_socket) { | 286 bool SendMessage(const std::string& msg, Socket* client_socket) { |
| 287 bool result = client_socket->WriteString(msg); | 287 bool result = client_socket->WriteString(msg); |
| 288 DCHECK(result); | 288 DCHECK(result); |
| 289 if (!result) | 289 if (!result) |
| 290 has_failed_ = true; | 290 has_failed_ = true; |
| 291 return result; | 291 return result; |
| 292 } | 292 } |
| 293 | 293 |
| 294 base::WeakPtrFactory<HostControllersManager> weak_ptr_factory_; | |
| 295 base::hash_map<std::string, int> device_serial_to_adb_port_map_; | 294 base::hash_map<std::string, int> device_serial_to_adb_port_map_; |
| 296 scoped_ptr<HostControllerMap> controllers_; | 295 scoped_ptr<HostControllerMap> controllers_; |
| 297 bool has_failed_; | 296 bool has_failed_; |
| 298 scoped_ptr<base::AtExitManager> at_exit_manager_; // Needed by base::Thread. | 297 scoped_ptr<base::AtExitManager> at_exit_manager_; // Needed by base::Thread. |
| 299 scoped_ptr<base::Thread> thread_; | 298 scoped_ptr<base::Thread> thread_; |
| 299 base::WeakPtrFactory<HostControllersManager> weak_ptr_factory_; |
| 300 }; | 300 }; |
| 301 | 301 |
| 302 class ServerDelegate : public Daemon::ServerDelegate { | 302 class ServerDelegate : public Daemon::ServerDelegate { |
| 303 public: | 303 public: |
| 304 ServerDelegate() : has_failed_(false) {} | 304 ServerDelegate() : has_failed_(false) {} |
| 305 | 305 |
| 306 bool has_failed() const { | 306 bool has_failed() const { |
| 307 return has_failed_ || controllers_manager_.has_failed(); | 307 return has_failed_ || controllers_manager_.has_failed(); |
| 308 } | 308 } |
| 309 | 309 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 448 |
| 449 return client_delegate.has_failed() || daemon_delegate.has_failed(); | 449 return client_delegate.has_failed() || daemon_delegate.has_failed(); |
| 450 } | 450 } |
| 451 | 451 |
| 452 } // namespace | 452 } // namespace |
| 453 } // namespace forwarder2 | 453 } // namespace forwarder2 |
| 454 | 454 |
| 455 int main(int argc, char** argv) { | 455 int main(int argc, char** argv) { |
| 456 return forwarder2::RunHostForwarder(argc, argv); | 456 return forwarder2::RunHostForwarder(argc, argv); |
| 457 } | 457 } |
| OLD | NEW |