| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 const TimingDeltas& load_timing_deltas) | 122 const TimingDeltas& load_timing_deltas) |
| 123 : net::URLRequestFileJob( | 123 : net::URLRequestFileJob( |
| 124 request, network_delegate, path, | 124 request, network_delegate, path, |
| 125 content::BrowserThread::GetBlockingPool()-> | 125 content::BrowserThread::GetBlockingPool()-> |
| 126 GetTaskRunnerWithShutdownBehavior( | 126 GetTaskRunnerWithShutdownBehavior( |
| 127 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), | 127 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
| 128 load_timing_deltas_(load_timing_deltas), | 128 load_timing_deltas_(load_timing_deltas), |
| 129 weak_factory_(this) {} | 129 weak_factory_(this) {} |
| 130 | 130 |
| 131 // net::URLRequestFileJob implementation: | 131 // net::URLRequestFileJob implementation: |
| 132 virtual void Start() OVERRIDE { | 132 virtual void Start() override { |
| 133 base::TimeDelta time_to_wait; | 133 base::TimeDelta time_to_wait; |
| 134 start_time_ = base::TimeTicks::Now(); | 134 start_time_ = base::TimeTicks::Now(); |
| 135 if (!load_timing_deltas_.receive_headers_end.is_null()) { | 135 if (!load_timing_deltas_.receive_headers_end.is_null()) { |
| 136 // Need to delay starting until the largest of the times has elapsed. | 136 // Need to delay starting until the largest of the times has elapsed. |
| 137 // Wait a little longer than necessary, to be on the safe side. | 137 // Wait a little longer than necessary, to be on the safe side. |
| 138 time_to_wait = load_timing_deltas_.receive_headers_end.GetDelta() + | 138 time_to_wait = load_timing_deltas_.receive_headers_end.GetDelta() + |
| 139 base::TimeDelta::FromMilliseconds(100); | 139 base::TimeDelta::FromMilliseconds(100); |
| 140 } | 140 } |
| 141 | 141 |
| 142 base::MessageLoop::current()->PostDelayedTask( | 142 base::MessageLoop::current()->PostDelayedTask( |
| 143 FROM_HERE, | 143 FROM_HERE, |
| 144 base::Bind(&MockUrlRequestJobWithTiming::DelayedStart, | 144 base::Bind(&MockUrlRequestJobWithTiming::DelayedStart, |
| 145 weak_factory_.GetWeakPtr()), | 145 weak_factory_.GetWeakPtr()), |
| 146 time_to_wait); | 146 time_to_wait); |
| 147 } | 147 } |
| 148 | 148 |
| 149 virtual void GetLoadTimingInfo( | 149 virtual void GetLoadTimingInfo( |
| 150 net::LoadTimingInfo* load_timing_info) const OVERRIDE { | 150 net::LoadTimingInfo* load_timing_info) const override { |
| 151 // Make sure enough time has elapsed since start was called. If this | 151 // Make sure enough time has elapsed since start was called. If this |
| 152 // fails, the test fixture itself is flaky. | 152 // fails, the test fixture itself is flaky. |
| 153 if (!load_timing_deltas_.receive_headers_end.is_null()) { | 153 if (!load_timing_deltas_.receive_headers_end.is_null()) { |
| 154 EXPECT_LE( | 154 EXPECT_LE( |
| 155 start_time_ + load_timing_deltas_.receive_headers_end.GetDelta(), | 155 start_time_ + load_timing_deltas_.receive_headers_end.GetDelta(), |
| 156 base::TimeTicks::Now()); | 156 base::TimeTicks::Now()); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // If there are no connect times, but there is a receive headers end time, | 159 // If there are no connect times, but there is a receive headers end time, |
| 160 // then assume the socket is reused. This shouldn't affect the load timing | 160 // then assume the socket is reused. This shouldn't affect the load timing |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // |this|. | 240 // |this|. |
| 241 void Unregister() { | 241 void Unregister() { |
| 242 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 242 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 243 net::URLRequestFilter::GetInstance()->RemoveHostnameHandler( | 243 net::URLRequestFilter::GetInstance()->RemoveHostnameHandler( |
| 244 "http", kTestDomain); | 244 "http", kTestDomain); |
| 245 } | 245 } |
| 246 | 246 |
| 247 // net::URLRequestJobFactory::ProtocolHandler implementation: | 247 // net::URLRequestJobFactory::ProtocolHandler implementation: |
| 248 virtual net::URLRequestJob* MaybeInterceptRequest( | 248 virtual net::URLRequestJob* MaybeInterceptRequest( |
| 249 net::URLRequest* request, | 249 net::URLRequest* request, |
| 250 net::NetworkDelegate* network_delegate) const OVERRIDE { | 250 net::NetworkDelegate* network_delegate) const override { |
| 251 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 251 EXPECT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 252 | 252 |
| 253 return new MockUrlRequestJobWithTiming(request, network_delegate, path_, | 253 return new MockUrlRequestJobWithTiming(request, network_delegate, path_, |
| 254 load_timing_deltas_); | 254 load_timing_deltas_); |
| 255 } | 255 } |
| 256 | 256 |
| 257 private: | 257 private: |
| 258 // Path of the file to use as the response body. | 258 // Path of the file to use as the response body. |
| 259 const base::FilePath path_; | 259 const base::FilePath path_; |
| 260 | 260 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 navigation_deltas.send_start.GetDelta()); | 589 navigation_deltas.send_start.GetDelta()); |
| 590 // The only times that are guaranteed to be distinct are send_start and | 590 // The only times that are guaranteed to be distinct are send_start and |
| 591 // received_headers_end. | 591 // received_headers_end. |
| 592 EXPECT_LT(navigation_deltas.send_start.GetDelta(), | 592 EXPECT_LT(navigation_deltas.send_start.GetDelta(), |
| 593 navigation_deltas.receive_headers_end.GetDelta()); | 593 navigation_deltas.receive_headers_end.GetDelta()); |
| 594 | 594 |
| 595 EXPECT_TRUE(navigation_deltas.ssl_start.is_null()); | 595 EXPECT_TRUE(navigation_deltas.ssl_start.is_null()); |
| 596 } | 596 } |
| 597 | 597 |
| 598 } // namespace | 598 } // namespace |
| OLD | NEW |