OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/url_request/url_request_job.h" | 5 #include "net/url_request/url_request_job.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "net/base/auth.h" | 9 #include "net/base/auth.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 metrics_.reset(new URLRequestJobMetrics()); | 46 metrics_.reset(new URLRequestJobMetrics()); |
47 metrics_->start_time_ = TimeTicks::Now(); | 47 metrics_->start_time_ = TimeTicks::Now(); |
48 } | 48 } |
49 g_url_request_job_tracker.AddNewJob(this); | 49 g_url_request_job_tracker.AddNewJob(this); |
50 } | 50 } |
51 | 51 |
52 URLRequestJob::~URLRequestJob() { | 52 URLRequestJob::~URLRequestJob() { |
53 g_url_request_job_tracker.RemoveJob(this); | 53 g_url_request_job_tracker.RemoveJob(this); |
54 } | 54 } |
55 | 55 |
| 56 void URLRequestJob::SetUpload(net::UploadData* upload) { |
| 57 } |
| 58 |
| 59 void URLRequestJob::SetExtraRequestHeaders( |
| 60 const net::HttpRequestHeaders& headers) { |
| 61 } |
| 62 |
56 void URLRequestJob::Kill() { | 63 void URLRequestJob::Kill() { |
57 // Make sure the request is notified that we are done. We assume that the | 64 // Make sure the request is notified that we are done. We assume that the |
58 // request took care of setting its error status before calling Kill. | 65 // request took care of setting its error status before calling Kill. |
59 if (request_) | 66 if (request_) |
60 NotifyCanceled(); | 67 NotifyCanceled(); |
61 } | 68 } |
62 | 69 |
63 void URLRequestJob::DetachRequest() { | 70 void URLRequestJob::DetachRequest() { |
64 request_ = NULL; | 71 request_ = NULL; |
65 } | 72 } |
66 | 73 |
67 bool URLRequestJob::IsDownload() const { | |
68 return (load_flags_ & net::LOAD_IS_DOWNLOAD) != 0; | |
69 } | |
70 | |
71 void URLRequestJob::SetupFilter() { | 74 void URLRequestJob::SetupFilter() { |
72 std::vector<Filter::FilterType> encoding_types; | 75 std::vector<Filter::FilterType> encoding_types; |
73 if (GetContentEncodings(&encoding_types)) { | 76 if (GetContentEncodings(&encoding_types)) { |
74 filter_.reset(Filter::Factory(encoding_types, *this)); | 77 filter_.reset(Filter::Factory(encoding_types, *this)); |
75 } | 78 } |
76 } | 79 } |
77 | 80 |
78 bool URLRequestJob::IsRedirectResponse(GURL* location, | 81 bool URLRequestJob::IsRedirectResponse(GURL* location, |
79 int* http_status_code) { | 82 int* http_status_code) { |
80 // For non-HTTP jobs, headers will be null. | 83 // For non-HTTP jobs, headers will be null. |
81 net::HttpResponseHeaders* headers = request_->response_headers(); | 84 net::HttpResponseHeaders* headers = request_->response_headers(); |
82 if (!headers) | 85 if (!headers) |
83 return false; | 86 return false; |
84 | 87 |
85 std::string value; | 88 std::string value; |
86 if (!headers->IsRedirect(&value)) | 89 if (!headers->IsRedirect(&value)) |
87 return false; | 90 return false; |
88 | 91 |
89 *location = request_->url().Resolve(value); | 92 *location = request_->url().Resolve(value); |
90 *http_status_code = headers->response_code(); | 93 *http_status_code = headers->response_code(); |
91 return true; | 94 return true; |
92 } | 95 } |
93 | 96 |
| 97 bool URLRequestJob::IsSafeRedirect(const GURL& location) { |
| 98 return true; |
| 99 } |
| 100 |
| 101 bool URLRequestJob::NeedsAuth() { |
| 102 return false; |
| 103 } |
| 104 |
94 void URLRequestJob::GetAuthChallengeInfo( | 105 void URLRequestJob::GetAuthChallengeInfo( |
95 scoped_refptr<net::AuthChallengeInfo>* auth_info) { | 106 scoped_refptr<net::AuthChallengeInfo>* auth_info) { |
96 // This will only be called if NeedsAuth() returns true, in which | 107 // This will only be called if NeedsAuth() returns true, in which |
97 // case the derived class should implement this! | 108 // case the derived class should implement this! |
98 NOTREACHED(); | 109 NOTREACHED(); |
99 } | 110 } |
100 | 111 |
101 void URLRequestJob::SetAuth(const std::wstring& username, | 112 void URLRequestJob::SetAuth(const std::wstring& username, |
102 const std::wstring& password) { | 113 const std::wstring& password) { |
103 // This will only be called if NeedsAuth() returns true, in which | 114 // This will only be called if NeedsAuth() returns true, in which |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 deferred_redirect_url_ = GURL(); | 151 deferred_redirect_url_ = GURL(); |
141 deferred_redirect_status_code_ = -1; | 152 deferred_redirect_status_code_ = -1; |
142 | 153 |
143 FollowRedirect(redirect_url, redirect_status_code); | 154 FollowRedirect(redirect_url, redirect_status_code); |
144 } | 155 } |
145 | 156 |
146 int64 URLRequestJob::GetByteReadCount() const { | 157 int64 URLRequestJob::GetByteReadCount() const { |
147 return filter_input_byte_count_; | 158 return filter_input_byte_count_; |
148 } | 159 } |
149 | 160 |
| 161 bool URLRequestJob::GetMimeType(std::string* mime_type) const { |
| 162 return false; |
| 163 } |
| 164 |
150 bool URLRequestJob::GetURL(GURL* gurl) const { | 165 bool URLRequestJob::GetURL(GURL* gurl) const { |
151 if (!request_) | 166 if (!request_) |
152 return false; | 167 return false; |
153 *gurl = request_->url(); | 168 *gurl = request_->url(); |
154 return true; | 169 return true; |
155 } | 170 } |
156 | 171 |
157 base::Time URLRequestJob::GetRequestTime() const { | 172 base::Time URLRequestJob::GetRequestTime() const { |
158 if (!request_) | 173 if (!request_) |
159 return base::Time(); | 174 return base::Time(); |
160 return request_->request_time(); | 175 return request_->request_time(); |
161 }; | 176 }; |
162 | 177 |
| 178 bool URLRequestJob::IsCachedContent() const { |
| 179 return false; |
| 180 } |
| 181 |
| 182 int URLRequestJob::GetResponseCode() const { |
| 183 return -1; |
| 184 } |
| 185 |
| 186 int URLRequestJob::GetInputStreamBufferSize() const { |
| 187 return kFilterBufSize; |
| 188 } |
| 189 |
163 // This function calls ReadData to get stream data. If a filter exists, passes | 190 // This function calls ReadData to get stream data. If a filter exists, passes |
164 // the data to the attached filter. Then returns the output from filter back to | 191 // the data to the attached filter. Then returns the output from filter back to |
165 // the caller. | 192 // the caller. |
166 bool URLRequestJob::Read(net::IOBuffer* buf, int buf_size, int *bytes_read) { | 193 bool URLRequestJob::Read(net::IOBuffer* buf, int buf_size, int *bytes_read) { |
167 bool rv = false; | 194 bool rv = false; |
168 | 195 |
169 DCHECK_LT(buf_size, 1000000); // sanity check | 196 DCHECK_LT(buf_size, 1000000); // sanity check |
170 DCHECK(buf); | 197 DCHECK(buf); |
171 DCHECK(bytes_read); | 198 DCHECK(bytes_read); |
172 | 199 |
(...skipping 18 matching lines...) Expand all Loading... |
191 } | 218 } |
192 if (rv && *bytes_read == 0) | 219 if (rv && *bytes_read == 0) |
193 NotifyDone(URLRequestStatus()); | 220 NotifyDone(URLRequestStatus()); |
194 return rv; | 221 return rv; |
195 } | 222 } |
196 | 223 |
197 void URLRequestJob::StopCaching() { | 224 void URLRequestJob::StopCaching() { |
198 // Nothing to do here. | 225 // Nothing to do here. |
199 } | 226 } |
200 | 227 |
| 228 net::LoadState URLRequestJob::GetLoadState() const { |
| 229 return net::LOAD_STATE_IDLE; |
| 230 } |
| 231 |
| 232 uint64 URLRequestJob::GetUploadProgress() const { |
| 233 return 0; |
| 234 } |
| 235 |
| 236 bool URLRequestJob::GetCharset(std::string* charset) { |
| 237 return false; |
| 238 } |
| 239 |
| 240 void URLRequestJob::GetResponseInfo(net::HttpResponseInfo* info) { |
| 241 } |
| 242 |
| 243 bool URLRequestJob::GetResponseCookies(std::vector<std::string>* cookies) { |
| 244 return false; |
| 245 } |
| 246 |
| 247 bool URLRequestJob::GetContentEncodings( |
| 248 std::vector<Filter::FilterType>* encoding_types) { |
| 249 return false; |
| 250 } |
| 251 |
| 252 bool URLRequestJob::IsDownload() const { |
| 253 return (load_flags_ & net::LOAD_IS_DOWNLOAD) != 0; |
| 254 } |
| 255 |
| 256 bool URLRequestJob::IsSdchResponse() const { |
| 257 return false; |
| 258 } |
| 259 |
201 bool URLRequestJob::ReadRawDataForFilter(int* bytes_read) { | 260 bool URLRequestJob::ReadRawDataForFilter(int* bytes_read) { |
202 bool rv = false; | 261 bool rv = false; |
203 | 262 |
204 DCHECK(bytes_read); | 263 DCHECK(bytes_read); |
205 DCHECK(filter_.get()); | 264 DCHECK(filter_.get()); |
206 | 265 |
207 *bytes_read = 0; | 266 *bytes_read = 0; |
208 | 267 |
209 // Get more pre-filtered data if needed. | 268 // Get more pre-filtered data if needed. |
210 // TODO(mbelshe): is it possible that the filter needs *MORE* data | 269 // TODO(mbelshe): is it possible that the filter needs *MORE* data |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 return; | 893 return; |
835 } | 894 } |
836 | 895 |
837 if (is_compressed_) { | 896 if (is_compressed_) { |
838 COMPRESSION_HISTOGRAM("NoProxy.BytesBeforeCompression", compressed_B); | 897 COMPRESSION_HISTOGRAM("NoProxy.BytesBeforeCompression", compressed_B); |
839 COMPRESSION_HISTOGRAM("NoProxy.BytesAfterCompression", decompressed_B); | 898 COMPRESSION_HISTOGRAM("NoProxy.BytesAfterCompression", decompressed_B); |
840 } else { | 899 } else { |
841 COMPRESSION_HISTOGRAM("NoProxy.ShouldHaveBeenCompressed", decompressed_B); | 900 COMPRESSION_HISTOGRAM("NoProxy.ShouldHaveBeenCompressed", decompressed_B); |
842 } | 901 } |
843 } | 902 } |
OLD | NEW |