Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: content/browser/loader/intercepting_resource_handler.cc

Issue 2436163002: When InterceptingResourceHandler swaps in a handler, call OnWillStart. (Closed)
Patch Set: Remove unused value, reorder defer/results (They don't quite match...) Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/intercepting_resource_handler.h" 5 #include "content/browser/loader/intercepting_resource_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "content/public/common/resource_response.h" 9 #include "content/public/common/resource_response.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
11 #include "net/url_request/url_request.h"
11 12
12 namespace content { 13 namespace content {
13 14
14 InterceptingResourceHandler::InterceptingResourceHandler( 15 InterceptingResourceHandler::InterceptingResourceHandler(
15 std::unique_ptr<ResourceHandler> next_handler, 16 std::unique_ptr<ResourceHandler> next_handler,
16 net::URLRequest* request) 17 net::URLRequest* request)
17 : LayeredResourceHandler(request, std::move(next_handler)) { 18 : LayeredResourceHandler(request, std::move(next_handler)) {
18 next_handler_->SetController(this); 19 next_handler_->SetController(this);
19 } 20 }
20 21
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 169
169 bool InterceptingResourceHandler::DoLoop(bool* defer) { 170 bool InterceptingResourceHandler::DoLoop(bool* defer) {
170 bool result = true; 171 bool result = true;
171 do { 172 do {
172 switch (state_) { 173 switch (state_) {
173 case State::STARTING: 174 case State::STARTING:
174 case State::WAITING_FOR_ON_READ_COMPLETED: 175 case State::WAITING_FOR_ON_READ_COMPLETED:
175 case State::PASS_THROUGH: 176 case State::PASS_THROUGH:
176 NOTREACHED(); 177 NOTREACHED();
177 break; 178 break;
178 case State::NOTIFYING_ON_RESPONSE_STARTED_TO_NEW_HANDLER: 179 case State::SENDING_ON_WILL_START_TO_NEW_HANDLER:
180 result = SendOnResponseStartedToNewHandler(defer);
181 break;
182 case State::SENDING_ON_RESPONSE_STARTED_TO_NEW_HANDLER:
179 if (first_read_buffer_double_) { 183 if (first_read_buffer_double_) {
180 // OnWillRead has been called, so copying the data from 184 // OnWillRead has been called, so copying the data from
181 // |first_read_buffer_double_| to |first_read_buffer_| will be needed 185 // |first_read_buffer_double_| to |first_read_buffer_| will be needed
182 // when OnReadCompleted is called. 186 // when OnReadCompleted is called.
183 state_ = State::WAITING_FOR_ON_READ_COMPLETED; 187 state_ = State::WAITING_FOR_ON_READ_COMPLETED;
184 } else { 188 } else {
185 // OnWillRead has not been called, so no special handling will be 189 // OnWillRead has not been called, so no special handling will be
186 // needed from now on. 190 // needed from now on.
187 state_ = State::PASS_THROUGH; 191 state_ = State::PASS_THROUGH;
188 next_handler_->SetController(controller()); 192 next_handler_->SetController(controller());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 236
233 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0); 237 net::URLRequestStatus status(net::URLRequestStatus::SUCCESS, 0);
234 if (payload_for_old_handler_.empty()) { 238 if (payload_for_old_handler_.empty()) {
235 // If there is no payload, just finalize the request on the old handler. 239 // If there is no payload, just finalize the request on the old handler.
236 status = net::URLRequestStatus::FromError(net::ERR_ABORTED); 240 status = net::URLRequestStatus::FromError(net::ERR_ABORTED);
237 } 241 }
238 next_handler_->OnResponseCompleted(status, defer); 242 next_handler_->OnResponseCompleted(status, defer);
239 DCHECK(!*defer); 243 DCHECK(!*defer);
240 244
241 next_handler_ = std::move(new_handler_); 245 next_handler_ = std::move(new_handler_);
242 state_ = State::NOTIFYING_ON_RESPONSE_STARTED_TO_NEW_HANDLER; 246 state_ = State::SENDING_ON_WILL_START_TO_NEW_HANDLER;
247 return next_handler_->OnWillStart(request()->url(), defer);
248 }
249
250 bool InterceptingResourceHandler::SendOnResponseStartedToNewHandler(
251 bool* defer) {
252 state_ = State::SENDING_ON_RESPONSE_STARTED_TO_NEW_HANDLER;
243 return next_handler_->OnResponseStarted(response_.get(), defer); 253 return next_handler_->OnResponseStarted(response_.get(), defer);
244 } 254 }
245 255
246 bool InterceptingResourceHandler::SendFirstReadBufferToNewHandler(bool* defer) { 256 bool InterceptingResourceHandler::SendFirstReadBufferToNewHandler(bool* defer) {
247 DCHECK_EQ(state_, State::SENDING_BUFFER_TO_NEW_HANDLER); 257 DCHECK_EQ(state_, State::SENDING_BUFFER_TO_NEW_HANDLER);
248 258
249 while (first_read_buffer_bytes_written_ < first_read_buffer_bytes_read_) { 259 while (first_read_buffer_bytes_written_ < first_read_buffer_bytes_read_) {
250 scoped_refptr<net::IOBuffer> buf; 260 scoped_refptr<net::IOBuffer> buf;
251 int size = 0; 261 int size = 0;
252 if (!next_handler_->OnWillRead(&buf, &size, -1)) 262 if (!next_handler_->OnWillRead(&buf, &size, -1))
(...skipping 10 matching lines...) Expand all
263 return true; 273 return true;
264 } 274 }
265 275
266 state_ = State::PASS_THROUGH; 276 state_ = State::PASS_THROUGH;
267 first_read_buffer_double_ = nullptr; 277 first_read_buffer_double_ = nullptr;
268 next_handler_->SetController(controller()); 278 next_handler_->SetController(controller());
269 return true; 279 return true;
270 } 280 }
271 281
272 } // namespace content 282 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698