Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: net/test/url_request/url_request_slow_download_job.cc

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/test/url_request/url_request_mock_http_job.cc ('k') | net/tools/balsa/balsa_frame.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test/url_request/url_request_slow_download_job.h" 5 #include "net/test/url_request/url_request_slow_download_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 NetworkDelegate* network_delegate) 94 NetworkDelegate* network_delegate)
95 : URLRequestJob(request, network_delegate), 95 : URLRequestJob(request, network_delegate),
96 bytes_already_sent_(0), 96 bytes_already_sent_(0),
97 should_error_download_(false), 97 should_error_download_(false),
98 should_finish_download_(false), 98 should_finish_download_(false),
99 buffer_size_(0), 99 buffer_size_(0),
100 weak_factory_(this) { 100 weak_factory_(this) {
101 } 101 }
102 102
103 void URLRequestSlowDownloadJob::StartAsync() { 103 void URLRequestSlowDownloadJob::StartAsync() {
104 if (LowerCaseEqualsASCII(kFinishDownloadUrl, request_->url().spec().c_str())) 104 if (base::LowerCaseEqualsASCII(kFinishDownloadUrl,
105 request_->url().spec().c_str())) {
105 URLRequestSlowDownloadJob::FinishPendingRequests(); 106 URLRequestSlowDownloadJob::FinishPendingRequests();
106 if (LowerCaseEqualsASCII(kErrorDownloadUrl, request_->url().spec().c_str())) 107 }
108 if (base::LowerCaseEqualsASCII(kErrorDownloadUrl,
109 request_->url().spec().c_str())) {
107 URLRequestSlowDownloadJob::ErrorPendingRequests(); 110 URLRequestSlowDownloadJob::ErrorPendingRequests();
111 }
108 112
109 NotifyHeadersComplete(); 113 NotifyHeadersComplete();
110 } 114 }
111 115
112 // ReadRawData and CheckDoneStatus together implement a state 116 // ReadRawData and CheckDoneStatus together implement a state
113 // machine. ReadRawData may be called arbitrarily by the network stack. 117 // machine. ReadRawData may be called arbitrarily by the network stack.
114 // It responds by: 118 // It responds by:
115 // * If there are bytes remaining in the first chunk, they are 119 // * If there are bytes remaining in the first chunk, they are
116 // returned. 120 // returned.
117 // [No bytes remaining in first chunk. ] 121 // [No bytes remaining in first chunk. ]
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 bytes_already_sent_ += bytes_to_write; 161 bytes_already_sent_ += bytes_to_write;
158 return BUFFER_FILLED; 162 return BUFFER_FILLED;
159 } 163 }
160 164
161 return REQUEST_COMPLETE; 165 return REQUEST_COMPLETE;
162 } 166 }
163 167
164 bool URLRequestSlowDownloadJob::ReadRawData(IOBuffer* buf, 168 bool URLRequestSlowDownloadJob::ReadRawData(IOBuffer* buf,
165 int buf_size, 169 int buf_size,
166 int* bytes_read) { 170 int* bytes_read) {
167 if (LowerCaseEqualsASCII(kFinishDownloadUrl, 171 if (base::LowerCaseEqualsASCII(kFinishDownloadUrl,
168 request_->url().spec().c_str()) || 172 request_->url().spec().c_str()) ||
169 LowerCaseEqualsASCII(kErrorDownloadUrl, request_->url().spec().c_str())) { 173 base::LowerCaseEqualsASCII(kErrorDownloadUrl,
174 request_->url().spec().c_str())) {
170 VLOG(10) << __FUNCTION__ << " called w/ kFinish/ErrorDownloadUrl."; 175 VLOG(10) << __FUNCTION__ << " called w/ kFinish/ErrorDownloadUrl.";
171 *bytes_read = 0; 176 *bytes_read = 0;
172 return true; 177 return true;
173 } 178 }
174 179
175 VLOG(10) << __FUNCTION__ << " called at position " << bytes_already_sent_ 180 VLOG(10) << __FUNCTION__ << " called at position " << bytes_already_sent_
176 << " in the stream."; 181 << " in the stream.";
177 ReadStatus status = FillBufferHelper(buf, buf_size, bytes_read); 182 ReadStatus status = FillBufferHelper(buf, buf_size, bytes_read);
178 switch (status) { 183 switch (status) {
179 case BUFFER_FILLED: 184 case BUFFER_FILLED:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 231
227 URLRequestSlowDownloadJob::~URLRequestSlowDownloadJob() { 232 URLRequestSlowDownloadJob::~URLRequestSlowDownloadJob() {
228 pending_requests_.Get().erase(this); 233 pending_requests_.Get().erase(this);
229 } 234 }
230 235
231 // Private const version. 236 // Private const version.
232 void URLRequestSlowDownloadJob::GetResponseInfoConst( 237 void URLRequestSlowDownloadJob::GetResponseInfoConst(
233 HttpResponseInfo* info) const { 238 HttpResponseInfo* info) const {
234 // Send back mock headers. 239 // Send back mock headers.
235 std::string raw_headers; 240 std::string raw_headers;
236 if (LowerCaseEqualsASCII(kFinishDownloadUrl, 241 if (base::LowerCaseEqualsASCII(kFinishDownloadUrl,
237 request_->url().spec().c_str()) || 242 request_->url().spec().c_str()) ||
238 LowerCaseEqualsASCII(kErrorDownloadUrl, request_->url().spec().c_str())) { 243 base::LowerCaseEqualsASCII(kErrorDownloadUrl,
244 request_->url().spec().c_str())) {
239 raw_headers.append( 245 raw_headers.append(
240 "HTTP/1.1 200 OK\n" 246 "HTTP/1.1 200 OK\n"
241 "Content-type: text/plain\n"); 247 "Content-type: text/plain\n");
242 } else { 248 } else {
243 raw_headers.append( 249 raw_headers.append(
244 "HTTP/1.1 200 OK\n" 250 "HTTP/1.1 200 OK\n"
245 "Content-type: application/octet-stream\n" 251 "Content-type: application/octet-stream\n"
246 "Cache-Control: max-age=0\n"); 252 "Cache-Control: max-age=0\n");
247 253
248 if (LowerCaseEqualsASCII(kKnownSizeUrl, request_->url().spec().c_str())) { 254 if (base::LowerCaseEqualsASCII(kKnownSizeUrl,
255 request_->url().spec().c_str())) {
249 raw_headers.append(base::StringPrintf( 256 raw_headers.append(base::StringPrintf(
250 "Content-Length: %d\n", kFirstDownloadSize + kSecondDownloadSize)); 257 "Content-Length: %d\n", kFirstDownloadSize + kSecondDownloadSize));
251 } 258 }
252 } 259 }
253 260
254 // ParseRawHeaders expects \0 to end each header line. 261 // ParseRawHeaders expects \0 to end each header line.
255 ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n", std::string("\0", 1)); 262 base::ReplaceSubstringsAfterOffset(&raw_headers, 0, "\n",
263 std::string("\0", 1));
256 info->headers = new HttpResponseHeaders(raw_headers); 264 info->headers = new HttpResponseHeaders(raw_headers);
257 } 265 }
258 266
259 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const { 267 bool URLRequestSlowDownloadJob::GetMimeType(std::string* mime_type) const {
260 HttpResponseInfo info; 268 HttpResponseInfo info;
261 GetResponseInfoConst(&info); 269 GetResponseInfoConst(&info);
262 return info.headers.get() && info.headers->GetMimeType(mime_type); 270 return info.headers.get() && info.headers->GetMimeType(mime_type);
263 } 271 }
264 272
265 } // namespace net 273 } // namespace net
OLDNEW
« no previous file with comments | « net/test/url_request/url_request_mock_http_job.cc ('k') | net/tools/balsa/balsa_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698