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/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 net::HttpResponseInfo info; | 84 net::HttpResponseInfo info; |
85 GetResponseInfoConst(&info); | 85 GetResponseInfoConst(&info); |
86 return info.headers && info.headers->GetMimeType(mime_type); | 86 return info.headers && info.headers->GetMimeType(mime_type); |
87 } | 87 } |
88 | 88 |
89 void URLRequestAbortOnEndJob::StartAsync() { | 89 void URLRequestAbortOnEndJob::StartAsync() { |
90 NotifyHeadersComplete(); | 90 NotifyHeadersComplete(); |
91 } | 91 } |
92 | 92 |
93 void URLRequestAbortOnEndJob::Start() { | 93 void URLRequestAbortOnEndJob::Start() { |
94 MessageLoop::current()->PostTask( | 94 base::MessageLoop::current()->PostTask( |
95 FROM_HERE, | 95 FROM_HERE, |
96 base::Bind(&URLRequestAbortOnEndJob::StartAsync, | 96 base::Bind(&URLRequestAbortOnEndJob::StartAsync, |
97 weak_factory_.GetWeakPtr())); | 97 weak_factory_.GetWeakPtr())); |
98 } | 98 } |
99 | 99 |
100 bool URLRequestAbortOnEndJob::ReadRawData(net::IOBuffer* buf, | 100 bool URLRequestAbortOnEndJob::ReadRawData(net::IOBuffer* buf, |
101 const int max_bytes, | 101 const int max_bytes, |
102 int* bytes_read) { | 102 int* bytes_read) { |
103 if (!sent_data_) { | 103 if (!sent_data_) { |
104 *bytes_read = std::min(size_t(max_bytes), sizeof(kPageContent)); | 104 *bytes_read = std::min(size_t(max_bytes), sizeof(kPageContent)); |
105 std::memcpy(buf->data(), kPageContent, *bytes_read); | 105 std::memcpy(buf->data(), kPageContent, *bytes_read); |
106 sent_data_ = true; | 106 sent_data_ = true; |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 110 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
111 net::ERR_CONNECTION_ABORTED)); | 111 net::ERR_CONNECTION_ABORTED)); |
112 *bytes_read = -1; | 112 *bytes_read = -1; |
113 return false; | 113 return false; |
114 } | 114 } |
115 | 115 |
116 } // namespace content | 116 } // namespace content |
OLD | NEW |