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