| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 MessageLoop::current()->PostTask( | 83 MessageLoop::current()->PostTask( |
| 84 FROM_HERE, | 84 FROM_HERE, |
| 85 base::Bind(&URLRequestAbortOnEndJob::StartAsync, | 85 base::Bind(&URLRequestAbortOnEndJob::StartAsync, |
| 86 weak_factory_.GetWeakPtr())); | 86 weak_factory_.GetWeakPtr())); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool URLRequestAbortOnEndJob::ReadRawData(net::IOBuffer* buf, | 89 bool URLRequestAbortOnEndJob::ReadRawData(net::IOBuffer* buf, |
| 90 const int max_bytes, | 90 const int max_bytes, |
| 91 int* bytes_read) { | 91 int* bytes_read) { |
| 92 if (!sent_data_) { | 92 if (!sent_data_) { |
| 93 *bytes_read = std::max(size_t(max_bytes), sizeof(kPageContent)); | 93 *bytes_read = std::min(size_t(max_bytes), sizeof(kPageContent)); |
| 94 std::memcpy(buf->data(), kPageContent, *bytes_read); | 94 std::memcpy(buf->data(), kPageContent, *bytes_read); |
| 95 sent_data_ = true; | 95 sent_data_ = true; |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 99 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 100 net::ERR_CONNECTION_ABORTED)); | 100 net::ERR_CONNECTION_ABORTED)); |
| 101 *bytes_read = -1; | 101 *bytes_read = -1; |
| 102 return false; | 102 return false; |
| 103 } | 103 } |
| 104 | 104 |
| 105 | 105 |
| OLD | NEW |