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/base/sdch_dictionary_fetcher.h" | 5 #include "net/base/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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 if (!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 DCHECK_NE(current_request_->status().error(), OK); | 206 DCHECK_NE(current_request_->status().error(), OK); |
|
Ryan Hamilton
2014/09/23 21:38:38
Technically, the style guide prohibits "handling"
| |
| 207 if (current_request_->status().error() == OK) { | |
| 208 // This "should never happen", but if it does the result will be | |
| 209 // an infinite loop. It's not clear how to handle a read failure | |
| 210 // without a promise to invoke the callback at some point in the future, | |
| 211 // so the request is failed. | |
| 212 SdchManager::SdchErrorRecovery(SdchManager::DICTIONARY_FETCH_READ_FAILED); | |
| 213 return ERR_FAILED; | |
| 214 } | |
| 207 | 215 |
| 208 return current_request_->status().error(); | 216 return current_request_->status().error(); |
| 209 } | 217 } |
| 210 | 218 |
| 211 if (bytes_read != 0) | 219 if (bytes_read != 0) |
| 212 dictionary_.append(buffer_->data(), bytes_read); | 220 dictionary_.append(buffer_->data(), bytes_read); |
| 213 else | 221 else |
| 214 next_state_ = STATE_REQUEST_COMPLETE; | 222 next_state_ = STATE_REQUEST_COMPLETE; |
| 215 | 223 |
| 216 return OK; | 224 return OK; |
| 217 } | 225 } |
| 218 | 226 |
| 219 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { | 227 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { |
| 220 DCHECK(CalledOnValidThread()); | 228 DCHECK(CalledOnValidThread()); |
| 221 | 229 |
| 222 // If the dictionary was successfully fetched, add it to the manager. | 230 // If the dictionary was successfully fetched, add it to the manager. |
| 223 if (rv == OK) | 231 if (rv == OK) |
| 224 consumer_->AddSdchDictionary(dictionary_, current_request_->url()); | 232 consumer_->AddSdchDictionary(dictionary_, current_request_->url()); |
| 225 | 233 |
| 226 current_request_.reset(); | 234 current_request_.reset(); |
| 227 buffer_ = NULL; | 235 buffer_ = NULL; |
| 228 dictionary_.clear(); | 236 dictionary_.clear(); |
| 229 | 237 |
| 230 next_state_ = STATE_IDLE; | 238 next_state_ = STATE_IDLE; |
| 231 | 239 |
| 232 return OK; | 240 return OK; |
| 233 } | 241 } |
| 234 | 242 |
| 235 } // namespace net | 243 } // namespace net |
| OLD | NEW |