Commit c9cbab07 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Fix ExtensionWebRequestApiTest.WebRequestUnloadImmediately with network service

The error event was not being sent when the client was reset.

Bug: 721414
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I951422061022d50644d8453900af14be27bb9eaf
Reviewed-on: https://chromium-review.googlesource.com/1150403
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580911}
parent a8191a7c
...@@ -62,11 +62,11 @@ WebRequestProxyingURLLoaderFactory::InProgressRequest::InProgressRequest( ...@@ -62,11 +62,11 @@ WebRequestProxyingURLLoaderFactory::InProgressRequest::InProgressRequest(
target_client_(std::move(client)), target_client_(std::move(client)),
proxied_client_binding_(this), proxied_client_binding_(this),
weak_factory_(this) { weak_factory_(this) {
// If there is a client error, remove this request from the proxy. |factory_| // If there is a client error, clean up the request.
// outlives this class, so base::Unretained is safe.
target_client_.set_connection_error_handler(base::BindOnce( target_client_.set_connection_error_handler(base::BindOnce(
&WebRequestProxyingURLLoaderFactory::RemoveRequest, &WebRequestProxyingURLLoaderFactory::InProgressRequest::OnRequestError,
base::Unretained(factory_), network_service_request_id_, request_id_)); weak_factory_.GetWeakPtr(),
network::URLLoaderCompletionStatus(net::ERR_ABORTED)));
} }
WebRequestProxyingURLLoaderFactory::InProgressRequest::~InProgressRequest() { WebRequestProxyingURLLoaderFactory::InProgressRequest::~InProgressRequest() {
...@@ -79,6 +79,7 @@ WebRequestProxyingURLLoaderFactory::InProgressRequest::~InProgressRequest() { ...@@ -79,6 +79,7 @@ WebRequestProxyingURLLoaderFactory::InProgressRequest::~InProgressRequest() {
} }
void WebRequestProxyingURLLoaderFactory::InProgressRequest::Restart() { void WebRequestProxyingURLLoaderFactory::InProgressRequest::Restart() {
request_completed_ = false;
// Derive a new WebRequestInfo value any time |Restart()| is called, because // Derive a new WebRequestInfo value any time |Restart()| is called, because
// the details in |request_| may have changed e.g. if we've been redirected. // the details in |request_| may have changed e.g. if we've been redirected.
info_.emplace( info_.emplace(
...@@ -230,6 +231,7 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::OnComplete( ...@@ -230,6 +231,7 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::OnComplete(
// Deletes |this|. // Deletes |this|.
factory_->RemoveRequest(network_service_request_id_, request_id_); factory_->RemoveRequest(network_service_request_id_, request_id_);
request_completed_ = true;
} }
void WebRequestProxyingURLLoaderFactory::InProgressRequest::HandleAuthRequest( void WebRequestProxyingURLLoaderFactory::InProgressRequest::HandleAuthRequest(
...@@ -496,6 +498,7 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest:: ...@@ -496,6 +498,7 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::
redirect_info.new_url); redirect_info.new_url);
target_client_->OnReceiveRedirect(redirect_info, current_response_); target_client_->OnReceiveRedirect(redirect_info, current_response_);
request_.url = redirect_info.new_url; request_.url = redirect_info.new_url;
request_completed_ = true;
} }
void WebRequestProxyingURLLoaderFactory::InProgressRequest:: void WebRequestProxyingURLLoaderFactory::InProgressRequest::
...@@ -529,13 +532,14 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest:: ...@@ -529,13 +532,14 @@ void WebRequestProxyingURLLoaderFactory::InProgressRequest::
continuation.Run(net::OK); continuation.Run(net::OK);
} }
void WebRequestProxyingURLLoaderFactory::InProgressRequest::OnRequestError( void WebRequestProxyingURLLoaderFactory::InProgressRequest::OnRequestError(
const network::URLLoaderCompletionStatus& status) { const network::URLLoaderCompletionStatus& status) {
if (!request_completed_) {
target_client_->OnComplete(status); target_client_->OnComplete(status);
ExtensionWebRequestEventRouter::GetInstance()->OnErrorOccurred( ExtensionWebRequestEventRouter::GetInstance()->OnErrorOccurred(
factory_->browser_context_, factory_->info_map_, &info_.value(), factory_->browser_context_, factory_->info_map_, &info_.value(),
true /* started */, status.error_code); true /* started */, status.error_code);
}
// Deletes |this|. // Deletes |this|.
factory_->RemoveRequest(network_service_request_id_, request_id_); factory_->RemoveRequest(network_service_request_id_, request_id_);
......
...@@ -163,6 +163,8 @@ class WebRequestProxyingURLLoaderFactory ...@@ -163,6 +163,8 @@ class WebRequestProxyingURLLoaderFactory
// lifetime. // lifetime.
base::Optional<net::AuthCredentials> auth_credentials_; base::Optional<net::AuthCredentials> auth_credentials_;
bool request_completed_ = false;
base::WeakPtrFactory<InProgressRequest> weak_factory_; base::WeakPtrFactory<InProgressRequest> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(InProgressRequest); DISALLOW_COPY_AND_ASSIGN(InProgressRequest);
......
...@@ -187,11 +187,6 @@ ...@@ -187,11 +187,6 @@
-IOThreadBrowserTestWithHangingPacRequest.Shutdown -IOThreadBrowserTestWithHangingPacRequest.Shutdown
-ProxySettingsApiTest.ProxyEventsParseError -ProxySettingsApiTest.ProxyEventsParseError
# http://crbug.com/721414
# TODO(rockot): add support for webRequest API.
# Note WebRequestUnloadImmediately is disabled on Linux
-ExtensionWebRequestApiTest.WebRequestUnloadImmediately
# http://crbug.com/827582 # http://crbug.com/827582
# Editing response cookies through headers with webRequest is not supported with # Editing response cookies through headers with webRequest is not supported with
# the network service. # the network service.
......
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