Commit 6123403c authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

DevTools: run DevToolsURLLoaderInterceptor on the UI thread

.. there's no reason to do it on IO and it lets us simplify things a bit.

This removes DevToolsURLLoaderInterceptor::Impl and moves most of its
methods and members to DevToolsURLLoaderInterceptor itself, resulting
in former Impl methods being run directly on the UI thread.

Bug: 1005281
Change-Id: I8193b43edbedcdfecad2541cd905c2c1ea2136ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815083Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarJohannes Henkel <johannes@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699595}
parent 5035cdff
......@@ -15,6 +15,7 @@
#include "mojo/public/cpp/system/data_pipe.h"
#include "net/base/auth.h"
#include "net/base/net_errors.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
namespace net {
......@@ -24,7 +25,9 @@ class HttpResponseHeaders;
namespace content {
class InterceptionJob;
class RenderProcessHost;
struct CreateLoaderParameters;
struct InterceptedRequestInfo {
InterceptedRequestInfo();
......@@ -154,8 +157,6 @@ class DevToolsURLLoaderInterceptor {
DISALLOW_COPY_AND_ASSIGN(FilterEntry);
};
class Impl;
using HandleAuthRequestCallback =
base::OnceCallback<void(bool use_fallback,
const base::Optional<net::AuthCredentials>&)>;
......@@ -187,12 +188,49 @@ class DevToolsURLLoaderInterceptor {
bool is_navigation,
bool is_download,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>*
target_factory_receiver) const;
target_factory_receiver);
private:
bool enabled_;
std::unique_ptr<Impl, base::OnTaskRunnerDeleter> impl_;
base::WeakPtr<Impl> weak_impl_;
friend class InterceptionJob;
friend class DevToolsURLLoaderFactoryProxy;
void CreateJob(
const base::UnguessableToken& frame_token,
int32_t process_id,
bool is_download,
const base::Optional<std::string>& renderer_request_id,
std::unique_ptr<CreateLoaderParameters> create_params,
network::mojom::URLLoaderRequest loader_request,
network::mojom::URLLoaderClientPtr client,
network::mojom::URLLoaderFactoryPtr target_factory,
mojo::PendingRemote<network::mojom::CookieManager> cookie_manager);
InterceptionStage GetInterceptionStage(const GURL& url,
ResourceType resource_type) const;
template <typename Callback>
InterceptionJob* FindJob(const std::string& id,
std::unique_ptr<Callback>* callback) {
auto it = jobs_.find(id);
if (it != jobs_.end())
return it->second;
(*callback)->sendFailure(
protocol::Response::InvalidParams("Invalid InterceptionId."));
return nullptr;
}
void RemoveJob(const std::string& id) { jobs_.erase(id); }
void AddJob(const std::string& id, InterceptionJob* job) {
jobs_.emplace(id, job);
}
const RequestInterceptedCallback request_intercepted_callback_;
std::vector<Pattern> patterns_;
bool handle_auth_ = false;
std::map<std::string, InterceptionJob*> jobs_;
base::WeakPtrFactory<DevToolsURLLoaderInterceptor> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DevToolsURLLoaderInterceptor);
};
......
......@@ -544,15 +544,10 @@ class LoginHandlerDelegate {
auth_challenge_responder_.set_disconnect_handler(base::BindOnce(
&LoginHandlerDelegate::OnRequestCancelled, base::Unretained(this)));
auto continue_after_inteceptor_io =
base::BindOnce(&LoginHandlerDelegate::ContinueAfterInterceptorIO,
weak_factory_.GetWeakPtr());
base::PostTask(
FROM_HERE, {BrowserThread::IO},
base::BindOnce(&DevToolsURLLoaderInterceptor::HandleAuthRequest,
request_id_.child_id, routing_id_,
request_id_.request_id, auth_info_,
std::move(continue_after_inteceptor_io)));
DevToolsURLLoaderInterceptor::HandleAuthRequest(
request_id_.child_id, routing_id_, request_id_.request_id, auth_info_,
base::BindOnce(&LoginHandlerDelegate::ContinueAfterInterceptor,
weak_factory_.GetWeakPtr()));
}
private:
......@@ -563,18 +558,7 @@ class LoginHandlerDelegate {
delete this;
}
static void ContinueAfterInterceptorIO(
base::WeakPtr<LoginHandlerDelegate> self_weak,
bool use_fallback,
const base::Optional<net::AuthCredentials>& auth_credentials) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTask(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&LoginHandlerDelegate::ContinueAfterInterceptorUI,
std::move(self_weak), use_fallback, auth_credentials));
}
void ContinueAfterInterceptorUI(
void ContinueAfterInterceptor(
bool use_fallback,
const base::Optional<net::AuthCredentials>& auth_credentials) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......
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