Commit 50039cd3 authored by tzik's avatar tzik Committed by Commit Bot

Avoid touching extensions::ContentVerifyJob's ref count before it's fully constructed

extensions::ContentVerifyJob is ref counted, and its first reference may
be implicitly created in ContentVerifyJob::Start through base::BindOnce.
However, after an upcoming change to base::Bind, it starts rejecting to
make the implicit first reference to a ref-counted object, as this is
an error prone pattern.

This CL updates callers of ContentVerifyJob::Start to hold to hold the
first reference, before Start() is called.

Bug: 866456
Change-Id: Ib3a70973ac789f60a75e636db03f4e4d66e12603
Reviewed-on: https://chromium-review.googlesource.com/1156704Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579653}
parent ee5b9bf7
...@@ -196,7 +196,7 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { ...@@ -196,7 +196,7 @@ class URLRequestExtensionJob : public net::URLRequestFileJob {
const std::string& content_security_policy, const std::string& content_security_policy,
bool send_cors_header, bool send_cors_header,
bool follow_symlinks_anywhere, bool follow_symlinks_anywhere,
ContentVerifyJob* verify_job) scoped_refptr<ContentVerifyJob> verify_job)
: net::URLRequestFileJob( : net::URLRequestFileJob(
request, request,
network_delegate, network_delegate,
...@@ -204,7 +204,7 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { ...@@ -204,7 +204,7 @@ class URLRequestExtensionJob : public net::URLRequestFileJob {
base::CreateTaskRunnerWithTraits( base::CreateTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT, {base::MayBlock(), base::TaskPriority::BEST_EFFORT,
base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})), base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})),
verify_job_(verify_job), verify_job_(std::move(verify_job)),
seek_position_(0), seek_position_(0),
bytes_read_(0), bytes_read_(0),
directory_path_(directory_path), directory_path_(directory_path),
...@@ -643,7 +643,7 @@ ExtensionProtocolHandler::MaybeCreateJob( ...@@ -643,7 +643,7 @@ ExtensionProtocolHandler::MaybeCreateJob(
if (g_test_handler) if (g_test_handler)
g_test_handler->Run(&directory_path, &relative_path); g_test_handler->Run(&directory_path, &relative_path);
ContentVerifyJob* verify_job = nullptr; scoped_refptr<ContentVerifyJob> verify_job;
ContentVerifier* verifier = extension_info_map_->content_verifier(); ContentVerifier* verifier = extension_info_map_->content_verifier();
if (verifier) { if (verifier) {
verify_job = verify_job =
...@@ -652,15 +652,10 @@ ExtensionProtocolHandler::MaybeCreateJob( ...@@ -652,15 +652,10 @@ ExtensionProtocolHandler::MaybeCreateJob(
verify_job->Start(verifier); verify_job->Start(verifier);
} }
return new URLRequestExtensionJob(request, return new URLRequestExtensionJob(
network_delegate, request, network_delegate, extension_id, directory_path, relative_path,
extension_id, content_security_policy, send_cors_header, follow_symlinks_anywhere,
directory_path, std::move(verify_job));
relative_path,
content_security_policy,
send_cors_header,
follow_symlinks_anywhere,
verify_job);
} }
bool ExtensionProtocolHandler::IsSafeRedirectTarget( bool ExtensionProtocolHandler::IsSafeRedirectTarget(
...@@ -962,7 +957,7 @@ class ExtensionURLLoaderFactory : public network::mojom::URLLoaderFactory { ...@@ -962,7 +957,7 @@ class ExtensionURLLoaderFactory : public network::mojom::URLLoaderFactory {
scoped_refptr<ContentVerifier> content_verifier, scoped_refptr<ContentVerifier> content_verifier,
const ExtensionResource& resource, const ExtensionResource& resource,
scoped_refptr<net::HttpResponseHeaders> response_headers) { scoped_refptr<net::HttpResponseHeaders> response_headers) {
ContentVerifyJob* verify_job = nullptr; scoped_refptr<ContentVerifyJob> verify_job;
if (content_verifier) { if (content_verifier) {
verify_job = content_verifier->CreateJobFor(resource.extension_id(), verify_job = content_verifier->CreateJobFor(resource.extension_id(),
resource.extension_root(), resource.extension_root(),
...@@ -973,7 +968,7 @@ class ExtensionURLLoaderFactory : public network::mojom::URLLoaderFactory { ...@@ -973,7 +968,7 @@ class ExtensionURLLoaderFactory : public network::mojom::URLLoaderFactory {
content::CreateFileURLLoader( content::CreateFileURLLoader(
request, std::move(loader), std::move(client), request, std::move(loader), std::move(client),
std::make_unique<FileLoaderObserver>(verify_job), std::make_unique<FileLoaderObserver>(std::move(verify_job)),
std::move(response_headers)); std::move(response_headers));
} }
......
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