OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sdch_dictionary_fetcher.h" | 5 #include "net/url_request/sdch_dictionary_fetcher.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 if (rv != OK) { | 192 if (rv != OK) { |
193 current_request_.reset(); | 193 current_request_.reset(); |
194 buffer_ = NULL; | 194 buffer_ = NULL; |
195 next_state_ = STATE_IDLE; | 195 next_state_ = STATE_IDLE; |
196 | 196 |
197 return OK; | 197 return OK; |
198 } | 198 } |
199 | 199 |
200 next_state_ = STATE_REQUEST_READING; | 200 next_state_ = STATE_REQUEST_READING; |
201 int bytes_read = 0; | 201 int bytes_read = 0; |
202 if (!current_request_->Read(buffer_.get(), kBufferSize, &bytes_read)) { | 202 current_request_->Read(buffer_.get(), kBufferSize, &bytes_read); |
203 if (current_request_->status().is_io_pending()) | 203 if (current_request_->status().is_io_pending()) |
204 return ERR_IO_PENDING; | 204 return ERR_IO_PENDING; |
205 | 205 |
206 if (current_request_->status().error() == OK) { | 206 if (bytes_read < 0 || !current_request_->status().is_success()) { |
207 // This "should never happen", but if it does the result will be | 207 if (current_request_->status().error() != OK) |
208 // an infinite loop. It's not clear how to handle a read failure | 208 return current_request_->status().error(); |
209 // without a promise to invoke the callback at some point in the future, | |
210 // so the request is failed. | |
211 SdchManager::SdchErrorRecovery(SDCH_DICTIONARY_FETCH_READ_FAILED); | |
212 current_request_->net_log().AddEvent( | |
213 NetLog::TYPE_SDCH_DICTIONARY_ERROR, | |
214 base::Bind(&NetLogSdchDictionaryFetchProblemCallback, | |
215 SDCH_DICTIONARY_FETCH_READ_FAILED, current_request_->url(), | |
216 true)); | |
217 DLOG(FATAL) | |
218 << "URLRequest::Read() returned false without IO pending or error!"; | |
219 return ERR_FAILED; | |
220 } | |
221 | 209 |
222 return current_request_->status().error(); | 210 // An error with request status of OK should not happen, |
| 211 // but there's enough machinery underneath URLRequest::Read() |
| 212 // that this routine checks for that case. |
| 213 net::Error error = |
| 214 current_request_->status().status() == URLRequestStatus::CANCELED ? |
| 215 ERR_ABORTED : ERR_FAILED; |
| 216 current_request_->net_log().AddEventWithNetErrorCode( |
| 217 NetLog::TYPE_SDCH_DICTIONARY_FETCH_IMPLIED_ERROR, error); |
| 218 return error; |
223 } | 219 } |
224 | 220 |
225 if (bytes_read != 0) | 221 if (bytes_read == 0) |
| 222 next_state_ = STATE_REQUEST_COMPLETE; |
| 223 else |
226 dictionary_.append(buffer_->data(), bytes_read); | 224 dictionary_.append(buffer_->data(), bytes_read); |
227 else | |
228 next_state_ = STATE_REQUEST_COMPLETE; | |
229 | 225 |
230 return OK; | 226 return OK; |
231 } | 227 } |
232 | 228 |
233 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { | 229 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { |
234 DCHECK(CalledOnValidThread()); | 230 DCHECK(CalledOnValidThread()); |
235 | 231 |
236 // If the dictionary was successfully fetched, add it to the manager. | 232 // If the dictionary was successfully fetched, add it to the manager. |
237 if (rv == OK) { | 233 if (rv == OK) { |
238 dictionary_fetched_callback_.Run(dictionary_, current_request_->url(), | 234 dictionary_fetched_callback_.Run(dictionary_, current_request_->url(), |
239 current_request_->net_log()); | 235 current_request_->net_log()); |
240 } | 236 } |
241 | 237 |
242 current_request_.reset(); | 238 current_request_.reset(); |
243 buffer_ = NULL; | 239 buffer_ = NULL; |
244 dictionary_.clear(); | 240 dictionary_.clear(); |
245 | 241 |
246 next_state_ = STATE_IDLE; | 242 next_state_ = STATE_IDLE; |
247 | 243 |
248 return OK; | 244 return OK; |
249 } | 245 } |
250 | 246 |
251 } // namespace net | 247 } // namespace net |
OLD | NEW |