| 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 "tools/android/forwarder2/device_controller.h" | 5 #include "tools/android/forwarder2/device_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | |
| 15 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 16 #include "tools/android/forwarder2/command.h" | 15 #include "tools/android/forwarder2/command.h" |
| 17 #include "tools/android/forwarder2/device_listener.h" | 16 #include "tools/android/forwarder2/device_listener.h" |
| 18 #include "tools/android/forwarder2/socket.h" | 17 #include "tools/android/forwarder2/socket.h" |
| 19 #include "tools/android/forwarder2/util.h" | 18 #include "tools/android/forwarder2/util.h" |
| 20 | 19 |
| 21 namespace forwarder2 { | 20 namespace forwarder2 { |
| 22 | 21 |
| 23 // static | 22 // static |
| 24 scoped_ptr<DeviceController> DeviceController::Create( | 23 scoped_ptr<DeviceController> DeviceController::Create( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 } | 41 } |
| 43 | 42 |
| 44 void DeviceController::Start() { | 43 void DeviceController::Start() { |
| 45 AcceptHostCommandSoon(); | 44 AcceptHostCommandSoon(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 DeviceController::DeviceController(scoped_ptr<Socket> host_socket, | 47 DeviceController::DeviceController(scoped_ptr<Socket> host_socket, |
| 49 int exit_notifier_fd) | 48 int exit_notifier_fd) |
| 50 : host_socket_(host_socket.Pass()), | 49 : host_socket_(host_socket.Pass()), |
| 51 exit_notifier_fd_(exit_notifier_fd), | 50 exit_notifier_fd_(exit_notifier_fd), |
| 52 construction_task_runner_(base::MessageLoopProxy::current()), | 51 construction_task_runner_(base::MessageLoop::current()->task_runner()), |
| 53 weak_ptr_factory_(this) { | 52 weak_ptr_factory_(this) { |
| 54 host_socket_->AddEventFd(exit_notifier_fd); | 53 host_socket_->AddEventFd(exit_notifier_fd); |
| 55 } | 54 } |
| 56 | 55 |
| 57 void DeviceController::AcceptHostCommandSoon() { | 56 void DeviceController::AcceptHostCommandSoon() { |
| 58 base::MessageLoopProxy::current()->PostTask( | 57 base::MessageLoop::current()->PostTask( |
| 59 FROM_HERE, | 58 FROM_HERE, base::Bind(&DeviceController::AcceptHostCommandInternal, |
| 60 base::Bind(&DeviceController::AcceptHostCommandInternal, | 59 base::Unretained(this))); |
| 61 base::Unretained(this))); | |
| 62 } | 60 } |
| 63 | 61 |
| 64 void DeviceController::AcceptHostCommandInternal() { | 62 void DeviceController::AcceptHostCommandInternal() { |
| 65 scoped_ptr<Socket> socket(new Socket); | 63 scoped_ptr<Socket> socket(new Socket); |
| 66 if (!host_socket_->Accept(socket.get())) { | 64 if (!host_socket_->Accept(socket.get())) { |
| 67 if (!host_socket_->DidReceiveEvent()) | 65 if (!host_socket_->DidReceiveEvent()) |
| 68 PLOG(ERROR) << "Could not Accept DeviceController socket"; | 66 PLOG(ERROR) << "Could not Accept DeviceController socket"; |
| 69 else | 67 else |
| 70 LOG(INFO) << "Received exit notification"; | 68 LOG(INFO) << "Received exit notification"; |
| 71 return; | 69 return; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return; | 147 return; |
| 150 } | 148 } |
| 151 DCHECK(controller->construction_task_runner_->RunsTasksOnCurrentThread()); | 149 DCHECK(controller->construction_task_runner_->RunsTasksOnCurrentThread()); |
| 152 bool listener_did_exist = DeleteRefCountedValueInMap( | 150 bool listener_did_exist = DeleteRefCountedValueInMap( |
| 153 listener->listener_port(), &controller->listeners_); | 151 listener->listener_port(), &controller->listeners_); |
| 154 DCHECK(listener_did_exist); | 152 DCHECK(listener_did_exist); |
| 155 // Note that |listener| was deleted by DeleteRefCountedValueInMap(). | 153 // Note that |listener| was deleted by DeleteRefCountedValueInMap(). |
| 156 } | 154 } |
| 157 | 155 |
| 158 } // namespace forwarder | 156 } // namespace forwarder |
| OLD | NEW |