| 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 // This class simulates what wininet does when a dns lookup fails. | 4 // This class simulates what wininet does when a dns lookup fails. |
| 5 | 5 |
| 6 #include <algorithm> | 6 #include <algorithm> |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void URLRequestAbortOnEndJob::StartAsync() { | 104 void URLRequestAbortOnEndJob::StartAsync() { |
| 105 NotifyHeadersComplete(); | 105 NotifyHeadersComplete(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void URLRequestAbortOnEndJob::Start() { | 108 void URLRequestAbortOnEndJob::Start() { |
| 109 base::ThreadTaskRunnerHandle::Get()->PostTask( | 109 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 110 FROM_HERE, base::Bind(&URLRequestAbortOnEndJob::StartAsync, | 110 FROM_HERE, base::Bind(&URLRequestAbortOnEndJob::StartAsync, |
| 111 weak_factory_.GetWeakPtr())); | 111 weak_factory_.GetWeakPtr())); |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool URLRequestAbortOnEndJob::ReadRawData(net::IOBuffer* buf, | 114 int URLRequestAbortOnEndJob::ReadRawData(net::IOBuffer* buf, int max_bytes) { |
| 115 const int max_bytes, | |
| 116 int* bytes_read) { | |
| 117 if (!sent_data_) { | 115 if (!sent_data_) { |
| 118 *bytes_read = std::min(size_t(max_bytes), sizeof(kPageContent)); | 116 max_bytes = |
| 119 std::memcpy(buf->data(), kPageContent, *bytes_read); | 117 std::min(max_bytes, base::checked_cast<int>(sizeof(kPageContent))); |
| 118 std::memcpy(buf->data(), kPageContent, max_bytes); |
| 120 sent_data_ = true; | 119 sent_data_ = true; |
| 121 return true; | 120 return max_bytes; |
| 122 } | 121 } |
| 123 | 122 |
| 124 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 123 return net::ERR_CONNECTION_ABORTED; |
| 125 net::ERR_CONNECTION_ABORTED)); | |
| 126 *bytes_read = -1; | |
| 127 return false; | |
| 128 } | 124 } |
| 129 | 125 |
| 130 } // namespace content | 126 } // namespace content |
| OLD | NEW |