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 @@ ...@@ -15,6 +15,7 @@
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
#include "net/base/auth.h" #include "net/base/auth.h"
#include "net/base/net_errors.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" #include "services/network/public/mojom/url_loader_factory.mojom.h"
namespace net { namespace net {
...@@ -24,7 +25,9 @@ class HttpResponseHeaders; ...@@ -24,7 +25,9 @@ class HttpResponseHeaders;
namespace content { namespace content {
class InterceptionJob;
class RenderProcessHost; class RenderProcessHost;
struct CreateLoaderParameters;
struct InterceptedRequestInfo { struct InterceptedRequestInfo {
InterceptedRequestInfo(); InterceptedRequestInfo();
...@@ -154,8 +157,6 @@ class DevToolsURLLoaderInterceptor { ...@@ -154,8 +157,6 @@ class DevToolsURLLoaderInterceptor {
DISALLOW_COPY_AND_ASSIGN(FilterEntry); DISALLOW_COPY_AND_ASSIGN(FilterEntry);
}; };
class Impl;
using HandleAuthRequestCallback = using HandleAuthRequestCallback =
base::OnceCallback<void(bool use_fallback, base::OnceCallback<void(bool use_fallback,
const base::Optional<net::AuthCredentials>&)>; const base::Optional<net::AuthCredentials>&)>;
...@@ -187,12 +188,49 @@ class DevToolsURLLoaderInterceptor { ...@@ -187,12 +188,49 @@ class DevToolsURLLoaderInterceptor {
bool is_navigation, bool is_navigation,
bool is_download, bool is_download,
mojo::PendingReceiver<network::mojom::URLLoaderFactory>* mojo::PendingReceiver<network::mojom::URLLoaderFactory>*
target_factory_receiver) const; target_factory_receiver);
private: private:
bool enabled_; friend class InterceptionJob;
std::unique_ptr<Impl, base::OnTaskRunnerDeleter> impl_; friend class DevToolsURLLoaderFactoryProxy;
base::WeakPtr<Impl> weak_impl_;
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); DISALLOW_COPY_AND_ASSIGN(DevToolsURLLoaderInterceptor);
}; };
......
...@@ -544,15 +544,10 @@ class LoginHandlerDelegate { ...@@ -544,15 +544,10 @@ class LoginHandlerDelegate {
auth_challenge_responder_.set_disconnect_handler(base::BindOnce( auth_challenge_responder_.set_disconnect_handler(base::BindOnce(
&LoginHandlerDelegate::OnRequestCancelled, base::Unretained(this))); &LoginHandlerDelegate::OnRequestCancelled, base::Unretained(this)));
auto continue_after_inteceptor_io = DevToolsURLLoaderInterceptor::HandleAuthRequest(
base::BindOnce(&LoginHandlerDelegate::ContinueAfterInterceptorIO, request_id_.child_id, routing_id_, request_id_.request_id, auth_info_,
weak_factory_.GetWeakPtr()); base::BindOnce(&LoginHandlerDelegate::ContinueAfterInterceptor,
base::PostTask( weak_factory_.GetWeakPtr()));
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)));
} }
private: private:
...@@ -563,18 +558,7 @@ class LoginHandlerDelegate { ...@@ -563,18 +558,7 @@ class LoginHandlerDelegate {
delete this; delete this;
} }
static void ContinueAfterInterceptorIO( void ContinueAfterInterceptor(
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(
bool use_fallback, bool use_fallback,
const base::Optional<net::AuthCredentials>& auth_credentials) { const base::Optional<net::AuthCredentials>& auth_credentials) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); 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