Commit 8d8db0e0 authored by Matt Falkenhagen's avatar Matt Falkenhagen Committed by Commit Bot

service worker: Don't crash when UI thread is shutdown.

In some tests, the DevToolsProxy can destruct after the UI thread shuts
down, so PostTaskWithTraits crashes. Use a TaskRunner instead, which
safely does nothing in that case.

Bug: 963702
Change-Id: I46a1647a9cfddd25ca0354fc95d4cbc4b43211a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1624074Reviewed-by: default avatarAlex Clarke <alexclarke@chromium.org>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662120}
parent 25591d8d
...@@ -293,21 +293,23 @@ class EmbeddedWorkerInstance::DevToolsProxy { ...@@ -293,21 +293,23 @@ class EmbeddedWorkerInstance::DevToolsProxy {
public: public:
DevToolsProxy(int process_id, int agent_route_id) DevToolsProxy(int process_id, int agent_route_id)
: process_id_(process_id), : process_id_(process_id),
agent_route_id_(agent_route_id) {} agent_route_id_(agent_route_id),
ui_task_runner_(
base::CreateSequencedTaskRunnerWithTraits({BrowserThread::UI})) {}
~DevToolsProxy() { ~DevToolsProxy() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, ui_task_runner_->PostTask(
base::BindOnce(NotifyWorkerDestroyedOnUI, FROM_HERE, base::BindOnce(NotifyWorkerDestroyedOnUI, process_id_,
process_id_, agent_route_id_)); agent_route_id_));
} }
void NotifyWorkerReadyForInspection( void NotifyWorkerReadyForInspection(
blink::mojom::DevToolsAgentHostAssociatedRequest host_request, blink::mojom::DevToolsAgentHostAssociatedRequest host_request,
blink::mojom::DevToolsAgentAssociatedPtrInfo devtools_agent_ptr_info) { blink::mojom::DevToolsAgentAssociatedPtrInfo devtools_agent_ptr_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PostTaskWithTraits( ui_task_runner_->PostTask(
FROM_HERE, {BrowserThread::UI}, FROM_HERE,
base::BindOnce(NotifyWorkerReadyForInspectionOnUI, process_id_, base::BindOnce(NotifyWorkerReadyForInspectionOnUI, process_id_,
agent_route_id_, std::move(host_request), agent_route_id_, std::move(host_request),
std::move(devtools_agent_ptr_info))); std::move(devtools_agent_ptr_info)));
...@@ -315,16 +317,16 @@ class EmbeddedWorkerInstance::DevToolsProxy { ...@@ -315,16 +317,16 @@ class EmbeddedWorkerInstance::DevToolsProxy {
void NotifyWorkerVersionInstalled() { void NotifyWorkerVersionInstalled() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, ui_task_runner_->PostTask(
base::BindOnce(NotifyWorkerVersionInstalledOnUI, FROM_HERE, base::BindOnce(NotifyWorkerVersionInstalledOnUI, process_id_,
process_id_, agent_route_id_)); agent_route_id_));
} }
void NotifyWorkerVersionDoomed() { void NotifyWorkerVersionDoomed() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, ui_task_runner_->PostTask(
base::BindOnce(NotifyWorkerVersionDoomedOnUI, FROM_HERE, base::BindOnce(NotifyWorkerVersionDoomedOnUI, process_id_,
process_id_, agent_route_id_)); agent_route_id_));
} }
bool ShouldNotifyWorkerStopIgnored() const { bool ShouldNotifyWorkerStopIgnored() const {
...@@ -338,6 +340,7 @@ class EmbeddedWorkerInstance::DevToolsProxy { ...@@ -338,6 +340,7 @@ class EmbeddedWorkerInstance::DevToolsProxy {
private: private:
const int process_id_; const int process_id_;
const int agent_route_id_; const int agent_route_id_;
const scoped_refptr<base::TaskRunner> ui_task_runner_;
bool worker_stop_ignored_notified_ = false; bool worker_stop_ignored_notified_ = false;
DISALLOW_COPY_AND_ASSIGN(DevToolsProxy); DISALLOW_COPY_AND_ASSIGN(DevToolsProxy);
......
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