Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: tools/android/forwarder2/host_controller.cc

Issue 19478003: Remove Thread wrapper class in forwarder2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/android/forwarder2/host_controller.cc
diff --git a/tools/android/forwarder2/host_controller.cc b/tools/android/forwarder2/host_controller.cc
index d98a4ad2e7c7cdc0a8c8ffc0177f6a449f37f163..fcf0e41917bfc974bc9e9b407c6abf26ff899e96 100644
--- a/tools/android/forwarder2/host_controller.cc
+++ b/tools/android/forwarder2/host_controller.cc
@@ -70,41 +70,42 @@ bool HostController::Connect() {
void HostController::Start() {
thread_.Start();
+ ReadNextCommandSoon();
+}
+
+void HostController::ReadNextCommandSoon() {
thread_.message_loop_proxy()->PostTask(
FROM_HERE,
- base::Bind(&HostController::ThreadHandler, base::Unretained(this)));
+ base::Bind(&HostController::ReadCommandOnInternalThread,
+ base::Unretained(this)));
}
-void HostController::ThreadHandler() {
+void HostController::ReadCommandOnInternalThread() {
CHECK(ready_) << "HostController not ready. Must call Connect() first.";
- while (true) {
- if (!ReceivedCommand(command::ACCEPT_SUCCESS, &adb_control_socket_)) {
- SelfDelete();
- return;
- }
- // Try to connect to host server.
- scoped_ptr<Socket> host_server_data_socket(CreateSocket());
- if (!host_server_data_socket->ConnectTcp(
- forward_to_host_, forward_to_host_port_)) {
- LOG(ERROR) << "Could not Connect HostServerData socket on port: "
- << forward_to_host_port_;
- SendCommand(command::HOST_SERVER_ERROR,
- device_port_,
- &adb_control_socket_);
- if (ReceivedCommand(command::ACK, &adb_control_socket_)) {
- // It can continue if the host forwarder could not connect to the host
- // server but the device acknowledged that, so that the device could
- // re-try later.
- continue;
- }
- SelfDelete();
+ if (!ReceivedCommand(command::ACCEPT_SUCCESS, &adb_control_socket_)) {
+ SelfDelete();
+ return;
+ }
+ // Try to connect to host server.
+ scoped_ptr<Socket> host_server_data_socket(CreateSocket());
+ if (!host_server_data_socket->ConnectTcp(
+ forward_to_host_, forward_to_host_port_)) {
+ LOG(ERROR) << "Could not Connect HostServerData socket on port: "
+ << forward_to_host_port_;
+ SendCommand(command::HOST_SERVER_ERROR, device_port_, &adb_control_socket_);
+ if (ReceivedCommand(command::ACK, &adb_control_socket_)) {
+ // It can continue if the host forwarder could not connect to the host
+ // server but the device acknowledged that, so that the device could
+ // re-try later.
+ ReadNextCommandSoon();
return;
}
- SendCommand(command::HOST_SERVER_SUCCESS,
- device_port_,
- &adb_control_socket_);
- StartForwarder(host_server_data_socket.Pass());
+ SelfDelete();
+ return;
}
+ SendCommand(command::HOST_SERVER_SUCCESS, device_port_, &adb_control_socket_);
+ StartForwarder(host_server_data_socket.Pass());
+ ReadNextCommandSoon();
}
void HostController::StartForwarder(
@@ -130,10 +131,8 @@ void HostController::StartForwarder(
SelfDelete();
return;
}
- Forwarder* forwarder = new Forwarder(host_server_data_socket.Pass(),
- adb_data_socket.Pass());
- // Forwarder object will self delete after returning.
- forwarder->Start();
+ forwarder2::StartForwarder(
+ host_server_data_socket.Pass(), adb_data_socket.Pass());
}
scoped_ptr<Socket> HostController::CreateSocket() {

Powered by Google App Engine
This is Rietveld 408576698