Commit a49b0582 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Don't crash when UI is shutdown (cont)

The fix at r662120
https://chromium-review.googlesource.com/c/chromium/src/+/1624074 was
insufficient to stop the bot failures. Convert more PostTaskWithTraits
to using a TaskRunner instead.

Bug: 963702
Change-Id: I57768cc53e9c6069acba19590a1dcbae19eda4a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626195Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662482}
parent 9f25eee5
...@@ -375,18 +375,20 @@ class EmbeddedWorkerInstance::WorkerProcessHandle { ...@@ -375,18 +375,20 @@ class EmbeddedWorkerInstance::WorkerProcessHandle {
WorkerProcessHandle( WorkerProcessHandle(
const base::WeakPtr<ServiceWorkerProcessManager>& process_manager, const base::WeakPtr<ServiceWorkerProcessManager>& process_manager,
int embedded_worker_id, int embedded_worker_id,
int process_id) int process_id,
scoped_refptr<base::SequencedTaskRunner> ui_task_runner)
: process_manager_(process_manager), : process_manager_(process_manager),
embedded_worker_id_(embedded_worker_id), embedded_worker_id_(embedded_worker_id),
process_id_(process_id) { process_id_(process_id),
ui_task_runner_(std::move(ui_task_runner)) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id_); DCHECK_NE(ChildProcessHost::kInvalidUniqueID, process_id_);
} }
~WorkerProcessHandle() { ~WorkerProcessHandle() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
base::PostTaskWithTraits( ui_task_runner_->PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE,
base::BindOnce(&ServiceWorkerProcessManager::ReleaseWorkerProcess, base::BindOnce(&ServiceWorkerProcessManager::ReleaseWorkerProcess,
process_manager_, embedded_worker_id_)); process_manager_, embedded_worker_id_));
} }
...@@ -399,6 +401,7 @@ class EmbeddedWorkerInstance::WorkerProcessHandle { ...@@ -399,6 +401,7 @@ class EmbeddedWorkerInstance::WorkerProcessHandle {
const int embedded_worker_id_; const int embedded_worker_id_;
const int process_id_; const int process_id_;
const scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
DISALLOW_COPY_AND_ASSIGN(WorkerProcessHandle); DISALLOW_COPY_AND_ASSIGN(WorkerProcessHandle);
}; };
...@@ -450,8 +453,8 @@ class EmbeddedWorkerInstance::StartTask { ...@@ -450,8 +453,8 @@ class EmbeddedWorkerInstance::StartTask {
break; break;
case ProcessAllocationState::ALLOCATING: case ProcessAllocationState::ALLOCATING:
// Abort half-baked process allocation on the UI thread. // Abort half-baked process allocation on the UI thread.
base::PostTaskWithTraits( instance_->ui_task_runner_->PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE,
base::BindOnce(&ServiceWorkerProcessManager::ReleaseWorkerProcess, base::BindOnce(&ServiceWorkerProcessManager::ReleaseWorkerProcess,
instance_->context_->process_manager()->AsWeakPtr(), instance_->context_->process_manager()->AsWeakPtr(),
instance_->embedded_worker_id())); instance_->embedded_worker_id()));
...@@ -510,8 +513,8 @@ class EmbeddedWorkerInstance::StartTask { ...@@ -510,8 +513,8 @@ class EmbeddedWorkerInstance::StartTask {
// Hop to the UI thread for process allocation and setup. We will continue // Hop to the UI thread for process allocation and setup. We will continue
// on the IO thread in StartTask::OnSetupCompleted(). // on the IO thread in StartTask::OnSetupCompleted().
base::PostTaskWithTraits( instance_->ui_task_runner_->PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE,
base::BindOnce( base::BindOnce(
&SetupOnUIThread, instance_->embedded_worker_id(), process_manager, &SetupOnUIThread, instance_->embedded_worker_id(), process_manager,
can_use_existing_process, std::move(params), std::move(request_), can_use_existing_process, std::move(params), std::move(request_),
...@@ -543,7 +546,7 @@ class EmbeddedWorkerInstance::StartTask { ...@@ -543,7 +546,7 @@ class EmbeddedWorkerInstance::StartTask {
// returning to ensure the process is eventually released. // returning to ensure the process is eventually released.
process_handle = std::make_unique<WorkerProcessHandle>( process_handle = std::make_unique<WorkerProcessHandle>(
process_manager, instance_->embedded_worker_id(), process_manager, instance_->embedded_worker_id(),
process_info->process_id); process_info->process_id, instance_->ui_task_runner_);
if (!instance_->context_) if (!instance_->context_)
status = blink::ServiceWorkerStatusCode::kErrorAbort; status = blink::ServiceWorkerStatusCode::kErrorAbort;
...@@ -728,6 +731,8 @@ EmbeddedWorkerInstance::EmbeddedWorkerInstance( ...@@ -728,6 +731,8 @@ EmbeddedWorkerInstance::EmbeddedWorkerInstance(
devtools_attached_(false), devtools_attached_(false),
network_accessed_for_script_(false), network_accessed_for_script_(false),
foreground_notified_(false), foreground_notified_(false),
ui_task_runner_(
base::CreateSequencedTaskRunnerWithTraits({BrowserThread::UI})),
weak_factory_(this) { weak_factory_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(context_); DCHECK(context_);
...@@ -1180,10 +1185,9 @@ void EmbeddedWorkerInstance::NotifyForegroundServiceWorkerAdded() { ...@@ -1180,10 +1185,9 @@ void EmbeddedWorkerInstance::NotifyForegroundServiceWorkerAdded() {
foreground_notified_ = true; foreground_notified_ = true;
base::PostTaskWithTraits( ui_task_runner_->PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, base::BindOnce(&NotifyForegroundServiceWorkerOnUIThread,
base::BindOnce(&NotifyForegroundServiceWorkerOnUIThread, true /* added */, true /* added */, process_id()));
process_id()));
} }
void EmbeddedWorkerInstance::NotifyForegroundServiceWorkerRemoved() { void EmbeddedWorkerInstance::NotifyForegroundServiceWorkerRemoved() {
...@@ -1197,10 +1201,9 @@ void EmbeddedWorkerInstance::NotifyForegroundServiceWorkerRemoved() { ...@@ -1197,10 +1201,9 @@ void EmbeddedWorkerInstance::NotifyForegroundServiceWorkerRemoved() {
foreground_notified_ = false; foreground_notified_ = false;
base::PostTaskWithTraits( ui_task_runner_->PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE, base::BindOnce(&NotifyForegroundServiceWorkerOnUIThread,
base::BindOnce(&NotifyForegroundServiceWorkerOnUIThread, false /* added */, process_id()));
false /* added */, process_id()));
} }
network::mojom::URLLoaderFactoryPtrInfo network::mojom::URLLoaderFactoryPtrInfo
......
...@@ -361,6 +361,8 @@ class CONTENT_EXPORT EmbeddedWorkerInstance ...@@ -361,6 +361,8 @@ class CONTENT_EXPORT EmbeddedWorkerInstance
mojo::StrongBindingPtr<network::mojom::URLLoaderFactory> mojo::StrongBindingPtr<network::mojom::URLLoaderFactory>
script_loader_factory_; script_loader_factory_;
const scoped_refptr<base::SequencedTaskRunner> ui_task_runner_;
base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
......
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