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" | |
11 #include "base/single_thread_task_runner.h" | |
12 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
13 #include "base/thread_task_runner_handle.h" | |
14 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
15 #include "content/test/net/url_request_abort_on_end_job.h" | 12 #include "content/test/net/url_request_abort_on_end_job.h" |
16 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
18 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
19 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
20 #include "net/url_request/url_request_filter.h" | 17 #include "net/url_request/url_request_filter.h" |
21 #include "net/url_request/url_request_interceptor.h" | 18 #include "net/url_request/url_request_interceptor.h" |
22 #include "net/url_request/url_request_status.h" | 19 #include "net/url_request/url_request_status.h" |
23 | 20 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 net::HttpResponseInfo info; | 95 net::HttpResponseInfo info; |
99 GetResponseInfoConst(&info); | 96 GetResponseInfoConst(&info); |
100 return info.headers.get() && info.headers->GetMimeType(mime_type); | 97 return info.headers.get() && info.headers->GetMimeType(mime_type); |
101 } | 98 } |
102 | 99 |
103 void URLRequestAbortOnEndJob::StartAsync() { | 100 void URLRequestAbortOnEndJob::StartAsync() { |
104 NotifyHeadersComplete(); | 101 NotifyHeadersComplete(); |
105 } | 102 } |
106 | 103 |
107 void URLRequestAbortOnEndJob::Start() { | 104 void URLRequestAbortOnEndJob::Start() { |
108 base::ThreadTaskRunnerHandle::Get()->PostTask( | 105 base::MessageLoop::current()->PostTask( |
109 FROM_HERE, base::Bind(&URLRequestAbortOnEndJob::StartAsync, | 106 FROM_HERE, |
110 weak_factory_.GetWeakPtr())); | 107 base::Bind(&URLRequestAbortOnEndJob::StartAsync, |
| 108 weak_factory_.GetWeakPtr())); |
111 } | 109 } |
112 | 110 |
113 bool URLRequestAbortOnEndJob::ReadRawData(net::IOBuffer* buf, | 111 bool URLRequestAbortOnEndJob::ReadRawData(net::IOBuffer* buf, |
114 const int max_bytes, | 112 const int max_bytes, |
115 int* bytes_read) { | 113 int* bytes_read) { |
116 if (!sent_data_) { | 114 if (!sent_data_) { |
117 *bytes_read = std::min(size_t(max_bytes), sizeof(kPageContent)); | 115 *bytes_read = std::min(size_t(max_bytes), sizeof(kPageContent)); |
118 std::memcpy(buf->data(), kPageContent, *bytes_read); | 116 std::memcpy(buf->data(), kPageContent, *bytes_read); |
119 sent_data_ = true; | 117 sent_data_ = true; |
120 return true; | 118 return true; |
121 } | 119 } |
122 | 120 |
123 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 121 SetStatus(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
124 net::ERR_CONNECTION_ABORTED)); | 122 net::ERR_CONNECTION_ABORTED)); |
125 *bytes_read = -1; | 123 *bytes_read = -1; |
126 return false; | 124 return false; |
127 } | 125 } |
128 | 126 |
129 } // namespace content | 127 } // namespace content |
OLD | NEW |