| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/loader/resource_loader.h" | 5 #include "content/browser/loader/resource_loader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 int total_bytes_downloaded() const { return total_bytes_downloaded_; } | 318 int total_bytes_downloaded() const { return total_bytes_downloaded_; } |
| 319 | 319 |
| 320 net::EffectiveConnectionType observed_effective_connection_type() const { | 320 net::EffectiveConnectionType observed_effective_connection_type() const { |
| 321 return observed_effective_connection_type_; | 321 return observed_effective_connection_type_; |
| 322 } | 322 } |
| 323 | 323 |
| 324 void Resume() { | 324 void Resume() { |
| 325 controller()->Resume(); | 325 controller()->Resume(); |
| 326 } | 326 } |
| 327 | 327 |
| 328 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 328 void OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 329 ResourceResponse* response, | 329 ResourceResponse* response, |
| 330 bool* defer) override { | 330 bool* defer_or_cancel) override { |
| 331 redirect_response_ = response; | 331 redirect_response_ = response; |
| 332 received_request_redirected_ = true; | 332 received_request_redirected_ = true; |
| 333 return true; | |
| 334 } | 333 } |
| 335 | 334 |
| 336 bool OnResponseStarted(ResourceResponse* response, bool* defer) override { | 335 void OnResponseStarted(ResourceResponse* response, |
| 336 bool* defer_or_cancel) override { |
| 337 EXPECT_FALSE(response_.get()); | 337 EXPECT_FALSE(response_.get()); |
| 338 response_ = response; | 338 response_ = response; |
| 339 observed_effective_connection_type_ = | 339 observed_effective_connection_type_ = |
| 340 response->head.effective_connection_type; | 340 response->head.effective_connection_type; |
| 341 return true; | |
| 342 } | 341 } |
| 343 | 342 |
| 344 bool OnWillStart(const GURL& url, bool* defer) override { | 343 void OnWillStart(const GURL& url, bool* defer_or_cancel) override { |
| 345 EXPECT_TRUE(start_url_.is_empty()); | 344 EXPECT_TRUE(start_url_.is_empty()); |
| 346 start_url_ = url; | 345 start_url_ = url; |
| 347 if (defer_request_on_will_start_) { | 346 if (defer_request_on_will_start_) { |
| 348 *defer = true; | 347 *defer_or_cancel = true; |
| 349 deferred_run_loop_.Quit(); | 348 deferred_run_loop_.Quit(); |
| 350 } | 349 } |
| 351 return true; | |
| 352 } | 350 } |
| 353 | 351 |
| 354 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 352 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 355 int* buf_size, | 353 int* buf_size, |
| 356 int min_size) override { | 354 int min_size) override { |
| 357 EXPECT_TRUE(expect_reads_); | 355 EXPECT_TRUE(expect_reads_); |
| 358 EXPECT_FALSE(received_on_will_read_); | 356 EXPECT_FALSE(received_on_will_read_); |
| 359 EXPECT_FALSE(received_eof_); | 357 EXPECT_FALSE(received_eof_); |
| 360 EXPECT_FALSE(received_response_completed_); | 358 EXPECT_FALSE(received_response_completed_); |
| 361 | 359 |
| 362 *buf = read_buffer_; | 360 *buf = read_buffer_; |
| 363 *buf_size = kReadBufSize; | 361 *buf_size = kReadBufSize; |
| 364 received_on_will_read_ = true; | 362 received_on_will_read_ = true; |
| 365 return true; | 363 return true; |
| 366 } | 364 } |
| 367 | 365 |
| 368 bool OnReadCompleted(int bytes_read, bool* defer) override { | 366 void OnReadCompleted(int bytes_read, bool* defer_or_cancel) override { |
| 369 EXPECT_TRUE(received_on_will_read_); | 367 EXPECT_TRUE(received_on_will_read_); |
| 370 EXPECT_TRUE(expect_reads_); | 368 EXPECT_TRUE(expect_reads_); |
| 371 EXPECT_FALSE(received_response_completed_); | 369 EXPECT_FALSE(received_response_completed_); |
| 372 | 370 |
| 373 if (bytes_read == 0) { | 371 if (bytes_read == 0) { |
| 374 received_eof_ = true; | 372 received_eof_ = true; |
| 375 if (defer_eof_) { | 373 if (defer_eof_) { |
| 376 defer_eof_ = false; | 374 defer_eof_ = false; |
| 377 *defer = true; | 375 *defer_or_cancel = true; |
| 378 deferred_run_loop_.Quit(); | 376 deferred_run_loop_.Quit(); |
| 379 } | 377 } |
| 380 } | 378 } |
| 381 | 379 |
| 382 // Need another OnWillRead() call before seeing an OnReadCompleted(). | 380 // Need another OnWillRead() call before seeing an OnReadCompleted(). |
| 383 received_on_will_read_ = false; | 381 received_on_will_read_ = false; |
| 384 | 382 |
| 385 return !cancel_on_read_completed_; | 383 if (cancel_on_read_completed_) { |
| 384 *defer_or_cancel = true; |
| 385 controller()->Cancel(); |
| 386 } |
| 386 } | 387 } |
| 387 | 388 |
| 388 void OnResponseCompleted(const net::URLRequestStatus& status, | 389 void OnResponseCompleted(const net::URLRequestStatus& status, |
| 389 bool* defer) override { | 390 bool* defer) override { |
| 390 EXPECT_FALSE(received_response_completed_); | 391 EXPECT_FALSE(received_response_completed_); |
| 391 if (status.is_success() && expect_reads_) | 392 if (status.is_success() && expect_reads_) |
| 392 EXPECT_TRUE(received_eof_); | 393 EXPECT_TRUE(received_eof_); |
| 393 | 394 |
| 394 received_response_completed_ = true; | 395 received_response_completed_ = true; |
| 395 status_ = status; | 396 status_ = status; |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 | 1160 |
| 1160 // Tests that the effective connection type is not set on non-main frame | 1161 // Tests that the effective connection type is not set on non-main frame |
| 1161 // requests. | 1162 // requests. |
| 1162 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) { | 1163 TEST_F(EffectiveConnectionTypeResourceLoaderTest, DoesNotBelongToMainFrame) { |
| 1163 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false, | 1164 VerifyEffectiveConnectionType(RESOURCE_TYPE_OBJECT, false, |
| 1164 net::EFFECTIVE_CONNECTION_TYPE_3G, | 1165 net::EFFECTIVE_CONNECTION_TYPE_3G, |
| 1165 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); | 1166 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN); |
| 1166 } | 1167 } |
| 1167 | 1168 |
| 1168 } // namespace content | 1169 } // namespace content |
| OLD | NEW |