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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Method: "GET". | 54 // Method: "GET". |
55 // Data to server: None. | 55 // Data to server: None. |
56 // Data from server: String "ready" returned if success. | 56 // Data from server: String "ready" returned if success. |
57 // | 57 // |
58 // 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. |
59 // The Start/StopServer methods block the caller thread until result is | 59 // The Start/StopServer methods block the caller thread until result is |
60 // fetched from spawner server or timed-out. | 60 // fetched from spawner server or timed-out. |
61 class SpawnerCommunicator : public net::URLRequest::Delegate { | 61 class SpawnerCommunicator : public net::URLRequest::Delegate { |
62 public: | 62 public: |
63 explicit SpawnerCommunicator(uint16 port); | 63 explicit SpawnerCommunicator(uint16 port); |
64 virtual ~SpawnerCommunicator(); | 64 ~SpawnerCommunicator() override; |
65 | 65 |
66 // 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. |
67 // If successfully started, returns true, setting |*port| to the port | 67 // If successfully started, returns true, setting |*port| to the port |
68 // 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 |
69 // test server. | 69 // test server. |
70 bool StartServer(const std::string& arguments, | 70 bool StartServer(const std::string& arguments, |
71 uint16* port) WARN_UNUSED_RESULT; | 71 uint16* port) WARN_UNUSED_RESULT; |
72 | 72 |
73 bool StopServer() WARN_UNUSED_RESULT; | 73 bool StopServer() WARN_UNUSED_RESULT; |
74 | 74 |
(...skipping 18 matching lines...) Expand all Loading... |
93 int* result_code, | 93 int* result_code, |
94 std::string* data_received); | 94 std::string* data_received); |
95 | 95 |
96 // Performs the command sending on the IO thread. Called on the IO thread. | 96 // Performs the command sending on the IO thread. Called on the IO thread. |
97 void SendCommandAndWaitForResultOnIOThread(const std::string& command, | 97 void SendCommandAndWaitForResultOnIOThread(const std::string& command, |
98 const std::string& post_data, | 98 const std::string& post_data, |
99 int* result_code, | 99 int* result_code, |
100 std::string* data_received); | 100 std::string* data_received); |
101 | 101 |
102 // URLRequest::Delegate methods. Called on the IO thread. | 102 // URLRequest::Delegate methods. Called on the IO thread. |
103 virtual void OnResponseStarted(URLRequest* request) override; | 103 void OnResponseStarted(URLRequest* request) override; |
104 virtual void OnReadCompleted(URLRequest* request, int num_bytes) override; | 104 void OnReadCompleted(URLRequest* request, int num_bytes) override; |
105 | 105 |
106 // Reads Result from the response. Called on the IO thread. | 106 // Reads Result from the response. Called on the IO thread. |
107 void ReadResult(URLRequest* request); | 107 void ReadResult(URLRequest* request); |
108 | 108 |
109 // Called on the IO thread upon completion of the spawner command. | 109 // Called on the IO thread upon completion of the spawner command. |
110 void OnSpawnerCommandCompleted(URLRequest* request); | 110 void OnSpawnerCommandCompleted(URLRequest* request); |
111 | 111 |
112 // Callback on the IO thread for time-out task of request with id |id|. | 112 // Callback on the IO thread for time-out task of request with id |id|. |
113 void OnTimeout(int id); | 113 void OnTimeout(int id); |
114 | 114 |
(...skipping 27 matching lines...) Expand all Loading... |
142 // 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 |
143 // outstanding tasks when |this| is deleted. | 143 // outstanding tasks when |this| is deleted. |
144 base::WeakPtrFactory<SpawnerCommunicator> weak_factory_; | 144 base::WeakPtrFactory<SpawnerCommunicator> weak_factory_; |
145 | 145 |
146 DISALLOW_COPY_AND_ASSIGN(SpawnerCommunicator); | 146 DISALLOW_COPY_AND_ASSIGN(SpawnerCommunicator); |
147 }; | 147 }; |
148 | 148 |
149 } // namespace net | 149 } // namespace net |
150 | 150 |
151 #endif // NET_TEST_SPAWNED_TEST_SERVER_SPAWNER_COMMUNICATOR_H_ | 151 #endif // NET_TEST_SPAWNED_TEST_SERVER_SPAWNER_COMMUNICATOR_H_ |
OLD | NEW |