Chromium Code Reviews| 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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 if (rv != OK) { | 191 if (rv != OK) { |
| 192 current_request_.reset(); | 192 current_request_.reset(); |
| 193 buffer_ = NULL; | 193 buffer_ = NULL; |
| 194 next_state_ = STATE_IDLE; | 194 next_state_ = STATE_IDLE; |
| 195 | 195 |
| 196 return OK; | 196 return OK; |
| 197 } | 197 } |
| 198 | 198 |
| 199 next_state_ = STATE_REQUEST_READING; | 199 next_state_ = STATE_REQUEST_READING; |
| 200 int bytes_read = 0; | 200 int bytes_read = 0; |
| 201 if (!current_request_->Read(buffer_.get(), kBufferSize, &bytes_read)) { | 201 current_request_->Read(buffer_.get(), kBufferSize, &bytes_read); |
| 202 if (current_request_->status().is_io_pending()) | 202 if (current_request_->status().is_io_pending()) |
| 203 return ERR_IO_PENDING; | 203 return ERR_IO_PENDING; |
| 204 | 204 |
| 205 if (current_request_->status().error() == OK) { | 205 if (bytes_read < 0 || !current_request_->status().is_success()) { |
| 206 // This "should never happen", but if it does the result will be | 206 if (current_request_->status().error() != OK) |
| 207 // an infinite loop. It's not clear how to handle a read failure | 207 return current_request_->status().error(); |
| 208 // without a promise to invoke the callback at some point in the future, | |
| 209 // so the request is failed. | |
| 210 SdchManager::SdchErrorRecovery(SdchManager::DICTIONARY_FETCH_READ_FAILED); | |
| 211 DLOG(FATAL) | |
| 212 << "URLRequest::Read() returned false without IO pending or error!"; | |
| 213 return ERR_FAILED; | |
| 214 } | |
| 215 | 208 |
| 216 return current_request_->status().error(); | 209 // An error with request status of OK should not happen, |
| 210 // but there's enough machinery underneath URLRequest::Read() | |
| 211 // that this routine checks for that case. | |
| 212 return (current_request_->status().status() == | |
| 213 URLRequestStatus::CANCELED) ? ERR_ABORTED : ERR_FAILED; | |
| 217 } | 214 } |
| 218 | 215 |
| 219 if (bytes_read != 0) | 216 if (bytes_read == 0) |
| 217 next_state_ = STATE_REQUEST_COMPLETE; | |
| 218 else | |
| 220 dictionary_.append(buffer_->data(), bytes_read); | 219 dictionary_.append(buffer_->data(), bytes_read); |
| 221 else | |
| 222 next_state_ = STATE_REQUEST_COMPLETE; | |
| 223 | 220 |
| 224 return OK; | 221 return OK; |
| 225 } | 222 } |
| 226 | 223 |
| 227 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { | 224 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { |
| 228 DCHECK(CalledOnValidThread()); | 225 DCHECK(CalledOnValidThread()); |
| 229 | 226 |
| 230 // If the dictionary was successfully fetched, add it to the manager. | 227 // If the dictionary was successfully fetched, add it to the manager. |
| 231 if (rv == OK) | 228 if (rv == OK) |
| 232 dictionary_fetched_callback_.Run(dictionary_, current_request_->url()); | 229 dictionary_fetched_callback_.Run(dictionary_, current_request_->url()); |
|
mmenke
2014/11/17 15:24:58
Should we be recording an error in UMA here?
| |
| 233 | 230 |
| 234 current_request_.reset(); | 231 current_request_.reset(); |
| 235 buffer_ = NULL; | 232 buffer_ = NULL; |
| 236 dictionary_.clear(); | 233 dictionary_.clear(); |
| 237 | 234 |
| 238 next_state_ = STATE_IDLE; | 235 next_state_ = STATE_IDLE; |
| 239 | 236 |
| 240 return OK; | 237 return OK; |
| 241 } | 238 } |
| 242 | 239 |
| 243 } // namespace net | 240 } // namespace net |
| OLD | NEW |