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 return current_request_->status().error(); |
mmenke
2014/11/13 21:55:05
Hrm... if it's possible for is_success() is true,
mmenke
2014/11/13 21:55:05
Should have a comment by the old enum that it's ob
Randy Smith (Not in Mondays)
2014/11/13 22:05:21
Whoops, sorry, updated histograms.xml, but not the
Randy Smith (Not in Mondays)
2014/11/13 22:05:22
It's a fair concern, but ResourceLoader has the sa
mmenke
2014/11/13 22:23:43
I suggest we channel AsyncResourceHandler here (ht
Randy Smith (Not in Mondays)
2014/11/15 21:25:30
Sounds good. I've tried to duplicate that logic's
| |
207 // an infinite loop. It's not clear how to handle a read failure | |
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 | 207 |
216 return current_request_->status().error(); | 208 if (bytes_read > 0) |
217 } | |
218 | |
219 if (bytes_read != 0) | |
220 dictionary_.append(buffer_->data(), bytes_read); | 209 dictionary_.append(buffer_->data(), bytes_read); |
221 else | 210 else |
222 next_state_ = STATE_REQUEST_COMPLETE; | 211 next_state_ = STATE_REQUEST_COMPLETE; |
223 | 212 |
224 return OK; | 213 return OK; |
225 } | 214 } |
226 | 215 |
227 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { | 216 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { |
228 DCHECK(CalledOnValidThread()); | 217 DCHECK(CalledOnValidThread()); |
229 | 218 |
230 // If the dictionary was successfully fetched, add it to the manager. | 219 // If the dictionary was successfully fetched, add it to the manager. |
231 if (rv == OK) | 220 if (rv == OK) |
232 dictionary_fetched_callback_.Run(dictionary_, current_request_->url()); | 221 dictionary_fetched_callback_.Run(dictionary_, current_request_->url()); |
233 | 222 |
234 current_request_.reset(); | 223 current_request_.reset(); |
235 buffer_ = NULL; | 224 buffer_ = NULL; |
236 dictionary_.clear(); | 225 dictionary_.clear(); |
237 | 226 |
238 next_state_ = STATE_IDLE; | 227 next_state_ = STATE_IDLE; |
239 | 228 |
240 return OK; | 229 return OK; |
241 } | 230 } |
242 | 231 |
243 } // namespace net | 232 } // namespace net |
OLD | NEW |