| 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 #ifndef TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ | 5 #ifndef TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ |
| 6 #define TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ | 6 #define TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "tools/android/forwarder2/forwarders_manager.h" |
| 15 #include "tools/android/forwarder2/pipe_notifier.h" | 17 #include "tools/android/forwarder2/pipe_notifier.h" |
| 16 #include "tools/android/forwarder2/self_deleter_helper.h" | 18 #include "tools/android/forwarder2/self_deleter_helper.h" |
| 17 #include "tools/android/forwarder2/socket.h" | 19 #include "tools/android/forwarder2/socket.h" |
| 18 | 20 |
| 19 namespace forwarder2 { | 21 namespace forwarder2 { |
| 20 | 22 |
| 21 // This class partners with DeviceController and has the same lifetime and | 23 // This class partners with DeviceController and has the same lifetime and |
| 22 // threading characteristics as DeviceListener. In a nutshell, this class | 24 // threading characteristics as DeviceListener. In a nutshell, this class |
| 23 // operates on its own thread and is destroyed on the thread it was constructed | 25 // operates on its own thread and is destroyed on the thread it was constructed |
| 24 // on. The class' deletion can happen in two different ways: | 26 // on. The class' deletion can happen in two different ways: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 int exit_notifier_fd, | 60 int exit_notifier_fd, |
| 59 const ErrorCallback& error_callback, | 61 const ErrorCallback& error_callback, |
| 60 scoped_ptr<Socket> adb_control_socket, | 62 scoped_ptr<Socket> adb_control_socket, |
| 61 scoped_ptr<PipeNotifier> delete_controller_notifier); | 63 scoped_ptr<PipeNotifier> delete_controller_notifier); |
| 62 | 64 |
| 63 void ReadNextCommandSoon(); | 65 void ReadNextCommandSoon(); |
| 64 void ReadCommandOnInternalThread(); | 66 void ReadCommandOnInternalThread(); |
| 65 | 67 |
| 66 void StartForwarder(scoped_ptr<Socket> host_server_data_socket); | 68 void StartForwarder(scoped_ptr<Socket> host_server_data_socket); |
| 67 | 69 |
| 68 // Helper method that creates a socket and adds the appropriate event file | |
| 69 // descriptors. | |
| 70 scoped_ptr<Socket> CreateSocket(); | |
| 71 | |
| 72 // Note that this gets also called when ~HostController() is invoked. | 70 // Note that this gets also called when ~HostController() is invoked. |
| 73 void OnInternalThreadError(); | 71 void OnInternalThreadError(); |
| 74 | 72 |
| 75 void UnmapPortOnDevice(); | 73 void UnmapPortOnDevice(); |
| 76 | 74 |
| 77 SelfDeleterHelper<HostController> self_deleter_helper_; | 75 SelfDeleterHelper<HostController> self_deleter_helper_; |
| 78 const int device_port_; | 76 const int device_port_; |
| 79 const int host_port_; | 77 const int host_port_; |
| 80 const int adb_port_; | 78 const int adb_port_; |
| 81 // Used to notify the controller when the process is killed. | 79 // Used to notify the controller when the process is killed. |
| 82 const int global_exit_notifier_fd_; | 80 const int global_exit_notifier_fd_; |
| 83 scoped_ptr<Socket> adb_control_socket_; | 81 scoped_ptr<Socket> adb_control_socket_; |
| 84 scoped_ptr<PipeNotifier> delete_controller_notifier_; | |
| 85 // Used to cancel the pending blocking IO operations when the host controller | 82 // Used to cancel the pending blocking IO operations when the host controller |
| 86 // instance is deleted. | 83 // instance is deleted. |
| 87 // Task runner used for deletion set at construction time (i.e. the object is | 84 scoped_ptr<PipeNotifier> delete_controller_notifier_; |
| 85 // Task runner used for deletion set at deletion time (i.e. the object is |
| 88 // deleted on the same thread it is created on). | 86 // deleted on the same thread it is created on). |
| 89 const scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_; | 87 const scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_; |
| 88 // Note that this thread must outlive |forwarders_manager_| below. The |
| 89 // ForwardersManager's internal delegate (outliving ForwardersManager) may |
| 90 // post a task to this thread when it gets deleted. Also note that |
| 91 // base::Thread joins on destruction which means that ~Thread() will only |
| 92 // return after it executed all the tasks enqueued in its message loop. This |
| 93 // also means that it is guaranteed that all the Forwarder instances owned by |
| 94 // the ForwardersManager's internal delegate are destructed before |
| 95 // ~HostController() returns. |
| 90 base::Thread thread_; | 96 base::Thread thread_; |
| 97 ForwardersManager forwarders_manager_; |
| 91 | 98 |
| 92 DISALLOW_COPY_AND_ASSIGN(HostController); | 99 DISALLOW_COPY_AND_ASSIGN(HostController); |
| 93 }; | 100 }; |
| 94 | 101 |
| 95 } // namespace forwarder2 | 102 } // namespace forwarder2 |
| 96 | 103 |
| 97 #endif // TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ | 104 #endif // TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ |
| OLD | NEW |