| 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 priority_(DEFAULT_PRIORITY), |
| 92 offset_(0), | 93 offset_(0), |
| 93 async_buf_(NULL), | 94 async_buf_(NULL), |
| 94 async_buf_size_(0), | 95 async_buf_size_(0), |
| 95 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 96 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 96 } | 97 } |
| 97 | 98 |
| 98 URLRequestTestJob::URLRequestTestJob(URLRequest* request, | 99 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 99 NetworkDelegate* network_delegate, | 100 NetworkDelegate* network_delegate, |
| 100 bool auto_advance) | 101 bool auto_advance) |
| 101 : URLRequestJob(request, network_delegate), | 102 : URLRequestJob(request, network_delegate), |
| 102 auto_advance_(auto_advance), | 103 auto_advance_(auto_advance), |
| 103 stage_(WAITING), | 104 stage_(WAITING), |
| 105 priority_(DEFAULT_PRIORITY), |
| 104 offset_(0), | 106 offset_(0), |
| 105 async_buf_(NULL), | 107 async_buf_(NULL), |
| 106 async_buf_size_(0), | 108 async_buf_size_(0), |
| 107 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 109 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 108 } | 110 } |
| 109 | 111 |
| 110 URLRequestTestJob::URLRequestTestJob(URLRequest* request, | 112 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 111 NetworkDelegate* network_delegate, | 113 NetworkDelegate* network_delegate, |
| 112 const std::string& response_headers, | 114 const std::string& response_headers, |
| 113 const std::string& response_data, | 115 const std::string& response_data, |
| 114 bool auto_advance) | 116 bool auto_advance) |
| 115 : URLRequestJob(request, network_delegate), | 117 : URLRequestJob(request, network_delegate), |
| 116 auto_advance_(auto_advance), | 118 auto_advance_(auto_advance), |
| 117 stage_(WAITING), | 119 stage_(WAITING), |
| 120 priority_(DEFAULT_PRIORITY), |
| 118 response_headers_(new HttpResponseHeaders(response_headers)), | 121 response_headers_(new HttpResponseHeaders(response_headers)), |
| 119 response_data_(response_data), | 122 response_data_(response_data), |
| 120 offset_(0), | 123 offset_(0), |
| 121 async_buf_(NULL), | 124 async_buf_(NULL), |
| 122 async_buf_size_(0), | 125 async_buf_size_(0), |
| 123 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 126 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 124 } | 127 } |
| 125 | 128 |
| 126 URLRequestTestJob::~URLRequestTestJob() { | 129 URLRequestTestJob::~URLRequestTestJob() { |
| 127 g_pending_jobs.Get().erase( | 130 g_pending_jobs.Get().erase( |
| 128 std::remove( | 131 std::remove( |
| 129 g_pending_jobs.Get().begin(), g_pending_jobs.Get().end(), this), | 132 g_pending_jobs.Get().begin(), g_pending_jobs.Get().end(), this), |
| 130 g_pending_jobs.Get().end()); | 133 g_pending_jobs.Get().end()); |
| 131 } | 134 } |
| 132 | 135 |
| 133 bool URLRequestTestJob::GetMimeType(std::string* mime_type) const { | 136 bool URLRequestTestJob::GetMimeType(std::string* mime_type) const { |
| 134 DCHECK(mime_type); | 137 DCHECK(mime_type); |
| 135 if (!response_headers_) | 138 if (!response_headers_) |
| 136 return false; | 139 return false; |
| 137 return response_headers_->GetMimeType(mime_type); | 140 return response_headers_->GetMimeType(mime_type); |
| 138 } | 141 } |
| 139 | 142 |
| 143 void URLRequestTestJob::SetPriority(RequestPriority priority) { |
| 144 priority_ = priority; |
| 145 } |
| 146 |
| 140 void URLRequestTestJob::Start() { | 147 void URLRequestTestJob::Start() { |
| 141 // Start reading asynchronously so that all error reporting and data | 148 // Start reading asynchronously so that all error reporting and data |
| 142 // callbacks happen as they would for network requests. | 149 // callbacks happen as they would for network requests. |
| 143 MessageLoop::current()->PostTask( | 150 MessageLoop::current()->PostTask( |
| 144 FROM_HERE, base::Bind(&URLRequestTestJob::StartAsync, | 151 FROM_HERE, base::Bind(&URLRequestTestJob::StartAsync, |
| 145 weak_factory_.GetWeakPtr())); | 152 weak_factory_.GetWeakPtr())); |
| 146 } | 153 } |
| 147 | 154 |
| 148 void URLRequestTestJob::StartAsync() { | 155 void URLRequestTestJob::StartAsync() { |
| 149 if (!response_headers_) { | 156 if (!response_headers_) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 226 |
| 220 std::string value; | 227 std::string value; |
| 221 if (!response_headers_->IsRedirect(&value)) | 228 if (!response_headers_->IsRedirect(&value)) |
| 222 return false; | 229 return false; |
| 223 | 230 |
| 224 *location = request_->url().Resolve(value); | 231 *location = request_->url().Resolve(value); |
| 225 *http_status_code = response_headers_->response_code(); | 232 *http_status_code = response_headers_->response_code(); |
| 226 return true; | 233 return true; |
| 227 } | 234 } |
| 228 | 235 |
| 229 | |
| 230 void URLRequestTestJob::Kill() { | 236 void URLRequestTestJob::Kill() { |
| 231 stage_ = DONE; | 237 stage_ = DONE; |
| 232 URLRequestJob::Kill(); | 238 URLRequestJob::Kill(); |
| 233 weak_factory_.InvalidateWeakPtrs(); | 239 weak_factory_.InvalidateWeakPtrs(); |
| 234 g_pending_jobs.Get().erase( | 240 g_pending_jobs.Get().erase( |
| 235 std::remove( | 241 std::remove( |
| 236 g_pending_jobs.Get().begin(), g_pending_jobs.Get().end(), this), | 242 g_pending_jobs.Get().begin(), g_pending_jobs.Get().end(), this), |
| 237 g_pending_jobs.Get().end()); | 243 g_pending_jobs.Get().end()); |
| 238 } | 244 } |
| 239 | 245 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 300 |
| 295 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); | 301 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); |
| 296 g_pending_jobs.Get().pop_front(); | 302 g_pending_jobs.Get().pop_front(); |
| 297 | 303 |
| 298 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q | 304 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q |
| 299 next_job->ProcessNextOperation(); | 305 next_job->ProcessNextOperation(); |
| 300 return true; | 306 return true; |
| 301 } | 307 } |
| 302 | 308 |
| 303 } // namespace net | 309 } // namespace net |
| OLD | NEW |