Commit 90cf7fc2 authored by mmenke's avatar mmenke Committed by Commit bot

When InterceptingResourceHandler swaps in a handler, call OnWillStart.

The new ResourceHandler's OnWillStart was never being called, which
violates the ResourceHandler's API contract, and has caused at least one
crash previously (Though that fixed by another CL).

BUG=650717

Review-Url: https://codereview.chromium.org/2436163002
Cr-Commit-Position: refs/heads/master@{#427183}
parent 45b69824
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "content/public/common/resource_response.h" #include "content/public/common/resource_response.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/url_request/url_request.h"
namespace content { namespace content {
...@@ -175,7 +176,10 @@ bool InterceptingResourceHandler::DoLoop(bool* defer) { ...@@ -175,7 +176,10 @@ bool InterceptingResourceHandler::DoLoop(bool* defer) {
case State::PASS_THROUGH: case State::PASS_THROUGH:
NOTREACHED(); NOTREACHED();
break; break;
case State::NOTIFYING_ON_RESPONSE_STARTED_TO_NEW_HANDLER: case State::SENDING_ON_WILL_START_TO_NEW_HANDLER:
result = SendOnResponseStartedToNewHandler(defer);
break;
case State::SENDING_ON_RESPONSE_STARTED_TO_NEW_HANDLER:
if (first_read_buffer_double_) { if (first_read_buffer_double_) {
// OnWillRead has been called, so copying the data from // OnWillRead has been called, so copying the data from
// |first_read_buffer_double_| to |first_read_buffer_| will be needed // |first_read_buffer_double_| to |first_read_buffer_| will be needed
...@@ -239,7 +243,13 @@ bool InterceptingResourceHandler::SendPayloadToOldHandler(bool* defer) { ...@@ -239,7 +243,13 @@ bool InterceptingResourceHandler::SendPayloadToOldHandler(bool* defer) {
DCHECK(!*defer); DCHECK(!*defer);
next_handler_ = std::move(new_handler_); next_handler_ = std::move(new_handler_);
state_ = State::NOTIFYING_ON_RESPONSE_STARTED_TO_NEW_HANDLER; state_ = State::SENDING_ON_WILL_START_TO_NEW_HANDLER;
return next_handler_->OnWillStart(request()->url(), defer);
}
bool InterceptingResourceHandler::SendOnResponseStartedToNewHandler(
bool* defer) {
state_ = State::SENDING_ON_RESPONSE_STARTED_TO_NEW_HANDLER;
return next_handler_->OnResponseStarted(response_.get(), defer); return next_handler_->OnResponseStarted(response_.get(), defer);
} }
......
...@@ -81,11 +81,17 @@ class CONTENT_EXPORT InterceptingResourceHandler ...@@ -81,11 +81,17 @@ class CONTENT_EXPORT InterceptingResourceHandler
// Resume(). // Resume().
SENDING_PAYLOAD_TO_OLD_HANDLER, SENDING_PAYLOAD_TO_OLD_HANDLER,
// The InterceptingResourcHandler is notifying OnResponseStarted to the new // The InterceptingResourcHandler is calling the new handler's
// handler and waiting for its completion via Resume(). After the // OnResponseStarted method and waiting for its completion via Resume().
// completion, the InterceptingResourcHandler will transit to // After completion, the InterceptingResourceHandler will transition to
// SENDING_ON_RESPONSE_STARTED_TO_NEW_HANDLER on success.
SENDING_ON_WILL_START_TO_NEW_HANDLER,
// The InterceptingResourcHandler is calling the new handler's
// OnResponseStarted method and waiting for its completion via Resume().
// After completion, the InterceptingResourceHandler will transition to
// WAITING_FOR_ON_READ_COMPLETED on success. // WAITING_FOR_ON_READ_COMPLETED on success.
NOTIFYING_ON_RESPONSE_STARTED_TO_NEW_HANDLER, SENDING_ON_RESPONSE_STARTED_TO_NEW_HANDLER,
// The InterceptingResourcHandler is waiting for OnReadCompleted to be // The InterceptingResourcHandler is waiting for OnReadCompleted to be
// called. // called.
...@@ -110,7 +116,7 @@ class CONTENT_EXPORT InterceptingResourceHandler ...@@ -110,7 +116,7 @@ class CONTENT_EXPORT InterceptingResourceHandler
// The return value and |defer| has the same meaning as DoLoop. // The return value and |defer| has the same meaning as DoLoop.
bool SendPayloadToOldHandler(bool* defer); bool SendPayloadToOldHandler(bool* defer);
bool SendFirstReadBufferToNewHandler(bool* defer); bool SendFirstReadBufferToNewHandler(bool* defer);
bool SendCompletionToOldHandler(bool* defer); bool SendOnResponseStartedToNewHandler(bool* defer);
State state_ = State::STARTING; State state_ = State::STARTING;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment