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

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

Issue 1467603002: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add done_reading_called_ to MockNetworkTransaction Created 5 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_mock_data_job.h" 5 #include "net/test/url_request/url_request_mock_data_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // Start reading asynchronously so that all error reporting and data 97 // Start reading asynchronously so that all error reporting and data
98 // callbacks happen as they would for network requests. 98 // callbacks happen as they would for network requests.
99 base::ThreadTaskRunnerHandle::Get()->PostTask( 99 base::ThreadTaskRunnerHandle::Get()->PostTask(
100 FROM_HERE, base::Bind(&URLRequestMockDataJob::StartAsync, 100 FROM_HERE, base::Bind(&URLRequestMockDataJob::StartAsync,
101 weak_factory_.GetWeakPtr())); 101 weak_factory_.GetWeakPtr()));
102 } 102 }
103 103
104 URLRequestMockDataJob::~URLRequestMockDataJob() { 104 URLRequestMockDataJob::~URLRequestMockDataJob() {
105 } 105 }
106 106
107 bool URLRequestMockDataJob::ReadRawData(IOBuffer* buf, 107 int URLRequestMockDataJob::ReadRawData(IOBuffer* buf, int buf_size) {
108 int buf_size, 108 int bytes_read =
109 int* bytes_read) { 109 std::min(static_cast<size_t>(buf_size), data_.length() - data_offset_);
110 DCHECK(bytes_read); 110 memcpy(buf->data(), data_.c_str() + data_offset_, bytes_read);
111 *bytes_read = static_cast<int>( 111 data_offset_ += bytes_read;
112 std::min(static_cast<size_t>(buf_size), data_.length() - data_offset_)); 112 return bytes_read;
113 memcpy(buf->data(), data_.c_str() + data_offset_, *bytes_read);
114 data_offset_ += *bytes_read;
115 return true;
116 } 113 }
117 114
118 int URLRequestMockDataJob::GetResponseCode() const { 115 int URLRequestMockDataJob::GetResponseCode() const {
119 HttpResponseInfo info; 116 HttpResponseInfo info;
120 GetResponseInfoConst(&info); 117 GetResponseInfoConst(&info);
121 return info.headers->response_code(); 118 return info.headers->response_code();
122 } 119 }
123 120
124 // Public virtual version. 121 // Public virtual version.
125 void URLRequestMockDataJob::GetResponseInfo(HttpResponseInfo* info) { 122 void URLRequestMockDataJob::GetResponseInfo(HttpResponseInfo* info) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 183
187 // static 184 // static
188 GURL URLRequestMockDataJob::GetMockHttpsUrlForHostname( 185 GURL URLRequestMockDataJob::GetMockHttpsUrlForHostname(
189 const std::string& hostname, 186 const std::string& hostname,
190 const std::string& data, 187 const std::string& data,
191 int repeat_count) { 188 int repeat_count) {
192 return GetMockUrl("https", hostname, data, repeat_count); 189 return GetMockUrl("https", hostname, data, repeat_count);
193 } 190 }
194 191
195 } // namespace net 192 } // namespace net
OLDNEW
« no previous file with comments | « net/test/url_request/url_request_mock_data_job.h ('k') | net/test/url_request/url_request_slow_download_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698