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 NET_TEST_SPAWNED_TEST_SERVER_SPAWNER_COMMUNICATOR_H_ | 5 #ifndef NET_TEST_SPAWNED_TEST_SERVER_SPAWNER_COMMUNICATOR_H_ |
6 #define NET_TEST_SPAWNED_TEST_SERVER_SPAWNER_COMMUNICATOR_H_ | 6 #define NET_TEST_SPAWNED_TEST_SERVER_SPAWNER_COMMUNICATOR_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <string> | 10 #include <string> |
9 | 11 |
10 #include "base/basictypes.h" | |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
15 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 class ScopedPortException; | 20 class ScopedPortException; |
20 | 21 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // Path: "/ping". | 54 // Path: "/ping". |
54 // Method: "GET". | 55 // Method: "GET". |
55 // Data to server: None. | 56 // Data to server: None. |
56 // Data from server: String "ready" returned if success. | 57 // Data from server: String "ready" returned if success. |
57 // | 58 // |
58 // The internal I/O thread is required by net stack to perform net I/O. | 59 // The internal I/O thread is required by net stack to perform net I/O. |
59 // The Start/StopServer methods block the caller thread until result is | 60 // The Start/StopServer methods block the caller thread until result is |
60 // fetched from spawner server or timed-out. | 61 // fetched from spawner server or timed-out. |
61 class SpawnerCommunicator : public URLRequest::Delegate { | 62 class SpawnerCommunicator : public URLRequest::Delegate { |
62 public: | 63 public: |
63 explicit SpawnerCommunicator(uint16 port); | 64 explicit SpawnerCommunicator(uint16_t port); |
64 ~SpawnerCommunicator() override; | 65 ~SpawnerCommunicator() override; |
65 | 66 |
66 // Starts an instance of the Python test server on the host/ machine. | 67 // Starts an instance of the Python test server on the host/ machine. |
67 // If successfully started, returns true, setting |*port| to the port | 68 // If successfully started, returns true, setting |*port| to the port |
68 // on the local machine that can be used to communicate with the remote | 69 // on the local machine that can be used to communicate with the remote |
69 // test server. | 70 // test server. |
70 bool StartServer(const std::string& arguments, | 71 bool StartServer(const std::string& arguments, |
71 uint16* port) WARN_UNUSED_RESULT; | 72 uint16_t* port) WARN_UNUSED_RESULT; |
72 | 73 |
73 bool StopServer() WARN_UNUSED_RESULT; | 74 bool StopServer() WARN_UNUSED_RESULT; |
74 | 75 |
75 private: | 76 private: |
76 // Starts the IO thread. Called on the user thread. | 77 // Starts the IO thread. Called on the user thread. |
77 void StartIOThread(); | 78 void StartIOThread(); |
78 | 79 |
79 // Shuts down the remote test server spawner. Called on the user thread. | 80 // Shuts down the remote test server spawner. Called on the user thread. |
80 void Shutdown(); | 81 void Shutdown(); |
81 | 82 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // A thread to communicate with test_spawner server. | 116 // A thread to communicate with test_spawner server. |
116 base::Thread io_thread_; | 117 base::Thread io_thread_; |
117 | 118 |
118 // WaitableEvent to notify whether the communication is done. | 119 // WaitableEvent to notify whether the communication is done. |
119 base::WaitableEvent event_; | 120 base::WaitableEvent event_; |
120 | 121 |
121 // The local port used to communicate with the TestServer spawner. This is | 122 // The local port used to communicate with the TestServer spawner. This is |
122 // used to control the startup and shutdown of the Python TestServer running | 123 // used to control the startup and shutdown of the Python TestServer running |
123 // on the remote machine. On Android, this port will be redirected to the | 124 // on the remote machine. On Android, this port will be redirected to the |
124 // same port on the host machine. | 125 // same port on the host machine. |
125 const uint16 port_; | 126 const uint16_t port_; |
126 | 127 |
127 // Helper to add |port_| to the list of the globally explicitly allowed ports. | 128 // Helper to add |port_| to the list of the globally explicitly allowed ports. |
128 scoped_ptr<ScopedPortException> allowed_port_; | 129 scoped_ptr<ScopedPortException> allowed_port_; |
129 | 130 |
130 // The next ID to use for |cur_request_| (monotonically increasing). | 131 // The next ID to use for |cur_request_| (monotonically increasing). |
131 int next_id_; | 132 int next_id_; |
132 | 133 |
133 // Request context used by |cur_request_|. | 134 // Request context used by |cur_request_|. |
134 scoped_ptr<URLRequestContext> context_; | 135 scoped_ptr<URLRequestContext> context_; |
135 | 136 |
136 // The current (in progress) request, or NULL. | 137 // The current (in progress) request, or NULL. |
137 scoped_ptr<URLRequest> cur_request_; | 138 scoped_ptr<URLRequest> cur_request_; |
138 | 139 |
139 // Only gets/sets |is_running_| on user's thread to avoid race-condition. | 140 // Only gets/sets |is_running_| on user's thread to avoid race-condition. |
140 bool is_running_; | 141 bool is_running_; |
141 | 142 |
142 // Factory for creating the time-out task. This takes care of revoking | 143 // Factory for creating the time-out task. This takes care of revoking |
143 // outstanding tasks when |this| is deleted. | 144 // outstanding tasks when |this| is deleted. |
144 base::WeakPtrFactory<SpawnerCommunicator> weak_factory_; | 145 base::WeakPtrFactory<SpawnerCommunicator> weak_factory_; |
145 | 146 |
146 DISALLOW_COPY_AND_ASSIGN(SpawnerCommunicator); | 147 DISALLOW_COPY_AND_ASSIGN(SpawnerCommunicator); |
147 }; | 148 }; |
148 | 149 |
149 } // namespace net | 150 } // namespace net |
150 | 151 |
151 #endif // NET_TEST_SPAWNED_TEST_SERVER_SPAWNER_COMMUNICATOR_H_ | 152 #endif // NET_TEST_SPAWNED_TEST_SERVER_SPAWNER_COMMUNICATOR_H_ |
OLD | NEW |