| 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)) | 
|  | 163     return BadRequestJobCallback(request, network_delegate); | 
|  | 164 | 
|  | 165   if (!request_msg.has_remote_command_request()) | 
|  | 166     return BadRequestJobCallback(request, network_delegate); | 
|  | 167 | 
|  | 168   const em::DeviceRemoteCommandRequest& remote_command_request = | 
|  | 169       request_msg.remote_command_request(); | 
|  | 170   if (!remote_command_request.has_last_command_unique_id()) | 
|  | 171     return BadRequestJobCallback(request, network_delegate); | 
|  | 172 | 
|  | 173   std::vector<em::RemoteCommandResult> previous_results( | 
|  | 174       remote_command_request.command_results().begin(), | 
|  | 175       remote_command_request.command_results().end()); | 
|  | 176 | 
|  | 177   // Verify the number of results for previous commands. | 
|  | 178   DCHECK_EQ(expected_command_results, previous_results.size()); | 
|  | 179 | 
|  | 180   // Interact with TestingRemoteCommandsServer to actually fetch commands, | 
|  | 181   // and verify the number of fetched commands. | 
|  | 182   const std::vector<em::RemoteCommand> fetched_commands = server->FetchCommands( | 
|  | 183       remote_command_request.last_command_unique_id(), previous_results); | 
|  | 184   DCHECK_EQ(expected_fetched_commands, fetched_commands.size()); | 
|  | 185 | 
|  | 186   // Generating response. | 
|  | 187   em::DeviceManagementResponse response; | 
|  | 188   em::DeviceRemoteCommandResponse* remote_command_response = | 
|  | 189       response.mutable_remote_command_response(); | 
|  | 190 | 
|  | 191   for (const auto& fetched_command : fetched_commands) | 
|  | 192     *remote_command_response->add_commands() = fetched_command; | 
|  | 193   std::string data; | 
|  | 194   response.SerializeToString(&data); | 
|  | 195 | 
|  | 196   const std::string headers(kGoodHeaders, arraysize(kGoodHeaders)); | 
| 148   return new net::URLRequestTestJob( | 197   return new net::URLRequestTestJob( | 
| 149       request, network_delegate, headers, data, true); | 198       request, network_delegate, headers, data, true); | 
| 150 } | 199 } | 
| 151 | 200 | 
| 152 void RegisterHttpInterceptor( | 201 void RegisterHttpInterceptor( | 
| 153     const std::string& hostname, | 202     const std::string& hostname, | 
| 154     scoped_ptr<net::URLRequestInterceptor> interceptor) { | 203     scoped_ptr<net::URLRequestInterceptor> interceptor) { | 
| 155   net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 204   net::URLRequestFilter::GetInstance()->AddHostnameInterceptor( | 
| 156       "http", hostname, interceptor.Pass()); | 205       "http", hostname, interceptor.Pass()); | 
| 157 } | 206 } | 
| 158 | 207 | 
| 159 }  // namespace | 208 }  // namespace | 
| 160 | 209 | 
| 161 class TestRequestInterceptor::Delegate : public net::URLRequestInterceptor { | 210 class TestRequestInterceptor::Delegate : public net::URLRequestInterceptor { | 
| 162  public: | 211  public: | 
| 163   Delegate(const std::string& hostname, | 212   Delegate(const std::string& hostname, | 
| 164            scoped_refptr<base::SequencedTaskRunner> io_task_runner); | 213            scoped_refptr<base::SequencedTaskRunner> io_task_runner); | 
| 165   ~Delegate() override; | 214   ~Delegate() override; | 
| 166 | 215 | 
| 167   // net::URLRequestInterceptor implementation: | 216   // net::URLRequestInterceptor implementation: | 
| 168   net::URLRequestJob* MaybeInterceptRequest( | 217   net::URLRequestJob* MaybeInterceptRequest( | 
| 169       net::URLRequest* request, | 218       net::URLRequest* request, | 
| 170       net::NetworkDelegate* network_delegate) const override; | 219       net::NetworkDelegate* network_delegate) const override; | 
| 171 | 220 | 
| 172   void GetPendingSize(size_t* pending_size) const; | 221   void GetPendingSize(size_t* pending_size) const; | 
| 173   void AddRequestServicedCallback(const base::Closure& callback); | 222   void AddRequestServicedCallback(const base::Closure& callback); | 
| 174   void PushJobCallback(const JobCallback& callback); | 223   void PushJobCallback(const JobCallback& callback); | 
|  | 224   void AddIgnoredRequestType(const std::string& ignored_type); | 
| 175 | 225 | 
| 176  private: | 226  private: | 
| 177   static void InvokeRequestServicedCallbacks( | 227   static void InvokeRequestServicedCallbacks( | 
| 178       scoped_ptr<std::vector<base::Closure>> callbacks); | 228       scoped_ptr<std::vector<base::Closure>> callbacks); | 
| 179 | 229 | 
|  | 230   std::vector<std::string> ignored_types_; | 
|  | 231 | 
| 180   const std::string hostname_; | 232   const std::string hostname_; | 
| 181   scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 233   scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 
| 182 | 234 | 
| 183   // The queue of pending callbacks. 'mutable' because MaybeCreateJob() is a | 235   // The queue of pending callbacks. 'mutable' because MaybeCreateJob() is a | 
| 184   // const method; it can't reenter though, because it runs exclusively on | 236   // const method; it can't reenter though, because it runs exclusively on | 
| 185   // the IO thread. | 237   // the IO thread. | 
| 186   mutable std::queue<JobCallback> pending_job_callbacks_; | 238   mutable std::queue<JobCallback> pending_job_callbacks_; | 
| 187 | 239 | 
| 188   // Queue of pending request serviced callbacks. Mutable for the same reason | 240   // Queue of pending request serviced callbacks. Mutable for the same reason | 
| 189   // as |pending_job_callbacks_|. | 241   // as |pending_job_callbacks_|. | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 206     // Reject requests to other servers. | 258     // Reject requests to other servers. | 
| 207     return ErrorJobCallback( | 259     return ErrorJobCallback( | 
| 208         net::ERR_CONNECTION_REFUSED, request, network_delegate); | 260         net::ERR_CONNECTION_REFUSED, request, network_delegate); | 
| 209   } | 261   } | 
| 210 | 262 | 
| 211   if (pending_job_callbacks_.empty()) { | 263   if (pending_job_callbacks_.empty()) { | 
| 212     // Reject dmserver requests by default. | 264     // Reject dmserver requests by default. | 
| 213     return BadRequestJobCallback(request, network_delegate); | 265     return BadRequestJobCallback(request, network_delegate); | 
| 214   } | 266   } | 
| 215 | 267 | 
|  | 268   // If the request is explicitly ignored, don't handle this request by | 
|  | 269   // sending back an bad request response. | 
|  | 270   for (const std::string& ignored_type : ignored_types_) { | 
|  | 271     if (ValidRequest(request, ignored_type, nullptr)) | 
|  | 272       return BadRequestJobCallback(request, network_delegate); | 
|  | 273   } | 
|  | 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 | 
|---|