Commit 2ddb3786 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worker: Clean up WebSharedWorkerImpl::TerminateWorkerThread()

In WebSharedWorkerImpl::TerminateWorkerThread(), following if-conditions

  (1) if (shadow_page_ && !shadow_page_->WasInitialized())
  (2) if (worker_thread_)

are mutually exclusive, so we don't have to check the both conditions.

Bug: 987850
Change-Id: Ibfac267d4ed684966853c606a09ab2fd8bb31e05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1734733Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683931}
parent d4253abf
...@@ -96,7 +96,8 @@ void WebSharedWorkerImpl::TerminateWorkerThread() { ...@@ -96,7 +96,8 @@ void WebSharedWorkerImpl::TerminateWorkerThread() {
return; return;
asked_to_terminate_ = true; asked_to_terminate_ = true;
appcache_host_->Detach(); appcache_host_->Detach();
if (shadow_page_ && !shadow_page_->WasInitialized()) {
if (!worker_thread_) {
client_->WorkerScriptLoadFailed(); client_->WorkerScriptLoadFailed();
// The worker thread hasn't been started yet. Immediately notify the client // The worker thread hasn't been started yet. Immediately notify the client
// of worker termination. // of worker termination.
...@@ -104,11 +105,10 @@ void WebSharedWorkerImpl::TerminateWorkerThread() { ...@@ -104,11 +105,10 @@ void WebSharedWorkerImpl::TerminateWorkerThread() {
// |this| is deleted at this point. // |this| is deleted at this point.
return; return;
} }
if (worker_thread_) { worker_thread_->Terminate();
worker_thread_->Terminate(); DevToolsAgent::WorkerThreadTerminated(shadow_page_->GetDocument(),
DevToolsAgent::WorkerThreadTerminated(shadow_page_->GetDocument(), worker_thread_.get());
worker_thread_.get()); // DidTerminateWorkerThread() will be called asynchronously.
}
} }
void WebSharedWorkerImpl::OnShadowPageInitialized() { void WebSharedWorkerImpl::OnShadowPageInitialized() {
...@@ -159,6 +159,7 @@ void WebSharedWorkerImpl::DidCloseWorkerGlobalScope() { ...@@ -159,6 +159,7 @@ void WebSharedWorkerImpl::DidCloseWorkerGlobalScope() {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
client_->WorkerContextClosed(); client_->WorkerContextClosed();
TerminateWorkerThread(); TerminateWorkerThread();
// DidTerminateWorkerThread() will be called asynchronously.
} }
void WebSharedWorkerImpl::DidTerminateWorkerThread() { void WebSharedWorkerImpl::DidTerminateWorkerThread() {
......
...@@ -71,7 +71,9 @@ class WebURL; ...@@ -71,7 +71,9 @@ class WebURL;
// methods must be called from a worker thread. Such methods are suffixed with // methods must be called from a worker thread. Such methods are suffixed with
// *OnWorkerThread or have header comments. // *OnWorkerThread or have header comments.
// //
// Owned by WebSharedWorkerClient. // Owned by WebSharedWorkerClient. Destroyed in TerminateWorkerThread() or
// DidTerminateWorkerThread() via
// WebSharedWorkerClient::WorkerContextDestroyed().
class CORE_EXPORT WebSharedWorkerImpl final : public WebSharedWorker, class CORE_EXPORT WebSharedWorkerImpl final : public WebSharedWorker,
public WorkerShadowPage::Client { public WorkerShadowPage::Client {
public: public:
...@@ -116,12 +118,13 @@ class CORE_EXPORT WebSharedWorkerImpl final : public WebSharedWorker, ...@@ -116,12 +118,13 @@ class CORE_EXPORT WebSharedWorkerImpl final : public WebSharedWorker,
void DidFailToFetchClassicScript(); void DidFailToFetchClassicScript();
void DidEvaluateClassicScript(bool success); void DidEvaluateClassicScript(bool success);
void DidCloseWorkerGlobalScope(); void DidCloseWorkerGlobalScope();
// This synchronously destroys |this|.
void DidTerminateWorkerThread(); void DidTerminateWorkerThread();
private: private:
SharedWorkerThread* GetWorkerThread() { return worker_thread_.get(); } SharedWorkerThread* GetWorkerThread() { return worker_thread_.get(); }
// Shuts down the worker thread. // Shuts down the worker thread. This may synchronously destroy |this|.
void TerminateWorkerThread(); void TerminateWorkerThread();
void OnAppCacheSelected(); void OnAppCacheSelected();
......
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