| 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 #include "net/url_request/url_request_test_job.h" | 5 #include "net/url_request/url_request_test_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 NetworkDelegate* network_delegate, | 82 NetworkDelegate* network_delegate, |
| 83 const std::string& scheme) { | 83 const std::string& scheme) { |
| 84 return new URLRequestTestJob(request, network_delegate); | 84 return new URLRequestTestJob(request, network_delegate); |
| 85 } | 85 } |
| 86 | 86 |
| 87 URLRequestTestJob::URLRequestTestJob(URLRequest* request, | 87 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 88 NetworkDelegate* network_delegate) | 88 NetworkDelegate* network_delegate) |
| 89 : URLRequestJob(request, network_delegate), | 89 : URLRequestJob(request, network_delegate), |
| 90 auto_advance_(false), | 90 auto_advance_(false), |
| 91 stage_(WAITING), | 91 stage_(WAITING), |
| 92 // Let |request| set |priority_| itself. |
| 93 priority_(IDLE), |
| 92 offset_(0), | 94 offset_(0), |
| 93 async_buf_(NULL), | 95 async_buf_(NULL), |
| 94 async_buf_size_(0), | 96 async_buf_size_(0), |
| 95 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 97 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 96 } | 98 } |
| 97 | 99 |
| 98 URLRequestTestJob::URLRequestTestJob(URLRequest* request, | 100 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 99 NetworkDelegate* network_delegate, | 101 NetworkDelegate* network_delegate, |
| 100 bool auto_advance) | 102 bool auto_advance) |
| 101 : URLRequestJob(request, network_delegate), | 103 : URLRequestJob(request, network_delegate), |
| 102 auto_advance_(auto_advance), | 104 auto_advance_(auto_advance), |
| 103 stage_(WAITING), | 105 stage_(WAITING), |
| 106 priority_(IDLE), |
| 104 offset_(0), | 107 offset_(0), |
| 105 async_buf_(NULL), | 108 async_buf_(NULL), |
| 106 async_buf_size_(0), | 109 async_buf_size_(0), |
| 107 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 110 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 108 } | 111 } |
| 109 | 112 |
| 110 URLRequestTestJob::URLRequestTestJob(URLRequest* request, | 113 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 111 NetworkDelegate* network_delegate, | 114 NetworkDelegate* network_delegate, |
| 112 const std::string& response_headers, | 115 const std::string& response_headers, |
| 113 const std::string& response_data, | 116 const std::string& response_data, |
| 114 bool auto_advance) | 117 bool auto_advance) |
| 115 : URLRequestJob(request, network_delegate), | 118 : URLRequestJob(request, network_delegate), |
| 116 auto_advance_(auto_advance), | 119 auto_advance_(auto_advance), |
| 117 stage_(WAITING), | 120 stage_(WAITING), |
| 121 priority_(IDLE), |
| 118 response_headers_(new HttpResponseHeaders(response_headers)), | 122 response_headers_(new HttpResponseHeaders(response_headers)), |
| 119 response_data_(response_data), | 123 response_data_(response_data), |
| 120 offset_(0), | 124 offset_(0), |
| 121 async_buf_(NULL), | 125 async_buf_(NULL), |
| 122 async_buf_size_(0), | 126 async_buf_size_(0), |
| 123 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 127 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 124 } | 128 } |
| 125 | 129 |
| 126 URLRequestTestJob::~URLRequestTestJob() { | 130 URLRequestTestJob::~URLRequestTestJob() { |
| 127 g_pending_jobs.Get().erase( | 131 g_pending_jobs.Get().erase( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 223 |
| 220 std::string value; | 224 std::string value; |
| 221 if (!response_headers_->IsRedirect(&value)) | 225 if (!response_headers_->IsRedirect(&value)) |
| 222 return false; | 226 return false; |
| 223 | 227 |
| 224 *location = request_->url().Resolve(value); | 228 *location = request_->url().Resolve(value); |
| 225 *http_status_code = response_headers_->response_code(); | 229 *http_status_code = response_headers_->response_code(); |
| 226 return true; | 230 return true; |
| 227 } | 231 } |
| 228 | 232 |
| 233 void URLRequestTestJob::SetPriority(RequestPriority priority) { |
| 234 priority_ = priority; |
| 235 } |
| 229 | 236 |
| 230 void URLRequestTestJob::Kill() { | 237 void URLRequestTestJob::Kill() { |
| 231 stage_ = DONE; | 238 stage_ = DONE; |
| 232 URLRequestJob::Kill(); | 239 URLRequestJob::Kill(); |
| 233 weak_factory_.InvalidateWeakPtrs(); | 240 weak_factory_.InvalidateWeakPtrs(); |
| 234 g_pending_jobs.Get().erase( | 241 g_pending_jobs.Get().erase( |
| 235 std::remove( | 242 std::remove( |
| 236 g_pending_jobs.Get().begin(), g_pending_jobs.Get().end(), this), | 243 g_pending_jobs.Get().begin(), g_pending_jobs.Get().end(), this), |
| 237 g_pending_jobs.Get().end()); | 244 g_pending_jobs.Get().end()); |
| 238 } | 245 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 301 |
| 295 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); | 302 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); |
| 296 g_pending_jobs.Get().pop_front(); | 303 g_pending_jobs.Get().pop_front(); |
| 297 | 304 |
| 298 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q | 305 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q |
| 299 next_job->ProcessNextOperation(); | 306 next_job->ProcessNextOperation(); |
| 300 return true; | 307 return true; |
| 301 } | 308 } |
| 302 | 309 |
| 303 } // namespace net | 310 } // namespace net |
| OLD | NEW |