Index: tools/android/forwarder2/host_controller.h |
diff --git a/tools/android/forwarder2/host_controller.h b/tools/android/forwarder2/host_controller.h |
index dc75f88e057760dbd9bd5261ee31b2d791d0334a..1b5789b8740340c08bf519d9a8ad9ab634d16c44 100644 |
--- a/tools/android/forwarder2/host_controller.h |
+++ b/tools/android/forwarder2/host_controller.h |
@@ -23,36 +23,39 @@ class HostController { |
public: |
// Callback used for self-deletion that lets the client perform some cleanup |
// work before deleting the HostController instance. |
- typedef base::Callback<void (HostController*)> DeleteCallback; |
+ typedef base::Callback<void (scoped_ptr<HostController>)> DeletionCallback; |
- // If |device_port| is zero, it dynamically allocates a port. |
- HostController(int device_port, |
- const std::string& forward_to_host, |
- int forward_to_host_port, |
- int adb_port, |
- int exit_notifier_fd, |
- const DeleteCallback& delete_callback); |
+ // If |device_port| is zero then a dynamic port is allocated (and retrievable |
+ // through device_port() below). |
+ static scoped_ptr<HostController> Create( |
+ int device_port, |
+ int host_port, |
+ int adb_port, |
+ int exit_notifier_fd, |
+ const DeletionCallback& deletion_callback); |
~HostController(); |
- // Connects to the device forwarder app and sets the |device_port_| to the |
- // dynamically allocated port (when the provided |device_port| is zero). |
- // Returns true on success. Clients must call Connect() before calling |
- // Start(). |
- bool Connect(); |
- |
// Starts the internal controller thread. |
void Start(); |
int adb_port() const { return adb_port_; } |
- // Gets the current device allocated port. Must be called after Connect(). |
int device_port() const { return device_port_; } |
private: |
- void ThreadHandler(); |
+ HostController(int device_port, |
+ int host_port, |
+ int adb_port, |
+ int exit_notifier_fd, |
+ const DeletionCallback& deletion_callback, |
+ scoped_ptr<Socket> adb_control_socket, |
+ scoped_ptr<PipeNotifier> delete_controller_notifier); |
- void StartForwarder(scoped_ptr<Socket> host_server_data_socket_ptr); |
+ void ReadNextCommandSoon(); |
+ void ReadCommandOnInternalThread(); |
+ |
+ void StartForwarder(scoped_ptr<Socket> host_server_data_socket); |
// Helper method that creates a socket and adds the appropriate event file |
// descriptors. |
@@ -60,19 +63,24 @@ class HostController { |
void SelfDelete(); |
- Socket adb_control_socket_; |
- int device_port_; |
- const std::string forward_to_host_; |
- const int forward_to_host_port_; |
+ static void SelfDeleteOnDeletionTaskRunner( |
+ const DeletionCallback& deletion_callback, |
+ scoped_ptr<HostController> controller); |
+ |
+ const int device_port_; |
+ const int host_port_; |
const int adb_port_; |
// Used to notify the controller when the process is killed. |
const int global_exit_notifier_fd_; |
// Used to let the client delete the instance in case an error happened. |
- const DeleteCallback delete_callback_; |
+ const DeletionCallback deletion_callback_; |
+ scoped_ptr<Socket> adb_control_socket_; |
+ scoped_ptr<PipeNotifier> delete_controller_notifier_; |
// Used to cancel the pending blocking IO operations when the host controller |
// instance is deleted. |
- PipeNotifier delete_controller_notifier_; |
- bool ready_; |
+ // Task runner used for deletion set at construction time (i.e. the object is |
+ // deleted on the same thread it is created on). |
+ const scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_; |
base::Thread thread_; |
DISALLOW_COPY_AND_ASSIGN(HostController); |