OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "content/browser/frame_host/render_frame_host_impl.h" | 11 #include "content/browser/frame_host/render_frame_host_impl.h" |
12 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 12 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
13 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
14 #include "content/common/frame_messages.h" | 14 #include "content/common/frame_messages.h" |
15 #include "content/public/browser/resource_controller.h" | |
16 #include "content/public/browser/resource_dispatcher_host.h" | 15 #include "content/public/browser/resource_dispatcher_host.h" |
17 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 16 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
18 #include "content/public/browser/resource_throttle.h" | 17 #include "content/public/browser/resource_throttle.h" |
19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
20 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
21 #include "content/public/test/content_browser_test.h" | 20 #include "content/public/test/content_browser_test.h" |
22 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
23 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
24 #include "content/shell/browser/shell.h" | 23 #include "content/shell/browser/shell.h" |
25 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" | 24 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 : resumed_(false), | 100 : resumed_(false), |
102 request_(request), | 101 request_(request), |
103 tracker_(tracker), | 102 tracker_(tracker), |
104 run_on_start_(run_on_start), | 103 run_on_start_(run_on_start), |
105 weak_factory_(this) {} | 104 weak_factory_(this) {} |
106 | 105 |
107 void WillStartRequest(bool* defer) override { | 106 void WillStartRequest(bool* defer) override { |
108 *defer = true; | 107 *defer = true; |
109 base::Closure resume_request_on_io_thread = base::Bind( | 108 base::Closure resume_request_on_io_thread = base::Bind( |
110 base::IgnoreResult(&BrowserThread::PostTask), BrowserThread::IO, | 109 base::IgnoreResult(&BrowserThread::PostTask), BrowserThread::IO, |
111 FROM_HERE, base::Bind(&CallbackRunningResourceThrottle::Resume, | 110 FROM_HERE, base::Bind(&CallbackRunningResourceThrottle::MarkAndResume, |
112 weak_factory_.GetWeakPtr())); | 111 weak_factory_.GetWeakPtr())); |
113 BrowserThread::PostTask( | 112 BrowserThread::PostTask( |
114 BrowserThread::UI, FROM_HERE, | 113 BrowserThread::UI, FROM_HERE, |
115 base::Bind(run_on_start_, resume_request_on_io_thread)); | 114 base::Bind(run_on_start_, resume_request_on_io_thread)); |
116 } | 115 } |
117 | 116 |
118 ~CallbackRunningResourceThrottle() override { | 117 ~CallbackRunningResourceThrottle() override { |
119 // If the request is deleted without being cancelled, its status will | 118 // If the request is deleted without being cancelled, its status will |
120 // indicate it succeeded, so have to check if the request is still pending | 119 // indicate it succeeded, so have to check if the request is still pending |
121 // as well. If the request never even started, the throttle will never | 120 // as well. If the request never even started, the throttle will never |
122 // resume it. Check this condition as well to allow for early | 121 // resume it. Check this condition as well to allow for early |
123 // cancellation. | 122 // cancellation. |
124 tracker_->OnTrackedRequestDestroyed(!request_->is_pending() && | 123 tracker_->OnTrackedRequestDestroyed(!request_->is_pending() && |
125 request_->status().is_success() && | 124 request_->status().is_success() && |
126 resumed_); | 125 resumed_); |
127 } | 126 } |
128 | 127 |
129 // ResourceThrottle implementation: | 128 // ResourceThrottle implementation: |
130 const char* GetNameForLogging() const override { | 129 const char* GetNameForLogging() const override { |
131 return "CallbackRunningResourceThrottle"; | 130 return "CallbackRunningResourceThrottle"; |
132 } | 131 } |
133 | 132 |
134 private: | 133 private: |
135 void Resume() { | 134 void MarkAndResume() { |
136 resumed_ = true; | 135 resumed_ = true; |
137 controller()->Resume(); | 136 Resume(); |
138 } | 137 } |
139 | 138 |
140 bool resumed_; | 139 bool resumed_; |
141 net::URLRequest* request_; | 140 net::URLRequest* request_; |
142 TestResourceDispatcherHostDelegate* tracker_; | 141 TestResourceDispatcherHostDelegate* tracker_; |
143 RequestDeferredHook run_on_start_; | 142 RequestDeferredHook run_on_start_; |
144 base::WeakPtrFactory<CallbackRunningResourceThrottle> weak_factory_; | 143 base::WeakPtrFactory<CallbackRunningResourceThrottle> weak_factory_; |
145 | 144 |
146 DISALLOW_COPY_AND_ASSIGN(CallbackRunningResourceThrottle); | 145 DISALLOW_COPY_AND_ASSIGN(CallbackRunningResourceThrottle); |
147 }; | 146 }; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 base::StringPrintf("document.getElementById('child-0').src='%s'", | 278 base::StringPrintf("document.getElementById('child-0').src='%s'", |
280 target_resource.spec().c_str()))); | 279 target_resource.spec().c_str()))); |
281 | 280 |
282 // Wait for the scenario to play out. If this returns false, it means the | 281 // Wait for the scenario to play out. If this returns false, it means the |
283 // request did not succeed, which is good in this case. | 282 // request did not succeed, which is good in this case. |
284 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()) | 283 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()) |
285 << "Request should have been cancelled before reaching the renderer."; | 284 << "Request should have been cancelled before reaching the renderer."; |
286 } | 285 } |
287 | 286 |
288 } // namespace content | 287 } // namespace content |
OLD | NEW |