| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_scheduler.h" | 5 #include "content/browser/loader/resource_scheduler.h" |
| 6 | 6 |
| 7 #include <string> |
| 8 |
| 7 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/timer/mock_timer.h" | 13 #include "base/timer/mock_timer.h" |
| 12 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 16 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 15 #include "content/browser/loader/resource_message_filter.h" | 17 #include "content/browser/loader/resource_message_filter.h" |
| 16 #include "content/browser/loader/resource_request_info_impl.h" | 18 #include "content/browser/loader/resource_request_info_impl.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 | 423 |
| 422 // Throw in one high priority request to make sure that's not a factor. | 424 // Throw in one high priority request to make sure that's not a factor. |
| 423 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | 425 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
| 424 EXPECT_TRUE(high->started()); | 426 EXPECT_TRUE(high->started()); |
| 425 | 427 |
| 426 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. | 428 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. |
| 427 const int kMaxNumDelayableRequestsPerHost = 6; | 429 const int kMaxNumDelayableRequestsPerHost = 6; |
| 428 ScopedVector<TestRequest> lows_singlehost; | 430 ScopedVector<TestRequest> lows_singlehost; |
| 429 // Queue up to the per-host limit (we subtract the current high-pri request). | 431 // Queue up to the per-host limit (we subtract the current high-pri request). |
| 430 for (int i = 0; i < kMaxNumDelayableRequestsPerHost - 1; ++i) { | 432 for (int i = 0; i < kMaxNumDelayableRequestsPerHost - 1; ++i) { |
| 431 string url = "http://host/low" + base::IntToString(i); | 433 std::string url = "http://host/low" + base::IntToString(i); |
| 432 lows_singlehost.push_back(NewRequest(url.c_str(), net::LOWEST)); | 434 lows_singlehost.push_back(NewRequest(url.c_str(), net::LOWEST)); |
| 433 EXPECT_TRUE(lows_singlehost[i]->started()); | 435 EXPECT_TRUE(lows_singlehost[i]->started()); |
| 434 } | 436 } |
| 435 | 437 |
| 436 scoped_ptr<TestRequest> second_last_singlehost(NewRequest("http://host/last", | 438 scoped_ptr<TestRequest> second_last_singlehost(NewRequest("http://host/last", |
| 437 net::LOWEST)); | 439 net::LOWEST)); |
| 438 scoped_ptr<TestRequest> last_singlehost(NewRequest("http://host/s_last", | 440 scoped_ptr<TestRequest> last_singlehost(NewRequest("http://host/s_last", |
| 439 net::LOWEST)); | 441 net::LOWEST)); |
| 440 | 442 |
| 441 EXPECT_FALSE(second_last_singlehost->started()); | 443 EXPECT_FALSE(second_last_singlehost->started()); |
| 442 high.reset(); | 444 high.reset(); |
| 443 EXPECT_TRUE(second_last_singlehost->started()); | 445 EXPECT_TRUE(second_last_singlehost->started()); |
| 444 EXPECT_FALSE(last_singlehost->started()); | 446 EXPECT_FALSE(last_singlehost->started()); |
| 445 lows_singlehost.erase(lows_singlehost.begin()); | 447 lows_singlehost.erase(lows_singlehost.begin()); |
| 446 EXPECT_TRUE(last_singlehost->started()); | 448 EXPECT_TRUE(last_singlehost->started()); |
| 447 | 449 |
| 448 // Queue more requests from different hosts until we reach the total limit. | 450 // Queue more requests from different hosts until we reach the total limit. |
| 449 int expected_slots_left = | 451 int expected_slots_left = |
| 450 kMaxNumDelayableRequestsPerClient - kMaxNumDelayableRequestsPerHost; | 452 kMaxNumDelayableRequestsPerClient - kMaxNumDelayableRequestsPerHost; |
| 451 EXPECT_GT(expected_slots_left, 0); | 453 EXPECT_GT(expected_slots_left, 0); |
| 452 ScopedVector<TestRequest> lows_differenthosts; | 454 ScopedVector<TestRequest> lows_differenthosts; |
| 453 for (int i = 0; i < expected_slots_left; ++i) { | 455 for (int i = 0; i < expected_slots_left; ++i) { |
| 454 string url = "http://host" + base::IntToString(i) + "/low"; | 456 std::string url = "http://host" + base::IntToString(i) + "/low"; |
| 455 lows_differenthosts.push_back(NewRequest(url.c_str(), net::LOWEST)); | 457 lows_differenthosts.push_back(NewRequest(url.c_str(), net::LOWEST)); |
| 456 EXPECT_TRUE(lows_differenthosts[i]->started()); | 458 EXPECT_TRUE(lows_differenthosts[i]->started()); |
| 457 } | 459 } |
| 458 | 460 |
| 459 scoped_ptr<TestRequest> last_differenthost(NewRequest("http://host_new/last", | 461 scoped_ptr<TestRequest> last_differenthost(NewRequest("http://host_new/last", |
| 460 net::LOWEST)); | 462 net::LOWEST)); |
| 461 EXPECT_FALSE(last_differenthost->started()); | 463 EXPECT_FALSE(last_differenthost->started()); |
| 462 } | 464 } |
| 463 | 465 |
| 464 TEST_F(ResourceSchedulerTest, RaisePriorityAndStart) { | 466 TEST_F(ResourceSchedulerTest, RaisePriorityAndStart) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 483 EXPECT_FALSE(request->started()); | 485 EXPECT_FALSE(request->started()); |
| 484 EXPECT_FALSE(idle->started()); | 486 EXPECT_FALSE(idle->started()); |
| 485 | 487 |
| 486 ChangeRequestPriority(request.get(), net::LOWEST); | 488 ChangeRequestPriority(request.get(), net::LOWEST); |
| 487 EXPECT_FALSE(request->started()); | 489 EXPECT_FALSE(request->started()); |
| 488 EXPECT_FALSE(idle->started()); | 490 EXPECT_FALSE(idle->started()); |
| 489 | 491 |
| 490 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. | 492 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. |
| 491 ScopedVector<TestRequest> lows; | 493 ScopedVector<TestRequest> lows; |
| 492 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { | 494 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { |
| 493 string url = "http://host/low" + base::IntToString(i); | 495 std::string url = "http://host/low" + base::IntToString(i); |
| 494 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); | 496 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); |
| 495 } | 497 } |
| 496 | 498 |
| 497 scheduler_.OnWillInsertBody(kChildId, kRouteId); | 499 scheduler_.OnWillInsertBody(kChildId, kRouteId); |
| 498 high.reset(); | 500 high.reset(); |
| 499 | 501 |
| 500 EXPECT_TRUE(request->started()); | 502 EXPECT_TRUE(request->started()); |
| 501 EXPECT_FALSE(idle->started()); | 503 EXPECT_FALSE(idle->started()); |
| 502 } | 504 } |
| 503 | 505 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 514 ChangeRequestPriority(request.get(), net::IDLE); | 516 ChangeRequestPriority(request.get(), net::IDLE); |
| 515 EXPECT_FALSE(request->started()); | 517 EXPECT_FALSE(request->started()); |
| 516 EXPECT_FALSE(idle->started()); | 518 EXPECT_FALSE(idle->started()); |
| 517 | 519 |
| 518 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. | 520 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. |
| 519 // 2 fewer filler requests: 1 for the "low" dummy at the start, and 1 for the | 521 // 2 fewer filler requests: 1 for the "low" dummy at the start, and 1 for the |
| 520 // one at the end, which will be tested. | 522 // one at the end, which will be tested. |
| 521 const int kNumFillerRequests = kMaxNumDelayableRequestsPerClient - 2; | 523 const int kNumFillerRequests = kMaxNumDelayableRequestsPerClient - 2; |
| 522 ScopedVector<TestRequest> lows; | 524 ScopedVector<TestRequest> lows; |
| 523 for (int i = 0; i < kNumFillerRequests; ++i) { | 525 for (int i = 0; i < kNumFillerRequests; ++i) { |
| 524 string url = "http://host" + base::IntToString(i) + "/low"; | 526 std::string url = "http://host" + base::IntToString(i) + "/low"; |
| 525 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); | 527 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); |
| 526 } | 528 } |
| 527 | 529 |
| 528 scheduler_.OnWillInsertBody(kChildId, kRouteId); | 530 scheduler_.OnWillInsertBody(kChildId, kRouteId); |
| 529 high.reset(); | 531 high.reset(); |
| 530 | 532 |
| 531 EXPECT_FALSE(request->started()); | 533 EXPECT_FALSE(request->started()); |
| 532 EXPECT_TRUE(idle->started()); | 534 EXPECT_TRUE(idle->started()); |
| 533 } | 535 } |
| 534 | 536 |
| 535 TEST_F(ResourceSchedulerTest, ReprioritizedRequestGoesToBackOfQueue) { | 537 TEST_F(ResourceSchedulerTest, ReprioritizedRequestGoesToBackOfQueue) { |
| 536 // Dummies to enforce scheduling. | 538 // Dummies to enforce scheduling. |
| 537 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | 539 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
| 538 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | 540 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
| 539 | 541 |
| 540 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST)); | 542 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::LOWEST)); |
| 541 scoped_ptr<TestRequest> idle(NewRequest("http://host/idle", net::IDLE)); | 543 scoped_ptr<TestRequest> idle(NewRequest("http://host/idle", net::IDLE)); |
| 542 EXPECT_FALSE(request->started()); | 544 EXPECT_FALSE(request->started()); |
| 543 EXPECT_FALSE(idle->started()); | 545 EXPECT_FALSE(idle->started()); |
| 544 | 546 |
| 545 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. | 547 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. |
| 546 ScopedVector<TestRequest> lows; | 548 ScopedVector<TestRequest> lows; |
| 547 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { | 549 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { |
| 548 string url = "http://host/low" + base::IntToString(i); | 550 std::string url = "http://host/low" + base::IntToString(i); |
| 549 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); | 551 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); |
| 550 } | 552 } |
| 551 | 553 |
| 552 ChangeRequestPriority(request.get(), net::IDLE); | 554 ChangeRequestPriority(request.get(), net::IDLE); |
| 553 EXPECT_FALSE(request->started()); | 555 EXPECT_FALSE(request->started()); |
| 554 EXPECT_FALSE(idle->started()); | 556 EXPECT_FALSE(idle->started()); |
| 555 | 557 |
| 556 ChangeRequestPriority(request.get(), net::LOWEST); | 558 ChangeRequestPriority(request.get(), net::LOWEST); |
| 557 EXPECT_FALSE(request->started()); | 559 EXPECT_FALSE(request->started()); |
| 558 EXPECT_FALSE(idle->started()); | 560 EXPECT_FALSE(idle->started()); |
| 559 | 561 |
| 560 scheduler_.OnWillInsertBody(kChildId, kRouteId); | 562 scheduler_.OnWillInsertBody(kChildId, kRouteId); |
| 561 EXPECT_FALSE(request->started()); | 563 EXPECT_FALSE(request->started()); |
| 562 EXPECT_FALSE(idle->started()); | 564 EXPECT_FALSE(idle->started()); |
| 563 } | 565 } |
| 564 | 566 |
| 565 TEST_F(ResourceSchedulerTest, HigherIntraPriorityGoesToFrontOfQueue) { | 567 TEST_F(ResourceSchedulerTest, HigherIntraPriorityGoesToFrontOfQueue) { |
| 566 // Dummies to enforce scheduling. | 568 // Dummies to enforce scheduling. |
| 567 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); | 569 scoped_ptr<TestRequest> high(NewRequest("http://host/high", net::HIGHEST)); |
| 568 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); | 570 scoped_ptr<TestRequest> low(NewRequest("http://host/low", net::LOWEST)); |
| 569 | 571 |
| 570 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. | 572 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. |
| 571 ScopedVector<TestRequest> lows; | 573 ScopedVector<TestRequest> lows; |
| 572 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { | 574 for (int i = 0; i < kMaxNumDelayableRequestsPerClient; ++i) { |
| 573 string url = "http://host/low" + base::IntToString(i); | 575 std::string url = "http://host/low" + base::IntToString(i); |
| 574 lows.push_back(NewRequest(url.c_str(), net::IDLE)); | 576 lows.push_back(NewRequest(url.c_str(), net::IDLE)); |
| 575 } | 577 } |
| 576 | 578 |
| 577 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::IDLE)); | 579 scoped_ptr<TestRequest> request(NewRequest("http://host/req", net::IDLE)); |
| 578 EXPECT_FALSE(request->started()); | 580 EXPECT_FALSE(request->started()); |
| 579 | 581 |
| 580 ChangeRequestPriority(request.get(), net::IDLE, 1); | 582 ChangeRequestPriority(request.get(), net::IDLE, 1); |
| 581 EXPECT_FALSE(request->started()); | 583 EXPECT_FALSE(request->started()); |
| 582 | 584 |
| 583 scheduler_.OnWillInsertBody(kChildId, kRouteId); | 585 scheduler_.OnWillInsertBody(kChildId, kRouteId); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 645 |
| 644 TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) { | 646 TEST_F(ResourceSchedulerTest, NewSpdyHostInDelayableRequests) { |
| 645 scheduler_.OnWillInsertBody(kChildId, kRouteId); | 647 scheduler_.OnWillInsertBody(kChildId, kRouteId); |
| 646 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. | 648 const int kMaxNumDelayableRequestsPerClient = 10; // Should match the .cc. |
| 647 | 649 |
| 648 scoped_ptr<TestRequest> low1_spdy( | 650 scoped_ptr<TestRequest> low1_spdy( |
| 649 NewRequest("http://spdyhost1:8080/low", net::LOWEST)); | 651 NewRequest("http://spdyhost1:8080/low", net::LOWEST)); |
| 650 // Cancel a request after we learn the server supports SPDY. | 652 // Cancel a request after we learn the server supports SPDY. |
| 651 ScopedVector<TestRequest> lows; | 653 ScopedVector<TestRequest> lows; |
| 652 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { | 654 for (int i = 0; i < kMaxNumDelayableRequestsPerClient - 1; ++i) { |
| 653 string url = "http://host" + base::IntToString(i) + "/low"; | 655 std::string url = "http://host" + base::IntToString(i) + "/low"; |
| 654 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); | 656 lows.push_back(NewRequest(url.c_str(), net::LOWEST)); |
| 655 } | 657 } |
| 656 scoped_ptr<TestRequest> low1(NewRequest("http://host/low", net::LOWEST)); | 658 scoped_ptr<TestRequest> low1(NewRequest("http://host/low", net::LOWEST)); |
| 657 EXPECT_FALSE(low1->started()); | 659 EXPECT_FALSE(low1->started()); |
| 658 http_server_properties_.SetSupportsSpdy( | 660 http_server_properties_.SetSupportsSpdy( |
| 659 net::HostPortPair("spdyhost1", 8080), true); | 661 net::HostPortPair("spdyhost1", 8080), true); |
| 660 low1_spdy.reset(); | 662 low1_spdy.reset(); |
| 661 EXPECT_TRUE(low1->started()); | 663 EXPECT_TRUE(low1->started()); |
| 662 | 664 |
| 663 low1.reset(); | 665 low1.reset(); |
| (...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2205 web_contents_2.reset(); | 2207 web_contents_2.reset(); |
| 2206 base::RunLoop().RunUntilIdle(); | 2208 base::RunLoop().RunUntilIdle(); |
| 2207 | 2209 |
| 2208 browser_context.reset(); | 2210 browser_context.reset(); |
| 2209 render_process_host_factory.reset(); | 2211 render_process_host_factory.reset(); |
| 2210 } | 2212 } |
| 2211 | 2213 |
| 2212 } // unnamed namespace | 2214 } // unnamed namespace |
| 2213 | 2215 |
| 2214 } // namespace content | 2216 } // namespace content |
| OLD | NEW |