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