OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "net/url_request/url_request_test_job.h" | 7 #include "net/url_request/url_request_test_job.h" |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // FIXME(brettw): this should emulate a network error, and not just fail | 86 // FIXME(brettw): this should emulate a network error, and not just fail |
87 // initiating a connection | 87 // initiating a connection |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 pending_jobs.push_back(scoped_refptr<URLRequestTestJob>(this)); | 91 pending_jobs.push_back(scoped_refptr<URLRequestTestJob>(this)); |
92 | 92 |
93 this->NotifyHeadersComplete(); | 93 this->NotifyHeadersComplete(); |
94 } | 94 } |
95 | 95 |
96 bool URLRequestTestJob::ReadRawData(char* buf, int buf_size, int *bytes_read) { | 96 bool URLRequestTestJob::ReadRawData(net::IOBuffer* buf, int buf_size, |
| 97 int *bytes_read) { |
97 if (stage_ == WAITING) { | 98 if (stage_ == WAITING) { |
98 async_buf_ = buf; | 99 async_buf_ = buf; |
99 async_buf_size_ = buf_size; | 100 async_buf_size_ = buf_size; |
100 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 101 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
101 return false; | 102 return false; |
102 } | 103 } |
103 | 104 |
104 DCHECK(bytes_read); | 105 DCHECK(bytes_read); |
105 *bytes_read = 0; | 106 *bytes_read = 0; |
106 | 107 |
107 if (offset_ >= static_cast<int>(data_.length())) { | 108 if (offset_ >= static_cast<int>(data_.length())) { |
108 return true; // done reading | 109 return true; // done reading |
109 } | 110 } |
110 | 111 |
111 int to_read = buf_size; | 112 int to_read = buf_size; |
112 if (to_read + offset_ > static_cast<int>(data_.length())) | 113 if (to_read + offset_ > static_cast<int>(data_.length())) |
113 to_read = static_cast<int>(data_.length()) - offset_; | 114 to_read = static_cast<int>(data_.length()) - offset_; |
114 | 115 |
115 memcpy(buf, &data_.c_str()[offset_], to_read); | 116 memcpy(buf->data(), &data_.c_str()[offset_], to_read); |
116 offset_ += to_read; | 117 offset_ += to_read; |
117 | 118 |
118 *bytes_read = to_read; | 119 *bytes_read = to_read; |
119 return true; | 120 return true; |
120 } | 121 } |
121 | 122 |
122 void URLRequestTestJob::GetResponseInfo(net::HttpResponseInfo* info) { | 123 void URLRequestTestJob::GetResponseInfo(net::HttpResponseInfo* info) { |
123 const std::string kResponseHeaders = StringPrintf( | 124 const std::string kResponseHeaders = StringPrintf( |
124 "HTTP/1.1 200 OK%c" | 125 "HTTP/1.1 200 OK%c" |
125 "Content-type: text/html%c" | 126 "Content-type: text/html%c" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 172 |
172 scoped_refptr<URLRequestTestJob> next_job(pending_jobs[0]); | 173 scoped_refptr<URLRequestTestJob> next_job(pending_jobs[0]); |
173 pending_jobs.erase(pending_jobs.begin()); | 174 pending_jobs.erase(pending_jobs.begin()); |
174 | 175 |
175 if (next_job->ProcessNextOperation()) | 176 if (next_job->ProcessNextOperation()) |
176 pending_jobs.push_back(next_job); | 177 pending_jobs.push_back(next_job); |
177 | 178 |
178 return true; | 179 return true; |
179 } | 180 } |
180 | 181 |
OLD | NEW |