Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: net/url_request/sdch_dictionary_fetcher.cc

Issue 2265873002: Adjust callers and networking delegates in net/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
Patch Set: rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <queue> 8 #include <queue>
9 #include <set> 9 #include <set>
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 namespace net { 26 namespace net {
27 27
28 namespace { 28 namespace {
29 29
30 const int kBufferSize = 4096; 30 const int kBufferSize = 4096;
31 31
32 // Map the bytes_read result from a read attempt and a URLRequest's 32 // Map the bytes_read result from a read attempt and a URLRequest's
33 // status into a single net return value. 33 // status into a single net return value.
34 int GetReadResult(int bytes_read, const URLRequest* request) { 34 int GetReadResult(int bytes_read, const URLRequest* request) {
35 int rv = request->status().error(); 35 DCHECK_NE(ERR_IO_PENDING, bytes_read);
36 if (request->status().is_success() && bytes_read < 0) { 36
37 int rv = bytes_read;
38 if (rv < 0) {
37 rv = ERR_FAILED; 39 rv = ERR_FAILED;
38 request->net_log().AddEventWithNetErrorCode( 40 request->net_log().AddEventWithNetErrorCode(
39 NetLog::TYPE_SDCH_DICTIONARY_FETCH_IMPLIED_ERROR, rv); 41 NetLog::TYPE_SDCH_DICTIONARY_FETCH_IMPLIED_ERROR, rv);
40 } 42 }
41 43
42 if (rv == OK) 44 if (rv == OK)
43 rv = bytes_read; 45 rv = bytes_read;
44 46
45 return rv; 47 return rv;
46 } 48 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 URLRequest* request, 150 URLRequest* request,
149 const RedirectInfo& redirect_info, 151 const RedirectInfo& redirect_info,
150 bool* defer_redirect) { 152 bool* defer_redirect) {
151 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_PENDING); 153 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_PENDING);
152 154
153 next_state_ = STATE_RECEIVED_REDIRECT; 155 next_state_ = STATE_RECEIVED_REDIRECT;
154 156
155 DoLoop(OK); 157 DoLoop(OK);
156 } 158 }
157 159
158 void SdchDictionaryFetcher::OnResponseStarted(URLRequest* request) { 160 void SdchDictionaryFetcher::OnResponseStarted(URLRequest* request,
161 int net_error) {
159 DCHECK(CalledOnValidThread()); 162 DCHECK(CalledOnValidThread());
160 DCHECK_EQ(request, current_request_.get()); 163 DCHECK_EQ(request, current_request_.get());
161 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_PENDING); 164 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_PENDING);
162 DCHECK(!in_loop_); 165 DCHECK(!in_loop_);
166 DCHECK_NE(ERR_IO_PENDING, net_error);
163 167
164 // Confirm that the response isn't a stale read from the cache (as 168 // Confirm that the response isn't a stale read from the cache (as
165 // may happen in the reload case). If the response was not retrieved over 169 // may happen in the reload case). If the response was not retrieved over
166 // HTTP, it is presumed to be fresh. 170 // HTTP, it is presumed to be fresh.
167 HttpResponseHeaders* response_headers = request->response_headers(); 171 HttpResponseHeaders* response_headers = request->response_headers();
168 int result = request->status().error(); 172 if (net_error == OK && response_headers) {
169 if (result == OK && response_headers) {
170 ValidationType validation_type = response_headers->RequiresValidation( 173 ValidationType validation_type = response_headers->RequiresValidation(
171 request->response_info().request_time, 174 request->response_info().request_time,
172 request->response_info().response_time, base::Time::Now()); 175 request->response_info().response_time, base::Time::Now());
173 // TODO(rdsmith): Maybe handle VALIDATION_ASYNCHRONOUS by queueing 176 // TODO(rdsmith): Maybe handle VALIDATION_ASYNCHRONOUS by queueing
174 // a non-reload request for the dictionary. 177 // a non-reload request for the dictionary.
175 if (validation_type != VALIDATION_NONE) 178 if (validation_type != VALIDATION_NONE)
176 result = ERR_FAILED; 179 net_error = ERR_FAILED;
177 } 180 }
178 181
179 DoLoop(result); 182 DoLoop(net_error);
180 } 183 }
181 184
182 void SdchDictionaryFetcher::OnReadCompleted(URLRequest* request, 185 void SdchDictionaryFetcher::OnReadCompleted(URLRequest* request,
183 int bytes_read) { 186 int bytes_read) {
184 DCHECK(CalledOnValidThread()); 187 DCHECK(CalledOnValidThread());
185 DCHECK_EQ(request, current_request_.get()); 188 DCHECK_EQ(request, current_request_.get());
186 DCHECK_EQ(next_state_, STATE_READ_BODY_COMPLETE); 189 DCHECK_EQ(next_state_, STATE_READ_BODY_COMPLETE);
187 DCHECK(!in_loop_); 190 DCHECK(!in_loop_);
191 DCHECK_NE(ERR_IO_PENDING, bytes_read);
188 192
189 DoLoop(GetReadResult(bytes_read, current_request_.get())); 193 DoLoop(GetReadResult(bytes_read, current_request_.get()));
190 } 194 }
191 195
192 bool SdchDictionaryFetcher::ScheduleInternal( 196 bool SdchDictionaryFetcher::ScheduleInternal(
193 const GURL& dictionary_url, 197 const GURL& dictionary_url,
194 bool reload, 198 bool reload,
195 const OnDictionaryFetchedCallback& callback) { 199 const OnDictionaryFetchedCallback& callback) {
196 DCHECK(CalledOnValidThread()); 200 DCHECK(CalledOnValidThread());
197 201
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 DCHECK(CalledOnValidThread()); 326 DCHECK(CalledOnValidThread());
323 327
324 // If there's been an error, abort the current request. 328 // If there's been an error, abort the current request.
325 if (rv != OK) { 329 if (rv != OK) {
326 ResetRequest(); 330 ResetRequest();
327 next_state_ = STATE_SEND_REQUEST; 331 next_state_ = STATE_SEND_REQUEST;
328 return OK; 332 return OK;
329 } 333 }
330 334
331 next_state_ = STATE_READ_BODY_COMPLETE; 335 next_state_ = STATE_READ_BODY_COMPLETE;
332 int bytes_read = 0; 336 int bytes_read = current_request_->Read(buffer_.get(), kBufferSize);
333 current_request_->Read(buffer_.get(), kBufferSize, &bytes_read); 337 if (bytes_read == ERR_IO_PENDING)
334 if (current_request_->status().is_io_pending())
335 return ERR_IO_PENDING; 338 return ERR_IO_PENDING;
336 339
337 return GetReadResult(bytes_read, current_request_.get()); 340 return GetReadResult(bytes_read, current_request_.get());
338 } 341 }
339 342
340 int SdchDictionaryFetcher::DoReadBodyComplete(int rv) { 343 int SdchDictionaryFetcher::DoReadBodyComplete(int rv) {
341 DCHECK(CalledOnValidThread()); 344 DCHECK(CalledOnValidThread());
342 345
343 // An error; abort the current request. 346 // An error; abort the current request.
344 if (rv < 0) { 347 if (rv < 0) {
345 ResetRequest(); 348 ResetRequest();
346 next_state_ = STATE_SEND_REQUEST; 349 next_state_ = STATE_SEND_REQUEST;
347 return OK; 350 return OK;
348 } 351 }
349 352
350 DCHECK(current_request_->status().is_success()); 353 DCHECK_GE(rv, 0);
351 354
352 // Data; append to the dictionary and look for more data. 355 // Data; append to the dictionary and look for more data.
353 if (rv > 0) { 356 if (rv > 0) {
354 dictionary_->append(buffer_->data(), rv); 357 dictionary_->append(buffer_->data(), rv);
355 next_state_ = STATE_READ_BODY; 358 next_state_ = STATE_READ_BODY;
356 return OK; 359 return OK;
357 } 360 }
358 361
359 // End of file; complete the request. 362 // End of file; complete the request.
360 next_state_ = STATE_REQUEST_COMPLETE; 363 next_state_ = STATE_REQUEST_COMPLETE;
361 return OK; 364 return OK;
362 } 365 }
363 366
364 int SdchDictionaryFetcher::DoCompleteRequest(int rv) { 367 int SdchDictionaryFetcher::DoCompleteRequest(int rv) {
365 DCHECK(CalledOnValidThread()); 368 DCHECK(CalledOnValidThread());
366 369
367 // If the dictionary was successfully fetched, add it to the manager. 370 // If the dictionary was successfully fetched, add it to the manager.
368 if (rv == OK) { 371 if (rv == OK) {
369 current_callback_.Run(*dictionary_, current_request_->url(), 372 current_callback_.Run(*dictionary_, current_request_->url(),
370 current_request_->net_log(), 373 current_request_->net_log(),
371 current_request_->was_cached()); 374 current_request_->was_cached());
372 } 375 }
373 376
374 ResetRequest(); 377 ResetRequest();
375 next_state_ = STATE_SEND_REQUEST; 378 next_state_ = STATE_SEND_REQUEST;
376 return OK; 379 return OK;
377 } 380 }
378 381
379 } // namespace net 382 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698