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

Unified Diff: content/common/throttling_url_loader.cc

Issue 2926693002: Make content::ThrottlingURLLoader take a task runner and more efficient. (Closed)
Patch Set: sync & resolve Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/common/throttling_url_loader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/throttling_url_loader.cc
diff --git a/content/common/throttling_url_loader.cc b/content/common/throttling_url_loader.cc
index 9f258c9d088eb45119684147f6e08bda2be1f69f..df1ef23f613f25ea9e3af6c98662d86d5944502a 100644
--- a/content/common/throttling_url_loader.cc
+++ b/content/common/throttling_url_loader.cc
@@ -4,8 +4,50 @@
#include "content/common/throttling_url_loader.h"
+#include "base/single_thread_task_runner.h"
+
namespace content {
+ThrottlingURLLoader::StartInfo::StartInfo(
+ mojom::URLLoaderFactory* in_url_loader_factory,
+ int32_t in_routing_id,
+ int32_t in_request_id,
+ uint32_t in_options,
+ std::unique_ptr<ResourceRequest> in_url_request,
+ scoped_refptr<base::SingleThreadTaskRunner> in_task_runner)
+ : url_loader_factory(in_url_loader_factory),
+ routing_id(in_routing_id),
+ request_id(in_request_id),
+ options(in_options),
+ url_request(std::move(in_url_request)),
+ task_runner(std::move(in_task_runner)) {}
+
+ThrottlingURLLoader::StartInfo::~StartInfo() = default;
+
+ThrottlingURLLoader::ResponseInfo::ResponseInfo(
+ const ResourceResponseHead& in_response_head,
+ const base::Optional<net::SSLInfo>& in_ssl_info,
+ mojom::DownloadedTempFilePtr in_downloaded_file)
+ : response_head(in_response_head),
+ ssl_info(in_ssl_info),
+ downloaded_file(std::move(in_downloaded_file)) {}
+
+ThrottlingURLLoader::ResponseInfo::~ResponseInfo() = default;
+
+ThrottlingURLLoader::RedirectInfo::RedirectInfo(
+ const net::RedirectInfo& in_redirect_info,
+ const ResourceResponseHead& in_response_head)
+ : redirect_info(in_redirect_info), response_head(in_response_head) {}
+
+ThrottlingURLLoader::RedirectInfo::~RedirectInfo() = default;
+
+ThrottlingURLLoader::PriorityInfo::PriorityInfo(
+ net::RequestPriority in_priority,
+ int32_t in_intra_priority_value)
+ : priority(in_priority), intra_priority_value(in_intra_priority_value) {}
+
+ThrottlingURLLoader::PriorityInfo::~PriorityInfo() = default;
+
// static
std::unique_ptr<ThrottlingURLLoader> ThrottlingURLLoader::CreateLoaderAndStart(
mojom::URLLoaderFactory* factory,
@@ -14,11 +56,12 @@ std::unique_ptr<ThrottlingURLLoader> ThrottlingURLLoader::CreateLoaderAndStart(
int32_t request_id,
uint32_t options,
std::unique_ptr<ResourceRequest> url_request,
- mojom::URLLoaderClient* client) {
+ mojom::URLLoaderClient* client,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
std::unique_ptr<ThrottlingURLLoader> loader(
new ThrottlingURLLoader(std::move(throttles), client));
loader->Start(factory, routing_id, request_id, options,
- std::move(url_request));
+ std::move(url_request), std::move(task_runner));
return loader;
}
@@ -33,9 +76,8 @@ void ThrottlingURLLoader::SetPriority(net::RequestPriority priority,
int32_t intra_priority_value) {
if (!url_loader_ && !cancelled_by_throttle_) {
DCHECK_EQ(DEFERRED_START, deferred_stage_);
- set_priority_cached_ = true;
- priority_ = priority;
- intra_priority_value_ = intra_priority_value;
+ priority_info_ =
+ base::MakeUnique<PriorityInfo>(priority, intra_priority_value);
return;
}
@@ -55,11 +97,13 @@ ThrottlingURLLoader::ThrottlingURLLoader(
}
}
-void ThrottlingURLLoader::Start(mojom::URLLoaderFactory* factory,
- int32_t routing_id,
- int32_t request_id,
- uint32_t options,
- std::unique_ptr<ResourceRequest> url_request) {
+void ThrottlingURLLoader::Start(
+ mojom::URLLoaderFactory* factory,
+ int32_t routing_id,
+ int32_t request_id,
+ uint32_t options,
+ std::unique_ptr<ResourceRequest> url_request,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK_EQ(DEFERRED_NONE, deferred_stage_);
DCHECK(!cancelled_by_throttle_);
@@ -72,18 +116,17 @@ void ThrottlingURLLoader::Start(mojom::URLLoaderFactory* factory,
if (deferred) {
deferred_stage_ = DEFERRED_START;
- url_loader_factory_ = factory;
- routing_id_ = routing_id;
- request_id_ = request_id;
- options_ = options;
- url_request_ = std::move(url_request);
+ start_info_ = base::MakeUnique<StartInfo>(factory, routing_id, request_id,
+ options, std::move(url_request),
+ std::move(task_runner));
return;
}
}
- factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_), routing_id,
- request_id, options, *url_request,
- client_binding_.CreateInterfacePtrAndBind());
+ factory->CreateLoaderAndStart(
+ mojo::MakeRequest(&url_loader_), routing_id, request_id, options,
+ *url_request,
+ client_binding_.CreateInterfacePtrAndBind(std::move(task_runner)));
}
void ThrottlingURLLoader::OnReceiveResponse(
@@ -101,9 +144,8 @@ void ThrottlingURLLoader::OnReceiveResponse(
if (deferred) {
deferred_stage_ = DEFERRED_RESPONSE;
- response_head_ = response_head;
- ssl_info_ = ssl_info;
- downloaded_file_ = std::move(downloaded_file);
+ response_info_ = base::MakeUnique<ResponseInfo>(
+ response_head, ssl_info, std::move(downloaded_file));
client_binding_.PauseIncomingMethodCallProcessing();
return;
}
@@ -127,8 +169,8 @@ void ThrottlingURLLoader::OnReceiveRedirect(
if (deferred) {
deferred_stage_ = DEFERRED_REDIRECT;
- redirect_info_ = redirect_info;
- response_head_ = response_head;
+ redirect_info_ =
+ base::MakeUnique<RedirectInfo>(redirect_info, response_head);
client_binding_.PauseIncomingMethodCallProcessing();
return;
}
@@ -212,25 +254,31 @@ void ThrottlingURLLoader::Resume() {
switch (deferred_stage_) {
case DEFERRED_START: {
- url_loader_factory_->CreateLoaderAndStart(
- mojo::MakeRequest(&url_loader_), routing_id_, request_id_, options_,
- *url_request_, client_binding_.CreateInterfacePtrAndBind());
-
- if (set_priority_cached_) {
- set_priority_cached_ = false;
- url_loader_->SetPriority(priority_, intra_priority_value_);
+ start_info_->url_loader_factory->CreateLoaderAndStart(
+ mojo::MakeRequest(&url_loader_), start_info_->routing_id,
+ start_info_->request_id, start_info_->options,
+ *start_info_->url_request,
+ client_binding_.CreateInterfacePtrAndBind(
+ std::move(start_info_->task_runner)));
+
+ if (priority_info_) {
+ auto priority_info = std::move(priority_info_);
+ url_loader_->SetPriority(priority_info->priority,
+ priority_info->intra_priority_value);
}
break;
}
case DEFERRED_REDIRECT: {
client_binding_.ResumeIncomingMethodCallProcessing();
- forwarding_client_->OnReceiveRedirect(redirect_info_, response_head_);
+ forwarding_client_->OnReceiveRedirect(redirect_info_->redirect_info,
+ redirect_info_->response_head);
break;
}
case DEFERRED_RESPONSE: {
client_binding_.ResumeIncomingMethodCallProcessing();
- forwarding_client_->OnReceiveResponse(response_head_, ssl_info_,
- std::move(downloaded_file_));
+ forwarding_client_->OnReceiveResponse(
+ response_info_->response_head, response_info_->ssl_info,
+ std::move(response_info_->downloaded_file));
break;
}
default:
« no previous file with comments | « content/common/throttling_url_loader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698