Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "chrome/browser/policy/cloud/test_request_interceptor.h" | 5 #include "chrome/browser/policy/cloud/test_request_interceptor.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "base/sequenced_task_runner.h" | 16 #include "base/sequenced_task_runner.h" |
| 17 #include "components/policy/core/common/remote_commands/testing_remote_commands_ server.h" | |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "net/base/upload_bytes_element_reader.h" | 20 #include "net/base/upload_bytes_element_reader.h" |
| 20 #include "net/base/upload_data_stream.h" | 21 #include "net/base/upload_data_stream.h" |
| 21 #include "net/base/upload_element_reader.h" | 22 #include "net/base/upload_element_reader.h" |
| 22 #include "net/test/url_request/url_request_mock_http_job.h" | 23 #include "net/test/url_request/url_request_mock_http_job.h" |
| 23 #include "net/url_request/url_request_error_job.h" | 24 #include "net/url_request/url_request_error_job.h" |
| 24 #include "net/url_request/url_request_filter.h" | 25 #include "net/url_request/url_request_filter.h" |
| 25 #include "net/url_request/url_request_interceptor.h" | 26 #include "net/url_request/url_request_interceptor.h" |
| 26 #include "net/url_request/url_request_test_job.h" | 27 #include "net/url_request/url_request_test_job.h" |
| 27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 28 | 29 |
| 29 namespace em = enterprise_management; | 30 namespace em = enterprise_management; |
| 30 | 31 |
| 31 namespace policy { | 32 namespace policy { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 36 static const char kGoodHeaders[] = | |
| 37 "HTTP/1.1 200 OK\0" | |
| 38 "Content-type: application/protobuf\0" | |
| 39 "\0"; | |
| 40 static const char kBadHeaders[] = | |
| 41 "HTTP/1.1 400 Bad request\0" | |
| 42 "Content-type: application/protobuf\0" | |
| 43 "\0"; | |
| 44 | |
| 35 // Helper callback for jobs that should fail with a network |error|. | 45 // Helper callback for jobs that should fail with a network |error|. |
| 36 net::URLRequestJob* ErrorJobCallback(int error, | 46 net::URLRequestJob* ErrorJobCallback(int error, |
| 37 net::URLRequest* request, | 47 net::URLRequest* request, |
| 38 net::NetworkDelegate* network_delegate) { | 48 net::NetworkDelegate* network_delegate) { |
| 39 return new net::URLRequestErrorJob(request, network_delegate, error); | 49 return new net::URLRequestErrorJob(request, network_delegate, error); |
| 40 } | 50 } |
| 41 | 51 |
| 42 // Helper callback for jobs that should fail with a 400 HTTP error. | 52 // Helper callback for jobs that should fail with a 400 HTTP error. |
| 43 net::URLRequestJob* BadRequestJobCallback( | 53 net::URLRequestJob* BadRequestJobCallback( |
| 44 net::URLRequest* request, | 54 net::URLRequest* request, |
| 45 net::NetworkDelegate* network_delegate) { | 55 net::NetworkDelegate* network_delegate) { |
| 46 static const char kBadHeaders[] = | 56 const std::string headers(kBadHeaders, arraysize(kBadHeaders)); |
| 47 "HTTP/1.1 400 Bad request\0" | |
| 48 "Content-type: application/protobuf\0" | |
| 49 "\0"; | |
| 50 std::string headers(kBadHeaders, arraysize(kBadHeaders)); | |
| 51 return new net::URLRequestTestJob( | 57 return new net::URLRequestTestJob( |
| 52 request, network_delegate, headers, std::string(), true); | 58 request, network_delegate, headers, std::string(), true); |
| 53 } | 59 } |
| 54 | 60 |
| 55 net::URLRequestJob* FileJobCallback(const base::FilePath& file_path, | 61 net::URLRequestJob* FileJobCallback(const base::FilePath& file_path, |
| 56 net::URLRequest* request, | 62 net::URLRequest* request, |
| 57 net::NetworkDelegate* network_delegate) { | 63 net::NetworkDelegate* network_delegate) { |
| 58 return new net::URLRequestMockHTTPJob( | 64 return new net::URLRequestMockHTTPJob( |
| 59 request, | 65 request, |
| 60 network_delegate, | 66 network_delegate, |
| 61 file_path, | 67 file_path, |
| 62 content::BrowserThread::GetBlockingPool() | 68 content::BrowserThread::GetBlockingPool() |
| 63 ->GetTaskRunnerWithShutdownBehavior( | 69 ->GetTaskRunnerWithShutdownBehavior( |
| 64 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 70 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 65 } | 71 } |
| 66 | 72 |
| 67 // Parses the upload data in |request| into |request_msg|, and validates the | 73 // Parses the upload data in |request| into |request_msg|, and validates the |
| 68 // request. The query string in the URL must contain the |expected_type| for | 74 // request. The query string in the URL must contain the |expected_type| for |
| 69 // the "request" parameter. Returns true if all checks succeeded, and the | 75 // the "request" parameter. Returns true if all checks succeeded, and the |
| 70 // request data has been parsed into |request_msg|. | 76 // request data has been parsed into |request_msg| if it's not null. |
| 71 bool ValidRequest(net::URLRequest* request, | 77 bool ValidRequest(net::URLRequest* request, |
| 72 const std::string& expected_type, | 78 const std::string& expected_type, |
| 73 em::DeviceManagementRequest* request_msg) { | 79 em::DeviceManagementRequest* request_msg) { |
| 74 if (request->method() != "POST") | 80 if (request->method() != "POST") |
| 75 return false; | 81 return false; |
| 76 std::string spec = request->url().spec(); | 82 std::string spec = request->url().spec(); |
| 77 if (spec.find("request=" + expected_type) == std::string::npos) | 83 if (spec.find("request=" + expected_type) == std::string::npos) |
| 78 return false; | 84 return false; |
| 79 | 85 |
| 80 // This assumes that the payload data was set from a single string. In that | 86 // This assumes that the payload data was set from a single string. In that |
| 81 // case the UploadDataStream has a single UploadBytesElementReader with the | 87 // case the UploadDataStream has a single UploadBytesElementReader with the |
| 82 // data in memory. | 88 // data in memory. |
| 83 const net::UploadDataStream* stream = request->get_upload(); | 89 const net::UploadDataStream* stream = request->get_upload(); |
| 84 if (!stream) | 90 if (!stream) |
| 85 return false; | 91 return false; |
| 86 const ScopedVector<net::UploadElementReader>* readers = | 92 const ScopedVector<net::UploadElementReader>* readers = |
| 87 stream->GetElementReaders(); | 93 stream->GetElementReaders(); |
| 88 if (!readers || readers->size() != 1u) | 94 if (!readers || readers->size() != 1u) |
| 89 return false; | 95 return false; |
| 90 const net::UploadBytesElementReader* reader = (*readers)[0]->AsBytesReader(); | 96 const net::UploadBytesElementReader* reader = (*readers)[0]->AsBytesReader(); |
| 91 if (!reader) | 97 if (!reader) |
| 92 return false; | 98 return false; |
| 93 std::string data(reader->bytes(), reader->length()); | 99 std::string data(reader->bytes(), reader->length()); |
| 94 if (!request_msg->ParseFromString(data)) | 100 if (request_msg && !request_msg->ParseFromString(data)) |
| 95 return false; | 101 return false; |
| 96 | 102 |
| 97 return true; | 103 return true; |
| 98 } | 104 } |
| 99 | 105 |
| 100 // Helper callback for register jobs that should suceed. Validates the request | 106 // Helper callback for register jobs that should suceed. Validates the request |
| 101 // parameters and returns an appropriate response job. If |expect_reregister| | 107 // parameters and returns an appropriate response job. If |expect_reregister| |
| 102 // is true then the reregister flag must be set in the DeviceRegisterRequest | 108 // is true then the reregister flag must be set in the DeviceRegisterRequest |
| 103 // protobuf. | 109 // protobuf. |
| 104 net::URLRequestJob* RegisterJobCallback( | 110 net::URLRequestJob* RegisterJobCallback( |
| 105 em::DeviceRegisterRequest::Type expected_type, | 111 em::DeviceRegisterRequest::Type expected_type, |
| 106 bool expect_reregister, | 112 bool expect_reregister, |
| 107 net::URLRequest* request, | 113 net::URLRequest* request, |
| 108 net::NetworkDelegate* network_delegate) { | 114 net::NetworkDelegate* network_delegate) { |
| 109 em::DeviceManagementRequest request_msg; | 115 em::DeviceManagementRequest request_msg; |
| 110 if (!ValidRequest(request, "register", &request_msg)) | 116 if (!ValidRequest(request, "register", &request_msg)) |
| 111 return BadRequestJobCallback(request, network_delegate); | 117 return BadRequestJobCallback(request, network_delegate); |
| 112 | 118 |
| 113 if (!request_msg.has_register_request() || | 119 if (!request_msg.has_register_request() || |
| 114 request_msg.has_unregister_request() || | 120 request_msg.has_unregister_request() || |
| 115 request_msg.has_policy_request() || | 121 request_msg.has_policy_request() || |
| 116 request_msg.has_device_status_report_request() || | 122 request_msg.has_device_status_report_request() || |
| 117 request_msg.has_session_status_report_request() || | 123 request_msg.has_session_status_report_request() || |
| 118 request_msg.has_auto_enrollment_request()) { | 124 request_msg.has_auto_enrollment_request() || |
| 125 request_msg.has_remote_command_request()) { | |
| 119 return BadRequestJobCallback(request, network_delegate); | 126 return BadRequestJobCallback(request, network_delegate); |
| 120 } | 127 } |
| 121 | 128 |
| 122 const em::DeviceRegisterRequest& register_request = | 129 const em::DeviceRegisterRequest& register_request = |
| 123 request_msg.register_request(); | 130 request_msg.register_request(); |
| 124 if (expect_reregister && | 131 if (expect_reregister && |
| 125 (!register_request.has_reregister() || !register_request.reregister())) { | 132 (!register_request.has_reregister() || !register_request.reregister())) { |
| 126 return BadRequestJobCallback(request, network_delegate); | 133 return BadRequestJobCallback(request, network_delegate); |
| 127 } else if (!expect_reregister && | 134 } else if (!expect_reregister && |
| 128 register_request.has_reregister() && | 135 register_request.has_reregister() && |
| 129 register_request.reregister()) { | 136 register_request.reregister()) { |
| 130 return BadRequestJobCallback(request, network_delegate); | 137 return BadRequestJobCallback(request, network_delegate); |
| 131 } | 138 } |
| 132 | 139 |
| 133 if (!register_request.has_type() || register_request.type() != expected_type) | 140 if (!register_request.has_type() || register_request.type() != expected_type) |
| 134 return BadRequestJobCallback(request, network_delegate); | 141 return BadRequestJobCallback(request, network_delegate); |
| 135 | 142 |
| 136 em::DeviceManagementResponse response; | 143 em::DeviceManagementResponse response; |
| 137 em::DeviceRegisterResponse* register_response = | 144 em::DeviceRegisterResponse* register_response = |
| 138 response.mutable_register_response(); | 145 response.mutable_register_response(); |
| 139 register_response->set_device_management_token("s3cr3t70k3n"); | 146 register_response->set_device_management_token("s3cr3t70k3n"); |
| 140 std::string data; | 147 std::string data; |
| 141 response.SerializeToString(&data); | 148 response.SerializeToString(&data); |
| 142 | 149 |
| 143 static const char kGoodHeaders[] = | 150 const std::string headers(kGoodHeaders, arraysize(kGoodHeaders)); |
| 144 "HTTP/1.1 200 OK\0" | 151 return new net::URLRequestTestJob(request, network_delegate, headers, data, |
| 145 "Content-type: application/protobuf\0" | 152 true); |
| 146 "\0"; | 153 } |
| 147 std::string headers(kGoodHeaders, arraysize(kGoodHeaders)); | 154 |
| 155 net::URLRequestJob* FetchRemoteCommandsJobCallback( | |
| 156 TestingRemoteCommandsServer* server, | |
| 157 size_t expected_command_results, | |
| 158 size_t expected_fetched_commands, | |
| 159 net::URLRequest* request, | |
| 160 net::NetworkDelegate* network_delegate) { | |
| 161 em::DeviceManagementRequest request_msg; | |
| 162 if (!ValidRequest(request, "remote_commands", &request_msg)) { | |
|
bartfab (slow)
2015/02/17 18:13:52
Nit: No need for {}.
binjin
2015/02/18 15:37:48
Done.
| |
| 163 return BadRequestJobCallback(request, network_delegate); | |
| 164 } | |
| 165 | |
| 166 if (!request_msg.has_remote_command_request()) | |
| 167 return BadRequestJobCallback(request, network_delegate); | |
| 168 | |
| 169 const em::DeviceRemoteCommandRequest& remote_command_request = | |
| 170 request_msg.remote_command_request(); | |
| 171 if (!remote_command_request.has_last_command_unique_id()) | |
| 172 return BadRequestJobCallback(request, network_delegate); | |
| 173 | |
| 174 std::vector<em::RemoteCommandResult> previous_results( | |
| 175 remote_command_request.command_results().begin(), | |
| 176 remote_command_request.command_results().end()); | |
| 177 | |
| 178 // Verify the number of results for previous commands. | |
| 179 DCHECK_EQ(expected_command_results, previous_results.size()); | |
| 180 | |
| 181 // Interact with TestingRemoteCommandsServer to actually fetch commands, | |
| 182 // and verify the number of fetched commands. | |
| 183 std::vector<em::RemoteCommand> fetched_commands = server->FetchCommandsFromIO( | |
|
bartfab (slow)
2015/02/17 18:13:52
Nit: const.
binjin
2015/02/18 15:37:48
Done.
| |
| 184 remote_command_request.last_command_unique_id(), previous_results); | |
| 185 DCHECK_EQ(expected_fetched_commands, fetched_commands.size()); | |
| 186 | |
| 187 // Generating response. | |
| 188 em::DeviceManagementResponse response; | |
| 189 em::DeviceRemoteCommandResponse* remote_command_response = | |
| 190 response.mutable_remote_command_response(); | |
| 191 | |
| 192 for (const auto& fetched_command : fetched_commands) | |
| 193 *remote_command_response->add_commands() = fetched_command; | |
| 194 std::string data; | |
| 195 response.SerializeToString(&data); | |
| 196 | |
| 197 const std::string headers(kGoodHeaders, arraysize(kGoodHeaders)); | |
| 148 return new net::URLRequestTestJob( | 198 return new net::URLRequestTestJob( |
| 149 request, network_delegate, headers, data, true); | 199 request, network_delegate, headers, data, true); |
| 150 } | 200 } |
| 151 | 201 |
| 152 void RegisterHttpInterceptor( | 202 void RegisterHttpInterceptor( |
| 153 const std::string& hostname, | 203 const std::string& hostname, |
| 154 scoped_ptr<net::URLRequestInterceptor> interceptor) { | 204 scoped_ptr<net::URLRequestInterceptor> interceptor) { |
| 155 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 205 net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( |
| 156 "http", hostname, interceptor.Pass()); | 206 "http", hostname, interceptor.Pass()); |
| 157 } | 207 } |
| 158 | 208 |
| 159 } // namespace | 209 } // namespace |
| 160 | 210 |
| 161 class TestRequestInterceptor::Delegate : public net::URLRequestInterceptor { | 211 class TestRequestInterceptor::Delegate : public net::URLRequestInterceptor { |
| 162 public: | 212 public: |
| 163 Delegate(const std::string& hostname, | 213 Delegate(const std::string& hostname, |
| 164 scoped_refptr<base::SequencedTaskRunner> io_task_runner); | 214 scoped_refptr<base::SequencedTaskRunner> io_task_runner); |
| 165 ~Delegate() override; | 215 ~Delegate() override; |
| 166 | 216 |
| 167 // net::URLRequestInterceptor implementation: | 217 // net::URLRequestInterceptor implementation: |
| 168 net::URLRequestJob* MaybeInterceptRequest( | 218 net::URLRequestJob* MaybeInterceptRequest( |
| 169 net::URLRequest* request, | 219 net::URLRequest* request, |
| 170 net::NetworkDelegate* network_delegate) const override; | 220 net::NetworkDelegate* network_delegate) const override; |
| 171 | 221 |
| 172 void GetPendingSize(size_t* pending_size) const; | 222 void GetPendingSize(size_t* pending_size) const; |
| 173 void AddRequestServicedCallback(const base::Closure& callback); | 223 void AddRequestServicedCallback(const base::Closure& callback); |
| 174 void PushJobCallback(const JobCallback& callback); | 224 void PushJobCallback(const JobCallback& callback); |
| 225 void AddIgnoredRequestType(const std::string& ignored_type); | |
| 175 | 226 |
| 176 private: | 227 private: |
| 177 static void InvokeRequestServicedCallbacks( | 228 static void InvokeRequestServicedCallbacks( |
| 178 scoped_ptr<std::vector<base::Closure>> callbacks); | 229 scoped_ptr<std::vector<base::Closure>> callbacks); |
| 179 | 230 |
| 231 std::vector<std::string> ignored_types; | |
|
bartfab (slow)
2015/02/17 18:13:52
Nit: Add trailing underscore.
binjin
2015/02/18 15:37:48
Done.
| |
| 232 | |
| 180 const std::string hostname_; | 233 const std::string hostname_; |
| 181 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 234 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
| 182 | 235 |
| 183 // The queue of pending callbacks. 'mutable' because MaybeCreateJob() is a | 236 // The queue of pending callbacks. 'mutable' because MaybeCreateJob() is a |
| 184 // const method; it can't reenter though, because it runs exclusively on | 237 // const method; it can't reenter though, because it runs exclusively on |
| 185 // the IO thread. | 238 // the IO thread. |
| 186 mutable std::queue<JobCallback> pending_job_callbacks_; | 239 mutable std::queue<JobCallback> pending_job_callbacks_; |
| 187 | 240 |
| 188 // Queue of pending request serviced callbacks. Mutable for the same reason | 241 // Queue of pending request serviced callbacks. Mutable for the same reason |
| 189 // as |pending_job_callbacks_|. | 242 // as |pending_job_callbacks_|. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 206 // Reject requests to other servers. | 259 // Reject requests to other servers. |
| 207 return ErrorJobCallback( | 260 return ErrorJobCallback( |
| 208 net::ERR_CONNECTION_REFUSED, request, network_delegate); | 261 net::ERR_CONNECTION_REFUSED, request, network_delegate); |
| 209 } | 262 } |
| 210 | 263 |
| 211 if (pending_job_callbacks_.empty()) { | 264 if (pending_job_callbacks_.empty()) { |
| 212 // Reject dmserver requests by default. | 265 // Reject dmserver requests by default. |
| 213 return BadRequestJobCallback(request, network_delegate); | 266 return BadRequestJobCallback(request, network_delegate); |
| 214 } | 267 } |
| 215 | 268 |
| 269 // If the request is explicitly ignored, don't handle this request by | |
| 270 // sending back an bad request response. | |
| 271 for (const std::string& ignored_type : ignored_types) | |
|
bartfab (slow)
2015/02/17 18:13:52
Nit: Add curly braces.
binjin
2015/02/18 15:37:48
Done.
| |
| 272 if (ValidRequest(request, ignored_type, nullptr)) | |
| 273 return BadRequestJobCallback(request, network_delegate); | |
| 274 | |
| 216 // Invoke any callbacks that are waiting for the next request to be serviced | 275 // Invoke any callbacks that are waiting for the next request to be serviced |
| 217 // after this job is serviced. | 276 // after this job is serviced. |
| 218 if (!request_serviced_callbacks_.empty()) { | 277 if (!request_serviced_callbacks_.empty()) { |
| 219 scoped_ptr<std::vector<base::Closure>> callbacks( | 278 scoped_ptr<std::vector<base::Closure>> callbacks( |
| 220 new std::vector<base::Closure>); | 279 new std::vector<base::Closure>); |
| 221 callbacks->swap(request_serviced_callbacks_); | 280 callbacks->swap(request_serviced_callbacks_); |
| 222 io_task_runner_->PostTask( | 281 io_task_runner_->PostTask( |
| 223 FROM_HERE, base::Bind(&Delegate::InvokeRequestServicedCallbacks, | 282 FROM_HERE, base::Bind(&Delegate::InvokeRequestServicedCallbacks, |
| 224 base::Passed(&callbacks))); | 283 base::Passed(&callbacks))); |
| 225 } | 284 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 240 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 299 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 241 request_serviced_callbacks_.push_back(callback); | 300 request_serviced_callbacks_.push_back(callback); |
| 242 } | 301 } |
| 243 | 302 |
| 244 void TestRequestInterceptor::Delegate::PushJobCallback( | 303 void TestRequestInterceptor::Delegate::PushJobCallback( |
| 245 const JobCallback& callback) { | 304 const JobCallback& callback) { |
| 246 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 305 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 247 pending_job_callbacks_.push(callback); | 306 pending_job_callbacks_.push(callback); |
| 248 } | 307 } |
| 249 | 308 |
| 309 void TestRequestInterceptor::Delegate::AddIgnoredRequestType( | |
| 310 const std::string& ignored_type) { | |
| 311 CHECK(io_task_runner_->RunsTasksOnCurrentThread()); | |
| 312 | |
| 313 ignored_types.push_back(ignored_type); | |
| 314 } | |
| 315 | |
| 250 // static | 316 // static |
| 251 void TestRequestInterceptor::Delegate::InvokeRequestServicedCallbacks( | 317 void TestRequestInterceptor::Delegate::InvokeRequestServicedCallbacks( |
| 252 scoped_ptr<std::vector<base::Closure>> callbacks) { | 318 scoped_ptr<std::vector<base::Closure>> callbacks) { |
| 253 for (const auto& p : *callbacks) | 319 for (const auto& p : *callbacks) |
| 254 p.Run(); | 320 p.Run(); |
| 255 } | 321 } |
| 256 | 322 |
| 257 TestRequestInterceptor::TestRequestInterceptor(const std::string& hostname, | 323 TestRequestInterceptor::TestRequestInterceptor(const std::string& hostname, |
| 258 scoped_refptr<base::SequencedTaskRunner> io_task_runner) | 324 scoped_refptr<base::SequencedTaskRunner> io_task_runner) |
| 259 : hostname_(hostname), | 325 : hostname_(hostname), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 base::Unretained(delegate_), | 360 base::Unretained(delegate_), |
| 295 post_callback)); | 361 post_callback)); |
| 296 } | 362 } |
| 297 | 363 |
| 298 void TestRequestInterceptor::PushJobCallback(const JobCallback& callback) { | 364 void TestRequestInterceptor::PushJobCallback(const JobCallback& callback) { |
| 299 PostToIOAndWait(base::Bind(&Delegate::PushJobCallback, | 365 PostToIOAndWait(base::Bind(&Delegate::PushJobCallback, |
| 300 base::Unretained(delegate_), | 366 base::Unretained(delegate_), |
| 301 callback)); | 367 callback)); |
| 302 } | 368 } |
| 303 | 369 |
| 370 void TestRequestInterceptor::AddIgnoredRequestType( | |
| 371 const std::string& ignored_type) { | |
| 372 PostToIOAndWait(base::Bind(&Delegate::AddIgnoredRequestType, | |
| 373 base::Unretained(delegate_), ignored_type)); | |
| 374 } | |
| 375 | |
| 304 // static | 376 // static |
| 305 TestRequestInterceptor::JobCallback TestRequestInterceptor::ErrorJob( | 377 TestRequestInterceptor::JobCallback TestRequestInterceptor::ErrorJob( |
| 306 int error) { | 378 int error) { |
| 307 return base::Bind(&ErrorJobCallback, error); | 379 return base::Bind(&ErrorJobCallback, error); |
| 308 } | 380 } |
| 309 | 381 |
| 310 // static | 382 // static |
| 311 TestRequestInterceptor::JobCallback TestRequestInterceptor::BadRequestJob() { | 383 TestRequestInterceptor::JobCallback TestRequestInterceptor::BadRequestJob() { |
| 312 return base::Bind(&BadRequestJobCallback); | 384 return base::Bind(&BadRequestJobCallback); |
| 313 } | 385 } |
| 314 | 386 |
| 315 // static | 387 // static |
| 316 TestRequestInterceptor::JobCallback TestRequestInterceptor::RegisterJob( | 388 TestRequestInterceptor::JobCallback TestRequestInterceptor::RegisterJob( |
| 317 em::DeviceRegisterRequest::Type expected_type, | 389 em::DeviceRegisterRequest::Type expected_type, |
| 318 bool expect_reregister) { | 390 bool expect_reregister) { |
| 319 return base::Bind(&RegisterJobCallback, expected_type, expect_reregister); | 391 return base::Bind(&RegisterJobCallback, expected_type, expect_reregister); |
| 320 } | 392 } |
| 321 | 393 |
| 322 // static | 394 // static |
| 323 TestRequestInterceptor::JobCallback TestRequestInterceptor::FileJob( | 395 TestRequestInterceptor::JobCallback TestRequestInterceptor::FileJob( |
| 324 const base::FilePath& file_path) { | 396 const base::FilePath& file_path) { |
| 325 return base::Bind(&FileJobCallback, file_path); | 397 return base::Bind(&FileJobCallback, file_path); |
| 326 } | 398 } |
| 327 | 399 |
| 400 // static | |
| 401 TestRequestInterceptor::JobCallback | |
| 402 TestRequestInterceptor::FetchRemoteCommandsJob( | |
| 403 TestingRemoteCommandsServer* server, | |
| 404 size_t expected_command_results, | |
| 405 size_t expected_fetched_commands) { | |
| 406 return base::Bind(&FetchRemoteCommandsJobCallback, server, | |
| 407 expected_command_results, expected_fetched_commands); | |
| 408 } | |
| 409 | |
| 328 void TestRequestInterceptor::PostToIOAndWait(const base::Closure& task) { | 410 void TestRequestInterceptor::PostToIOAndWait(const base::Closure& task) { |
| 329 io_task_runner_->PostTask(FROM_HERE, task); | 411 io_task_runner_->PostTask(FROM_HERE, task); |
| 330 base::RunLoop run_loop; | 412 base::RunLoop run_loop; |
| 331 io_task_runner_->PostTask( | 413 io_task_runner_->PostTask( |
| 332 FROM_HERE, | 414 FROM_HERE, |
| 333 base::Bind( | 415 base::Bind( |
| 334 base::IgnoreResult(&base::MessageLoopProxy::PostTask), | 416 base::IgnoreResult(&base::MessageLoopProxy::PostTask), |
| 335 base::MessageLoopProxy::current(), | 417 base::MessageLoopProxy::current(), |
| 336 FROM_HERE, | 418 FROM_HERE, |
| 337 run_loop.QuitClosure())); | 419 run_loop.QuitClosure())); |
| 338 run_loop.Run(); | 420 run_loop.Run(); |
| 339 } | 421 } |
| 340 | 422 |
| 341 } // namespace policy | 423 } // namespace policy |
| OLD | NEW |