| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" | 66 #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h" |
| 67 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h" | 67 #include "public/web/modules/serviceworker/WebServiceWorkerNetworkProvider.h" |
| 68 #include "web/IndexedDBClientImpl.h" | 68 #include "web/IndexedDBClientImpl.h" |
| 69 #include "web/ServiceWorkerGlobalScopeClientImpl.h" | 69 #include "web/ServiceWorkerGlobalScopeClientImpl.h" |
| 70 #include "web/ServiceWorkerGlobalScopeProxy.h" | 70 #include "web/ServiceWorkerGlobalScopeProxy.h" |
| 71 #include "web/WebDataSourceImpl.h" | 71 #include "web/WebDataSourceImpl.h" |
| 72 #include "web/WebLocalFrameImpl.h" | 72 #include "web/WebLocalFrameImpl.h" |
| 73 #include "web/WorkerContentSettingsClient.h" | 73 #include "web/WorkerContentSettingsClient.h" |
| 74 #include "wtf/Functional.h" | 74 #include "wtf/Functional.h" |
| 75 #include "wtf/PtrUtil.h" | 75 #include "wtf/PtrUtil.h" |
| 76 #include "wtf/WTF.h" |
| 76 #include <memory> | 77 #include <memory> |
| 77 | 78 |
| 78 namespace blink { | 79 namespace blink { |
| 79 | 80 |
| 80 WebEmbeddedWorker* WebEmbeddedWorker::create(WebServiceWorkerContextClient* clie
nt, WebWorkerContentSettingsClientProxy* contentSettingsClient) | 81 WebEmbeddedWorker* WebEmbeddedWorker::create(WebServiceWorkerContextClient* clie
nt, WebWorkerContentSettingsClientProxy* contentSettingsClient) |
| 81 { | 82 { |
| 82 return new WebEmbeddedWorkerImpl(wrapUnique(client), wrapUnique(contentSetti
ngsClient)); | 83 return new WebEmbeddedWorkerImpl(wrapUnique(client), wrapUnique(contentSetti
ngsClient)); |
| 83 } | 84 } |
| 84 | 85 |
| 85 static HashSet<WebEmbeddedWorkerImpl*>& runningWorkerInstances() | 86 static HashSet<WebEmbeddedWorkerImpl*>& runningWorkerInstances() |
| 86 { | 87 { |
| 87 DEFINE_STATIC_LOCAL(HashSet<WebEmbeddedWorkerImpl*>, set, ()); | 88 DEFINE_STATIC_LOCAL(HashSet<WebEmbeddedWorkerImpl*>, set, ()); |
| 88 return set; | 89 return set; |
| 89 } | 90 } |
| 90 | 91 |
| 91 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl(std::unique_ptr<WebServiceWorkerCon
textClient> client, std::unique_ptr<WebWorkerContentSettingsClientProxy> content
SettingsClient) | 92 WebEmbeddedWorkerImpl::WebEmbeddedWorkerImpl(std::unique_ptr<WebServiceWorkerCon
textClient> client, std::unique_ptr<WebWorkerContentSettingsClientProxy> content
SettingsClient) |
| 92 : m_workerContextClient(std::move(client)) | 93 : m_workerContextClient(std::move(client)) |
| 93 , m_contentSettingsClient(std::move(contentSettingsClient)) | 94 , m_contentSettingsClient(std::move(contentSettingsClient)) |
| 94 , m_workerInspectorProxy(WorkerInspectorProxy::create()) | 95 , m_workerInspectorProxy(WorkerInspectorProxy::create()) |
| 95 , m_webView(nullptr) | 96 , m_webView(nullptr) |
| 96 , m_mainFrame(nullptr) | 97 , m_mainFrame(nullptr) |
| 97 , m_loadingShadowPage(false) | 98 , m_loadingShadowPage(false) |
| 98 , m_askedToTerminate(false) | 99 , m_askedToTerminate(false) |
| 99 , m_pauseAfterDownloadState(DontPauseAfterDownload) | 100 , m_pauseAfterDownloadState(DontPauseAfterDownload) |
| 100 , m_waitingForDebuggerState(NotWaitingForDebugger) | 101 , m_waitingForDebuggerState(NotWaitingForDebugger) |
| 101 { | 102 { |
| 103 DCHECK(isMainThread()); |
| 102 runningWorkerInstances().add(this); | 104 runningWorkerInstances().add(this); |
| 103 } | 105 } |
| 104 | 106 |
| 105 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() | 107 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() |
| 106 { | 108 { |
| 107 // Prevent onScriptLoaderFinished from deleting 'this'. | 109 DCHECK(isMainThread()); |
| 108 m_askedToTerminate = true; | |
| 109 | 110 |
| 110 if (m_workerThread) | 111 // Worker thread termination must be done before this point. |
| 111 m_workerThread->terminateAndWait(); | 112 DCHECK(m_askedToTerminate); |
| 112 | 113 |
| 113 DCHECK(runningWorkerInstances().contains(this)); | 114 DCHECK(runningWorkerInstances().contains(this)); |
| 114 runningWorkerInstances().remove(this); | 115 runningWorkerInstances().remove(this); |
| 115 DCHECK(m_webView); | 116 DCHECK(m_webView); |
| 116 | 117 |
| 117 // Detach the client before closing the view to avoid getting called back. | 118 // Detach the client before closing the view to avoid getting called back. |
| 118 m_mainFrame->setClient(0); | 119 m_mainFrame->setClient(0); |
| 119 | 120 |
| 120 if (m_workerGlobalScopeProxy) { | 121 if (m_workerGlobalScopeProxy) { |
| 121 m_workerGlobalScopeProxy->detach(); | 122 m_workerGlobalScopeProxy->detach(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 if (data.pauseAfterDownloadMode == WebEmbeddedWorkerStartData::PauseAfterDow
nload) | 155 if (data.pauseAfterDownloadMode == WebEmbeddedWorkerStartData::PauseAfterDow
nload) |
| 155 m_pauseAfterDownloadState = DoPauseAfterDownload; | 156 m_pauseAfterDownloadState = DoPauseAfterDownload; |
| 156 prepareShadowPageForLoader(); | 157 prepareShadowPageForLoader(); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void WebEmbeddedWorkerImpl::terminateWorkerContext() | 160 void WebEmbeddedWorkerImpl::terminateWorkerContext() |
| 160 { | 161 { |
| 161 if (m_askedToTerminate) | 162 if (m_askedToTerminate) |
| 162 return; | 163 return; |
| 163 m_askedToTerminate = true; | 164 m_askedToTerminate = true; |
| 164 if (m_loadingShadowPage) { | 165 |
| 165 // This deletes 'this'. | 166 if (m_workerThread) { |
| 166 m_workerContextClient->workerContextFailedToStart(); | 167 m_workerThread->terminate(); |
| 168 m_workerInspectorProxy->workerThreadTerminated(); |
| 169 // WebServiceWorkerContextClient::workerContextDestroyed() that deletes |
| 170 // 'this' will be called after worker thread termination is done. |
| 167 return; | 171 return; |
| 168 } | 172 } |
| 173 |
| 169 if (m_mainScriptLoader) { | 174 if (m_mainScriptLoader) { |
| 170 m_mainScriptLoader->cancel(); | 175 m_mainScriptLoader->cancel(); |
| 171 m_mainScriptLoader.clear(); | 176 m_mainScriptLoader.clear(); |
| 172 // This deletes 'this'. | |
| 173 m_workerContextClient->workerContextFailedToStart(); | |
| 174 return; | |
| 175 } | 177 } |
| 176 if (!m_workerThread) { | 178 |
| 177 // The worker thread has not been created yet if the worker is asked to | 179 // This deletes 'this'. |
| 178 // terminate during waiting for debugger or paused after download. | 180 m_workerContextClient->workerContextFailedToStart(); |
| 179 DCHECK(m_workerStartData.waitForDebuggerMode == WebEmbeddedWorkerStartDa
ta::WaitForDebugger || m_pauseAfterDownloadState == IsPausedAfterDownload); | |
| 180 // This deletes 'this'. | |
| 181 m_workerContextClient->workerContextFailedToStart(); | |
| 182 return; | |
| 183 } | |
| 184 m_workerThread->terminate(); | |
| 185 m_workerInspectorProxy->workerThreadTerminated(); | |
| 186 } | 181 } |
| 187 | 182 |
| 188 void WebEmbeddedWorkerImpl::resumeAfterDownload() | 183 void WebEmbeddedWorkerImpl::resumeAfterDownload() |
| 189 { | 184 { |
| 190 DCHECK(!m_askedToTerminate); | 185 DCHECK(!m_askedToTerminate); |
| 191 DCHECK_EQ(m_pauseAfterDownloadState, IsPausedAfterDownload); | 186 DCHECK_EQ(m_pauseAfterDownloadState, IsPausedAfterDownload); |
| 192 | 187 |
| 193 m_pauseAfterDownloadState = DontPauseAfterDownload; | 188 m_pauseAfterDownloadState = DontPauseAfterDownload; |
| 194 startWorkerThread(); | 189 startWorkerThread(); |
| 195 } | 190 } |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 m_mainThreadTaskRunners = ParentFrameTaskRunners::create(nullptr); | 439 m_mainThreadTaskRunners = ParentFrameTaskRunners::create(nullptr); |
| 445 | 440 |
| 446 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); | 441 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); |
| 447 m_loaderProxy = WorkerLoaderProxy::create(this); | 442 m_loaderProxy = WorkerLoaderProxy::create(this); |
| 448 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy); | 443 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy); |
| 449 m_workerThread->start(std::move(startupData)); | 444 m_workerThread->start(std::move(startupData)); |
| 450 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); | 445 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); |
| 451 } | 446 } |
| 452 | 447 |
| 453 } // namespace blink | 448 } // namespace blink |
| OLD | NEW |