| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 // ResourceThrottle implementation: | 665 // ResourceThrottle implementation: |
| 666 void WillStartRequest(bool* defer) override { | 666 void WillStartRequest(bool* defer) override { |
| 667 ASSERT_EQ(NULL, active_throttle_); | 667 ASSERT_EQ(NULL, active_throttle_); |
| 668 if (flags_ & DEFER_STARTING_REQUEST) { | 668 if (flags_ & DEFER_STARTING_REQUEST) { |
| 669 active_throttle_ = this; | 669 active_throttle_ = this; |
| 670 *defer = true; | 670 *defer = true; |
| 671 } | 671 } |
| 672 | 672 |
| 673 if (flags_ & CANCEL_BEFORE_START) { | 673 if (flags_ & CANCEL_BEFORE_START) { |
| 674 if (error_code_for_cancellation_ == USE_DEFAULT_CANCEL_ERROR_CODE) { | 674 if (error_code_for_cancellation_ == USE_DEFAULT_CANCEL_ERROR_CODE) { |
| 675 controller()->Cancel(); | 675 Cancel(); |
| 676 } else { | 676 } else { |
| 677 controller()->CancelWithError(error_code_for_cancellation_); | 677 CancelWithError(error_code_for_cancellation_); |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 } | 680 } |
| 681 | 681 |
| 682 void WillProcessResponse(bool* defer) override { | 682 void WillProcessResponse(bool* defer) override { |
| 683 ASSERT_EQ(NULL, active_throttle_); | 683 ASSERT_EQ(NULL, active_throttle_); |
| 684 if (flags_ & DEFER_PROCESSING_RESPONSE) { | 684 if (flags_ & DEFER_PROCESSING_RESPONSE) { |
| 685 active_throttle_ = this; | 685 active_throttle_ = this; |
| 686 *defer = true; | 686 *defer = true; |
| 687 } | 687 } |
| 688 | 688 |
| 689 if (flags_ & CANCEL_PROCESSING_RESPONSE) { | 689 if (flags_ & CANCEL_PROCESSING_RESPONSE) { |
| 690 if (error_code_for_cancellation_ == USE_DEFAULT_CANCEL_ERROR_CODE) { | 690 if (error_code_for_cancellation_ == USE_DEFAULT_CANCEL_ERROR_CODE) { |
| 691 controller()->Cancel(); | 691 Cancel(); |
| 692 } else { | 692 } else { |
| 693 controller()->CancelWithError(error_code_for_cancellation_); | 693 CancelWithError(error_code_for_cancellation_); |
| 694 } | 694 } |
| 695 } | 695 } |
| 696 } | 696 } |
| 697 | 697 |
| 698 const char* GetNameForLogging() const override { | 698 const char* GetNameForLogging() const override { |
| 699 return "GenericResourceThrottle"; | 699 return "GenericResourceThrottle"; |
| 700 } | 700 } |
| 701 | 701 |
| 702 void Resume() { | 702 void AssertAndResume() { |
| 703 ASSERT_TRUE(this == active_throttle_); | 703 ASSERT_TRUE(this == active_throttle_); |
| 704 active_throttle_ = NULL; | 704 active_throttle_ = NULL; |
| 705 controller()->Resume(); | 705 ResourceThrottle::Resume(); |
| 706 } | 706 } |
| 707 | 707 |
| 708 static GenericResourceThrottle* active_throttle() { | 708 static GenericResourceThrottle* active_throttle() { |
| 709 return active_throttle_; | 709 return active_throttle_; |
| 710 } | 710 } |
| 711 | 711 |
| 712 bool MustProcessResponseBeforeReadingBody() override { | 712 bool MustProcessResponseBeforeReadingBody() override { |
| 713 return flags_ & MUST_NOT_CACHE_BODY; | 713 return flags_ & MUST_NOT_CACHE_BODY; |
| 714 } | 714 } |
| 715 | 715 |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 // However, it is still throttled because the defer happened above the | 1772 // However, it is still throttled because the defer happened above the |
| 1773 // DetachableResourceHandler. | 1773 // DetachableResourceHandler. |
| 1774 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1774 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1775 base::RunLoop().RunUntilIdle(); | 1775 base::RunLoop().RunUntilIdle(); |
| 1776 EXPECT_FALSE(was_deleted); | 1776 EXPECT_FALSE(was_deleted); |
| 1777 | 1777 |
| 1778 // Resume the request. | 1778 // Resume the request. |
| 1779 GenericResourceThrottle* throttle = | 1779 GenericResourceThrottle* throttle = |
| 1780 GenericResourceThrottle::active_throttle(); | 1780 GenericResourceThrottle::active_throttle(); |
| 1781 ASSERT_TRUE(throttle); | 1781 ASSERT_TRUE(throttle); |
| 1782 throttle->Resume(); | 1782 throttle->AssertAndResume(); |
| 1783 | 1783 |
| 1784 // Now, the request completes. | 1784 // Now, the request completes. |
| 1785 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1785 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1786 base::RunLoop().RunUntilIdle(); | 1786 base::RunLoop().RunUntilIdle(); |
| 1787 EXPECT_TRUE(was_deleted); | 1787 EXPECT_TRUE(was_deleted); |
| 1788 EXPECT_EQ(1, network_delegate()->completed_requests()); | 1788 EXPECT_EQ(1, network_delegate()->completed_requests()); |
| 1789 EXPECT_EQ(0, network_delegate()->canceled_requests()); | 1789 EXPECT_EQ(0, network_delegate()->canceled_requests()); |
| 1790 EXPECT_EQ(0, network_delegate()->error_count()); | 1790 EXPECT_EQ(0, network_delegate()->error_count()); |
| 1791 } | 1791 } |
| 1792 | 1792 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 TestResourceDispatcherHostDelegate delegate; | 1836 TestResourceDispatcherHostDelegate delegate; |
| 1837 delegate.set_flags(DEFER_STARTING_REQUEST); | 1837 delegate.set_flags(DEFER_STARTING_REQUEST); |
| 1838 delegate.set_create_two_throttles(true); | 1838 delegate.set_create_two_throttles(true); |
| 1839 host_.SetDelegate(&delegate); | 1839 host_.SetDelegate(&delegate); |
| 1840 | 1840 |
| 1841 // Make sure the first throttle blocked the request, and then resume. | 1841 // Make sure the first throttle blocked the request, and then resume. |
| 1842 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); | 1842 MakeTestRequest(0, 1, net::URLRequestTestJob::test_url_1()); |
| 1843 GenericResourceThrottle* first_throttle = | 1843 GenericResourceThrottle* first_throttle = |
| 1844 GenericResourceThrottle::active_throttle(); | 1844 GenericResourceThrottle::active_throttle(); |
| 1845 ASSERT_TRUE(first_throttle); | 1845 ASSERT_TRUE(first_throttle); |
| 1846 first_throttle->Resume(); | 1846 first_throttle->AssertAndResume(); |
| 1847 | 1847 |
| 1848 // Make sure the second throttle blocked the request, and then resume. | 1848 // Make sure the second throttle blocked the request, and then resume. |
| 1849 ASSERT_TRUE(GenericResourceThrottle::active_throttle()); | 1849 ASSERT_TRUE(GenericResourceThrottle::active_throttle()); |
| 1850 ASSERT_NE(first_throttle, GenericResourceThrottle::active_throttle()); | 1850 ASSERT_NE(first_throttle, GenericResourceThrottle::active_throttle()); |
| 1851 GenericResourceThrottle::active_throttle()->Resume(); | 1851 GenericResourceThrottle::active_throttle()->AssertAndResume(); |
| 1852 | 1852 |
| 1853 ASSERT_FALSE(GenericResourceThrottle::active_throttle()); | 1853 ASSERT_FALSE(GenericResourceThrottle::active_throttle()); |
| 1854 | 1854 |
| 1855 // The request is started asynchronously. | 1855 // The request is started asynchronously. |
| 1856 base::RunLoop().RunUntilIdle(); | 1856 base::RunLoop().RunUntilIdle(); |
| 1857 | 1857 |
| 1858 // Flush all the pending requests. | 1858 // Flush all the pending requests. |
| 1859 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} | 1859 while (net::URLRequestTestJob::ProcessOnePendingMessage()) {} |
| 1860 | 1860 |
| 1861 EXPECT_EQ(0, host_.pending_requests()); | 1861 EXPECT_EQ(0, host_.pending_requests()); |
| (...skipping 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3988 return nullptr; | 3988 return nullptr; |
| 3989 } | 3989 } |
| 3990 | 3990 |
| 3991 INSTANTIATE_TEST_CASE_P( | 3991 INSTANTIATE_TEST_CASE_P( |
| 3992 ResourceDispatcherHostTests, | 3992 ResourceDispatcherHostTests, |
| 3993 ResourceDispatcherHostTest, | 3993 ResourceDispatcherHostTest, |
| 3994 testing::Values(TestConfig::kDefault, | 3994 testing::Values(TestConfig::kDefault, |
| 3995 TestConfig::kOptimizeIPCForSmallResourceEnabled)); | 3995 TestConfig::kOptimizeIPCForSmallResourceEnabled)); |
| 3996 | 3996 |
| 3997 } // namespace content | 3997 } // namespace content |
| OLD | NEW |