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

Unified Diff: content/child/web_url_loader_impl.cc

Issue 1366883002: [Reland] Post loading tasks on the appropriate WebFrameScheduler's queue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a clone method to WebTaskRunner which lets us solve the lifetime issue. Created 5 years, 3 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
Index: content/child/web_url_loader_impl.cc
diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc
index 83c9ad5b64db596b8d5e7941f2c8abb3ea6ea493..e05e6ef28614408ebd6c49097f21b3310d294f8f 100644
--- a/content/child/web_url_loader_impl.cc
+++ b/content/child/web_url_loader_impl.cc
@@ -16,6 +16,7 @@
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "components/mime_util/mime_util.h"
+#include "components/scheduler/child/web_task_runner_impl.h"
#include "content/child/child_thread_impl.h"
#include "content/child/ftp_directory_listing_response_delegate.h"
#include "content/child/multipart_response_delegate.h"
@@ -42,6 +43,7 @@
#include "net/ssl/ssl_connection_status_flags.h"
#include "net/url_request/url_request_data_job.h"
#include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h"
+#include "third_party/WebKit/public/platform/WebTraceLocation.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/platform/WebURLLoadTiming.h"
@@ -254,7 +256,7 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>,
public:
Context(WebURLLoaderImpl* loader,
ResourceDispatcher* resource_dispatcher,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
+ blink::WebTaskRunner* task_runner);
Sami 2015/09/29 11:22:46 scoped_ptr here too?
alex clarke (OOO till 29th) 2015/09/29 16:10:36 Done.
WebURLLoaderClient* client() const { return client_; }
void set_client(WebURLLoaderClient* client) { client_ = client; }
@@ -267,6 +269,8 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>,
blink::WebThreadedDataReceiver* threaded_data_receiver);
void Start(const WebURLRequest& request,
SyncLoadResponse* sync_load_response);
+ // Takes owbership of |task_runner|.
+ void SetWebTaskRunner(blink::WebTaskRunner* task_runner);
Sami 2015/09/29 11:22:46 Could this be a scoped_ptr? This would mean the ca
alex clarke (OOO till 29th) 2015/09/29 16:10:36 Done, but It already did call clone.
// RequestPeer methods:
void OnUploadProgress(uint64 position, uint64 size) override;
@@ -295,6 +299,18 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>,
friend class base::RefCounted<Context>;
~Context() override;
+ class HandleDataURLTask : public blink::WebTaskRunner::Task {
+ public:
+ explicit HandleDataURLTask(Context* context) : context_(context) {}
+
+ void run() override {
+ context_->HandleDataURL();
+ }
+
+ private:
+ scoped_refptr<Context> context_;
+ };
+
// Called when the body data stream is detached from the reader side.
void CancelBodyStreaming();
// We can optimize the handling of data URLs in most cases.
@@ -305,7 +321,7 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>,
WebURLRequest request_;
WebURLLoaderClient* client_;
ResourceDispatcher* resource_dispatcher_;
- scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ scoped_ptr<blink::WebTaskRunner> web_task_runner_;
WebReferrerPolicy referrer_policy_;
scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
@@ -319,11 +335,11 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>,
WebURLLoaderImpl::Context::Context(
WebURLLoaderImpl* loader,
ResourceDispatcher* resource_dispatcher,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
+ blink::WebTaskRunner* web_task_runner)
: loader_(loader),
client_(NULL),
resource_dispatcher_(resource_dispatcher),
- task_runner_(task_runner),
+ web_task_runner_(web_task_runner),
referrer_policy_(blink::WebReferrerPolicyDefault),
defers_loading_(NOT_DEFERRING),
request_id_(-1) {
@@ -359,8 +375,9 @@ void WebURLLoaderImpl::Context::SetDefersLoading(bool value) {
defers_loading_ = SHOULD_DEFER;
} else if (!value && defers_loading_ != NOT_DEFERRING) {
if (defers_loading_ == DEFERRED_DATA) {
- task_runner_->PostTask(FROM_HERE,
- base::Bind(&Context::HandleDataURL, this));
+ web_task_runner_->postTask(
+ ::blink::WebTraceLocation(__FUNCTION__, __FILE__),
Sami 2015/09/29 11:22:46 Ditto about FROM_HERE
alex clarke (OOO till 29th) 2015/09/29 16:10:36 Done.
+ new HandleDataURLTask(this));
}
defers_loading_ = NOT_DEFERRING;
}
@@ -418,8 +435,9 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
GetInfoFromDataURL(sync_load_response->url, sync_load_response,
&sync_load_response->data);
} else {
- task_runner_->PostTask(FROM_HERE,
- base::Bind(&Context::HandleDataURL, this));
+ web_task_runner_->postTask(
+ ::blink::WebTraceLocation(__FUNCTION__, __FILE__),
Sami 2015/09/29 11:22:47 Ditto.
alex clarke (OOO till 29th) 2015/09/29 16:10:36 Done.
+ new HandleDataURLTask(this));
}
return;
}
@@ -482,6 +500,7 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
GetRequestContextFrameTypeForWebURLRequest(request);
request_info.extra_data = request.extraData();
request_info.report_raw_headers = request.reportRawHeaders();
+ request_info.loading_web_task_runner = web_task_runner_.get();
Sami 2015/09/29 11:22:46 nit: s/get/Pass/
alex clarke (OOO till 29th) 2015/09/29 16:10:36 Needs to be a clone().
scoped_refptr<ResourceRequestBody> request_body =
GetRequestBodyForWebURLRequest(request).get();
@@ -496,6 +515,11 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
request_info, request_body.get(), this);
}
+void WebURLLoaderImpl::Context::SetWebTaskRunner(
+ blink::WebTaskRunner* web_task_runner) {
+ web_task_runner_.reset(web_task_runner);
+}
+
void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) {
if (client_)
client_->didSendData(loader_, position, size);
@@ -841,8 +865,8 @@ void WebURLLoaderImpl::Context::HandleDataURL() {
WebURLLoaderImpl::WebURLLoaderImpl(
ResourceDispatcher* resource_dispatcher,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : context_(new Context(this, resource_dispatcher, task_runner)) {
+ blink::WebTaskRunner* web_task_runner)
+ : context_(new Context(this, resource_dispatcher, web_task_runner)) {
}
WebURLLoaderImpl::~WebURLLoaderImpl() {
@@ -1059,4 +1083,11 @@ bool WebURLLoaderImpl::attachThreadedDataReceiver(
return context_->AttachThreadedDataReceiver(threaded_data_receiver);
}
+void WebURLLoaderImpl::setLoadingTaskRunner(
+ blink::WebTaskRunner* loading_task_runner) {
+ // There's no guarantee on the lifetime of |loading_task_runner| so we take a
+ // copy.
+ context_->SetWebTaskRunner(loading_task_runner->clone());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698