| 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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 18 #include "net/url_request/url_request.h" | |
| 19 #include "net/url_request/url_request_context.h" | |
| 20 | 18 |
| 21 namespace net { | 19 namespace net { |
| 22 | 20 |
| 23 namespace { | 21 namespace { |
| 24 | 22 |
| 25 typedef std::list<URLRequestTestJob*> URLRequestJobList; | 23 typedef std::list<URLRequestTestJob*> URLRequestJobList; |
| 26 base::LazyInstance<URLRequestJobList>::Leaky | 24 base::LazyInstance<URLRequestJobList>::Leaky |
| 27 g_pending_jobs = LAZY_INSTANCE_INITIALIZER; | 25 g_pending_jobs = LAZY_INSTANCE_INITIALIZER; |
| 28 | 26 |
| 29 } // namespace | 27 } // namespace |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 // static getter for error response headers | 72 // static getter for error response headers |
| 75 std::string URLRequestTestJob::test_error_headers() { | 73 std::string URLRequestTestJob::test_error_headers() { |
| 76 static const char kHeaders[] = | 74 static const char kHeaders[] = |
| 77 "HTTP/1.1 500 BOO HOO\0" | 75 "HTTP/1.1 500 BOO HOO\0" |
| 78 "\0"; | 76 "\0"; |
| 79 return std::string(kHeaders, arraysize(kHeaders)); | 77 return std::string(kHeaders, arraysize(kHeaders)); |
| 80 } | 78 } |
| 81 | 79 |
| 82 // static | 80 // static |
| 83 URLRequestJob* URLRequestTestJob::Factory(URLRequest* request, | 81 URLRequestJob* URLRequestTestJob::Factory(URLRequest* request, |
| 82 NetworkDelegate* network_delegate, |
| 84 const std::string& scheme) { | 83 const std::string& scheme) { |
| 85 return new URLRequestTestJob(request); | 84 return new URLRequestTestJob(request, network_delegate); |
| 86 } | 85 } |
| 87 | 86 |
| 88 URLRequestTestJob::URLRequestTestJob(URLRequest* request) | 87 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 89 : URLRequestJob(request, request->context()->network_delegate()), | 88 NetworkDelegate* network_delegate) |
| 89 : URLRequestJob(request, network_delegate), |
| 90 auto_advance_(false), | 90 auto_advance_(false), |
| 91 stage_(WAITING), | 91 stage_(WAITING), |
| 92 offset_(0), | 92 offset_(0), |
| 93 async_buf_(NULL), | 93 async_buf_(NULL), |
| 94 async_buf_size_(0), | 94 async_buf_size_(0), |
| 95 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 95 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 96 } | 96 } |
| 97 | 97 |
| 98 URLRequestTestJob::URLRequestTestJob(URLRequest* request, | 98 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 99 NetworkDelegate* network_delegate, |
| 99 bool auto_advance) | 100 bool auto_advance) |
| 100 : URLRequestJob(request, request->context()->network_delegate()), | 101 : URLRequestJob(request, network_delegate), |
| 101 auto_advance_(auto_advance), | 102 auto_advance_(auto_advance), |
| 102 stage_(WAITING), | 103 stage_(WAITING), |
| 103 offset_(0), | 104 offset_(0), |
| 104 async_buf_(NULL), | 105 async_buf_(NULL), |
| 105 async_buf_size_(0), | 106 async_buf_size_(0), |
| 106 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 107 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 107 } | 108 } |
| 108 | 109 |
| 109 URLRequestTestJob::URLRequestTestJob(URLRequest* request, | 110 URLRequestTestJob::URLRequestTestJob(URLRequest* request, |
| 111 NetworkDelegate* network_delegate, |
| 110 const std::string& response_headers, | 112 const std::string& response_headers, |
| 111 const std::string& response_data, | 113 const std::string& response_data, |
| 112 bool auto_advance) | 114 bool auto_advance) |
| 113 : URLRequestJob(request, request->context()->network_delegate()), | 115 : URLRequestJob(request, network_delegate), |
| 114 auto_advance_(auto_advance), | 116 auto_advance_(auto_advance), |
| 115 stage_(WAITING), | 117 stage_(WAITING), |
| 116 response_headers_(new HttpResponseHeaders(response_headers)), | 118 response_headers_(new HttpResponseHeaders(response_headers)), |
| 117 response_data_(response_data), | 119 response_data_(response_data), |
| 118 offset_(0), | 120 offset_(0), |
| 119 async_buf_(NULL), | 121 async_buf_(NULL), |
| 120 async_buf_size_(0), | 122 async_buf_size_(0), |
| 121 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 123 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 122 } | 124 } |
| 123 | 125 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 294 |
| 293 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); | 295 URLRequestTestJob* next_job(g_pending_jobs.Get().front()); |
| 294 g_pending_jobs.Get().pop_front(); | 296 g_pending_jobs.Get().pop_front(); |
| 295 | 297 |
| 296 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q | 298 DCHECK(!next_job->auto_advance()); // auto_advance jobs should be in this q |
| 297 next_job->ProcessNextOperation(); | 299 next_job->ProcessNextOperation(); |
| 298 return true; | 300 return true; |
| 299 } | 301 } |
| 300 | 302 |
| 301 } // namespace net | 303 } // namespace net |
| OLD | NEW |