Chromium Code Reviews| 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/throttling_resource_handler.h" | 5 #include "content/browser/loader/throttling_resource_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/browser/loader/resource_controller.h" | 9 #include "content/browser/loader/resource_controller.h" |
| 10 #include "content/browser/loader/resource_request_info_impl.h" | |
| 11 #include "content/public/common/resource_response.h" | 10 #include "content/public/common/resource_response.h" |
| 12 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 13 | 12 |
| 14 namespace content { | 13 namespace content { |
| 15 | 14 |
| 16 ThrottlingResourceHandler::ThrottlingResourceHandler( | 15 ThrottlingResourceHandler::ThrottlingResourceHandler( |
| 17 std::unique_ptr<ResourceHandler> next_handler, | 16 std::unique_ptr<ResourceHandler> next_handler, |
| 18 net::URLRequest* request, | 17 net::URLRequest* request, |
| 19 ScopedVector<ResourceThrottle> throttles) | 18 ScopedVector<ResourceThrottle> throttles) |
| 20 : LayeredResourceHandler(request, std::move(next_handler)), | 19 : LayeredResourceHandler(request, std::move(next_handler)), |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 cancelled_by_resource_throttle_ = true; | 115 cancelled_by_resource_throttle_ = true; |
| 117 controller()->CancelAndIgnore(); | 116 controller()->CancelAndIgnore(); |
| 118 } | 117 } |
| 119 | 118 |
| 120 void ThrottlingResourceHandler::CancelWithError(int error_code) { | 119 void ThrottlingResourceHandler::CancelWithError(int error_code) { |
| 121 cancelled_by_resource_throttle_ = true; | 120 cancelled_by_resource_throttle_ = true; |
| 122 controller()->CancelWithError(error_code); | 121 controller()->CancelWithError(error_code); |
| 123 } | 122 } |
| 124 | 123 |
| 125 void ThrottlingResourceHandler::Resume() { | 124 void ThrottlingResourceHandler::Resume() { |
| 126 DCHECK(!cancelled_by_resource_throttle_); | 125 // Throttles expect to be able to cancel requests out-of-band, so just do |
| 126 // nothing if one request resumes after another cancels. Can't even recognize | |
| 127 // out-of-band cancels and for synchronous teardown, since don't know if the | |
| 128 // currently active throttle called Cancel() or if it was another one. | |
|
Randy Smith (Not in Mondays)
2016/12/20 22:16:41
I'd really like to understand this use case better
mmenke
2017/01/04 22:02:29
I was wrong about NavigationResourceThrottle (It's
mmenke
2017/01/05 18:50:00
Sorry, I was wrong.
For the problematic case, hav
Randy Smith (Not in Mondays)
2017/01/11 19:57:15
Oh, what a mess. Ok.
* For purposes of this CL,
| |
| 129 if (cancelled_by_resource_throttle_) | |
| 130 return; | |
| 127 | 131 |
| 128 DeferredStage last_deferred_stage = deferred_stage_; | 132 DeferredStage last_deferred_stage = deferred_stage_; |
| 129 deferred_stage_ = DEFERRED_NONE; | 133 deferred_stage_ = DEFERRED_NONE; |
| 130 // Clear information about the throttle that delayed the request. | 134 // Clear information about the throttle that delayed the request. |
| 131 request()->LogUnblocked(); | 135 request()->LogUnblocked(); |
| 132 switch (last_deferred_stage) { | 136 switch (last_deferred_stage) { |
| 133 case DEFERRED_NONE: | 137 case DEFERRED_NONE: |
| 134 NOTREACHED(); | 138 NOTREACHED(); |
| 135 break; | 139 break; |
| 136 case DEFERRED_START: | 140 case DEFERRED_START: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 } else if (!defer) { | 191 } else if (!defer) { |
| 188 controller()->Resume(); | 192 controller()->Resume(); |
| 189 } | 193 } |
| 190 } | 194 } |
| 191 | 195 |
| 192 void ThrottlingResourceHandler::OnRequestDeferred(int throttle_index) { | 196 void ThrottlingResourceHandler::OnRequestDeferred(int throttle_index) { |
| 193 request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging()); | 197 request()->LogBlockedBy(throttles_[throttle_index]->GetNameForLogging()); |
| 194 } | 198 } |
| 195 | 199 |
| 196 } // namespace content | 200 } // namespace content |
| OLD | NEW |