| OLD | NEW |
| 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 Loading... |
| 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 int URLRequestMockDataJob::ReadRawData(IOBuffer* buf, int buf_size) { | 107 bool URLRequestMockDataJob::ReadRawData(IOBuffer* buf, |
| 108 int bytes_read = | 108 int buf_size, |
| 109 std::min(static_cast<size_t>(buf_size), data_.length() - data_offset_); | 109 int* bytes_read) { |
| 110 memcpy(buf->data(), data_.c_str() + data_offset_, bytes_read); | 110 DCHECK(bytes_read); |
| 111 data_offset_ += bytes_read; | 111 *bytes_read = static_cast<int>( |
| 112 return bytes_read; | 112 std::min(static_cast<size_t>(buf_size), data_.length() - data_offset_)); |
| 113 memcpy(buf->data(), data_.c_str() + data_offset_, *bytes_read); |
| 114 data_offset_ += *bytes_read; |
| 115 return true; |
| 113 } | 116 } |
| 114 | 117 |
| 115 int URLRequestMockDataJob::GetResponseCode() const { | 118 int URLRequestMockDataJob::GetResponseCode() const { |
| 116 HttpResponseInfo info; | 119 HttpResponseInfo info; |
| 117 GetResponseInfoConst(&info); | 120 GetResponseInfoConst(&info); |
| 118 return info.headers->response_code(); | 121 return info.headers->response_code(); |
| 119 } | 122 } |
| 120 | 123 |
| 121 // Public virtual version. | 124 // Public virtual version. |
| 122 void URLRequestMockDataJob::GetResponseInfo(HttpResponseInfo* info) { | 125 void URLRequestMockDataJob::GetResponseInfo(HttpResponseInfo* info) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 186 |
| 184 // static | 187 // static |
| 185 GURL URLRequestMockDataJob::GetMockHttpsUrlForHostname( | 188 GURL URLRequestMockDataJob::GetMockHttpsUrlForHostname( |
| 186 const std::string& hostname, | 189 const std::string& hostname, |
| 187 const std::string& data, | 190 const std::string& data, |
| 188 int repeat_count) { | 191 int repeat_count) { |
| 189 return GetMockUrl("https", hostname, data, repeat_count); | 192 return GetMockUrl("https", hostname, data, repeat_count); |
| 190 } | 193 } |
| 191 | 194 |
| 192 } // namespace net | 195 } // namespace net |
| OLD | NEW |