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

Side by Side Diff: tools/android/forwarder2/host_controller.h

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "tools/android/forwarder2/pipe_notifier.h" 15 #include "tools/android/forwarder2/pipe_notifier.h"
16 #include "tools/android/forwarder2/socket.h" 16 #include "tools/android/forwarder2/socket.h"
17 17
18 namespace forwarder2 { 18 namespace forwarder2 {
19 19
20 class HostProxy; 20 class HostProxy;
21 21
22 class HostController { 22 class HostController {
23 public: 23 public:
24 // Callback used for self-deletion that lets the client perform some cleanup 24 // Callback used for self-deletion that lets the client perform some cleanup
25 // work before deleting the HostController instance. 25 // work before deleting the HostController instance.
26 typedef base::Callback<void (HostController*)> DeleteCallback; 26 typedef base::Callback<void (HostController*)> DeleteCallback;
27 27
28 // If |device_port| is zero, it dynamically allocates a port. 28 // If |device_port| is zero, it dynamically allocates a port.
29 HostController(int device_port, 29 HostController(int device_port,
Philippe 2013/07/22 15:16:14 FYI, I added a static factory method like I also d
30 const std::string& forward_to_host, 30 const std::string& forward_to_host,
31 int forward_to_host_port, 31 int forward_to_host_port,
32 int adb_port, 32 int adb_port,
33 int exit_notifier_fd, 33 int exit_notifier_fd,
34 const DeleteCallback& delete_callback); 34 const DeleteCallback& delete_callback);
35 35
36 ~HostController(); 36 ~HostController();
37 37
38 // Connects to the device forwarder app and sets the |device_port_| to the 38 // Connects to the device forwarder app and sets the |device_port_| to the
39 // dynamically allocated port (when the provided |device_port| is zero). 39 // dynamically allocated port (when the provided |device_port| is zero).
40 // Returns true on success. Clients must call Connect() before calling 40 // Returns true on success. Clients must call Connect() before calling
41 // Start(). 41 // Start().
42 bool Connect(); 42 bool Connect();
43 43
44 // Starts the internal controller thread. 44 // Starts the internal controller thread.
45 void Start(); 45 void Start();
46 46
47 int adb_port() const { return adb_port_; } 47 int adb_port() const { return adb_port_; }
48 48
49 // Gets the current device allocated port. Must be called after Connect(). 49 // Gets the current device allocated port. Must be called after Connect().
50 int device_port() const { return device_port_; } 50 int device_port() const { return device_port_; }
51 51
52 private: 52 private:
53 void ThreadHandler(); 53 void ReadNextCommandSoon();
54 void ReadCommandOnInternalThread();
54 55
55 void StartForwarder(scoped_ptr<Socket> host_server_data_socket_ptr); 56 void StartForwarder(scoped_ptr<Socket> host_server_data_socket);
56 57
57 // Helper method that creates a socket and adds the appropriate event file 58 // Helper method that creates a socket and adds the appropriate event file
58 // descriptors. 59 // descriptors.
59 scoped_ptr<Socket> CreateSocket(); 60 scoped_ptr<Socket> CreateSocket();
60 61
61 void SelfDelete(); 62 void SelfDelete();
62 63
63 Socket adb_control_socket_; 64 Socket adb_control_socket_;
64 int device_port_; 65 int device_port_;
65 const std::string forward_to_host_; 66 const std::string forward_to_host_;
66 const int forward_to_host_port_; 67 const int forward_to_host_port_;
67 const int adb_port_; 68 const int adb_port_;
68 // Used to notify the controller when the process is killed. 69 // Used to notify the controller when the process is killed.
69 const int global_exit_notifier_fd_; 70 const int global_exit_notifier_fd_;
70 // Used to let the client delete the instance in case an error happened. 71 // Used to let the client delete the instance in case an error happened.
71 const DeleteCallback delete_callback_; 72 const DeleteCallback delete_callback_;
72 // Used to cancel the pending blocking IO operations when the host controller 73 // Used to cancel the pending blocking IO operations when the host controller
73 // instance is deleted. 74 // instance is deleted.
74 PipeNotifier delete_controller_notifier_; 75 PipeNotifier delete_controller_notifier_;
75 bool ready_; 76 bool ready_;
76 base::Thread thread_; 77 base::Thread thread_;
77 78
78 DISALLOW_COPY_AND_ASSIGN(HostController); 79 DISALLOW_COPY_AND_ASSIGN(HostController);
79 }; 80 };
80 81
81 } // namespace forwarder2 82 } // namespace forwarder2
82 83
83 #endif // TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_ 84 #endif // TOOLS_ANDROID_FORWARDER2_HOST_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698