Changeset 224306 in webkit
- Timestamp:
- Nov 1, 2017 4:24:31 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r224305 r224306 1 2017-11-01 Chris Dumez <cdumez@apple.com> 2 3 Drop running Service Worker Jobs on a background thread 4 https://bugs.webkit.org/show_bug.cgi?id=179142 5 6 Reviewed by Youenn Fablet. 7 8 Drop running Service Worker Jobs on a background thread. We don't really need to 9 and this simplifies the logic a lot. 10 11 * workers/service/server/SWServer.cpp: 12 (WebCore::SWServer::getRegistration): 13 (WebCore::SWServer::addRegistration): 14 (WebCore::SWServer::removeRegistration): 15 * workers/service/server/SWServerJobQueue.cpp: 16 (WebCore::SWServerJobQueue::scriptContextStarted): 17 (WebCore::SWServerJobQueue::startNextJob): 18 (WebCore::SWServerJobQueue::runRegisterJob): 19 (WebCore::SWServerJobQueue::runUnregisterJob): 20 (WebCore::SWServerJobQueue::runUpdateJob): 21 (WebCore::SWServerJobQueue::finishCurrentJob): 22 * workers/service/server/SWServerJobQueue.h: 23 1 24 2017-11-01 Per Arne Vollan <pvollan@apple.com> 2 25 -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r224301 r224306 73 73 SWServerRegistration* SWServer::getRegistration(const ServiceWorkerRegistrationKey& registrationKey) 74 74 { 75 ASSERT(!isMainThread());76 75 return m_registrations.get(registrationKey); 77 76 } … … 79 78 void SWServer::addRegistration(std::unique_ptr<SWServerRegistration>&& registration) 80 79 { 81 ASSERT(!isMainThread());82 80 auto key = registration->key(); 83 81 m_registrations.add(key, WTFMove(registration)); … … 86 84 void SWServer::removeRegistration(const ServiceWorkerRegistrationKey& registrationKey) 87 85 { 88 ASSERT(!isMainThread());89 86 m_registrations.remove(registrationKey); 90 87 } -
trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp
r224301 r224306 68 68 void SWServerJobQueue::scriptFetchFinished(SWServer::Connection& connection, const ServiceWorkerFetchResult& result) 69 69 { 70 ASSERT(isMainThread());71 70 ASSERT(m_currentJob && m_currentJob->identifier() == result.jobIdentifier); 72 71 … … 89 88 void SWServerJobQueue::scriptContextFailedToStart(SWServer::Connection&, const String& workerID, const String& message) 90 89 { 91 ASSERT(isMainThread());92 90 // FIXME: Install has failed. Run the install failed substeps 93 91 // Run the Update Worker State algorithm passing registration’s installing worker and redundant as the arguments. … … 101 99 void SWServerJobQueue::scriptContextStarted(SWServer::Connection&, uint64_t serviceWorkerIdentifier, const String& workerID) 102 100 { 103 ASSERT(isMainThread());104 101 UNUSED_PARAM(workerID); 105 102 106 m_server.postTask(createCrossThreadTask(*this, &SWServerJobQueue::resolveCurrentRegistrationJobOnMainThead, serviceWorkerIdentifier)); 103 auto* registration = m_server.getRegistration(m_registrationKey); 104 ASSERT(registration); 105 registration->setActiveServiceWorkerIdentifier(serviceWorkerIdentifier); 106 resolveCurrentRegistrationJob(registration->data()); 107 107 } 108 108 109 109 void SWServerJobQueue::startNextJob() 110 110 { 111 ASSERT(isMainThread());112 111 ASSERT(!m_currentJob); 113 112 ASSERT(!m_jobQueue.isEmpty()); 114 113 115 m_currentJob = std::make_unique<ServiceWorkerJobData>(m_jobQueue.takeFirst() .isolatedCopy());114 m_currentJob = std::make_unique<ServiceWorkerJobData>(m_jobQueue.takeFirst()); 116 115 117 116 switch (m_currentJob->type) { 118 117 case ServiceWorkerJobType::Register: 119 m_server.postTask(createCrossThreadTask(*this, &SWServerJobQueue::runRegisterJob, *m_currentJob));118 runRegisterJob(*m_currentJob); 120 119 return; 121 120 case ServiceWorkerJobType::Unregister: 122 m_server.postTask(createCrossThreadTask(*this, &SWServerJobQueue::runUnregisterJob, *m_currentJob));121 runUnregisterJob(*m_currentJob); 123 122 return; 124 123 } … … 129 128 void SWServerJobQueue::runRegisterJob(const ServiceWorkerJobData& job) 130 129 { 131 ASSERT(!isMainThread());132 130 ASSERT(job.type == ServiceWorkerJobType::Register); 133 131 134 132 if (!shouldTreatAsPotentiallyTrustworthy(job.scriptURL)) 135 return reject WithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Script URL is not potentially trustworthy") });133 return rejectCurrentJob(ExceptionData { SecurityError, ASCIILiteral("Script URL is not potentially trustworthy") }); 136 134 137 135 // If the origin of job’s script url is not job’s referrer's origin, then: 138 136 if (!protocolHostAndPortAreEqual(job.scriptURL, job.clientCreationURL)) 139 return reject WithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Script origin does not match the registering client's origin") });137 return rejectCurrentJob(ExceptionData { SecurityError, ASCIILiteral("Script origin does not match the registering client's origin") }); 140 138 141 139 // If the origin of job’s scope url is not job’s referrer's origin, then: 142 140 if (!protocolHostAndPortAreEqual(job.scopeURL, job.clientCreationURL)) 143 return reject WithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Scope origin does not match the registering client's origin") });141 return rejectCurrentJob(ExceptionData { SecurityError, ASCIILiteral("Scope origin does not match the registering client's origin") }); 144 142 145 143 // If registration is not null (in our parlance "empty"), then: … … 148 146 auto* newestWorker = registration->getNewestWorker(); 149 147 if (newestWorker && equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL()) && job.registrationOptions.updateViaCache == registration->updateViaCache()) { 150 resolve WithRegistrationOnMainThread(*registration);148 resolveCurrentRegistrationJob(registration->data()); 151 149 return; 152 150 } … … 161 159 void SWServerJobQueue::runUnregisterJob(const ServiceWorkerJobData& job) 162 160 { 163 ASSERT(!isMainThread());164 165 161 // If the origin of job’s scope url is not job's client's origin, then: 166 162 if (!protocolHostAndPortAreEqual(job.scopeURL, job.clientCreationURL)) 167 return reject WithExceptionOnMainThread(ExceptionData { SecurityError, ASCIILiteral("Origin of scope URL does not match the client's origin") });163 return rejectCurrentJob(ExceptionData { SecurityError, ASCIILiteral("Origin of scope URL does not match the client's origin") }); 168 164 169 165 // Let registration be the result of running "Get Registration" algorithm passing job’s scope url as the argument. … … 173 169 if (!registration || registration->isUninstalling()) { 174 170 // Invoke Resolve Job Promise with job and false. 175 resolve WithUnregistrationResultOnMainThread(false);171 resolveCurrentUnregistrationJob(false); 176 172 return; 177 173 } … … 181 177 182 178 // Invoke Resolve Job Promise with job and true. 183 resolve WithUnregistrationResultOnMainThread(true);179 resolveCurrentUnregistrationJob(true); 184 180 185 181 // FIXME: Invoke Try Clear Registration with registration. … … 192 188 // If registration is null (in our parlance "empty") or registration’s uninstalling flag is set, then: 193 189 if (!registration) 194 return reject WithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a null/nonexistent service worker registration") });190 return rejectCurrentJob(ExceptionData { TypeError, ASCIILiteral("Cannot update a null/nonexistent service worker registration") }); 195 191 if (registration->isUninstalling()) 196 return reject WithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker registration that is uninstalling") });197 198 // If job ’s jobtype is update, and newestWorker’s script url does not equal job’s script url with the exclude fragments flag set, then:192 return rejectCurrentJob(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker registration that is uninstalling") }); 193 194 // If job's type is update, and newestWorker’s script url does not equal job’s script url with the exclude fragments flag set, then: 199 195 auto* newestWorker = registration->getNewestWorker(); 200 196 if (newestWorker && !equalIgnoringFragmentIdentifier(job.scriptURL, newestWorker->scriptURL())) 201 return rejectWithExceptionOnMainThread(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker with a requested script URL whose newest worker has a different script URL") }); 202 203 startScriptFetchFromMainThread(); 204 } 205 206 void SWServerJobQueue::rejectWithExceptionOnMainThread(const ExceptionData& exception) 207 { 208 ASSERT(!isMainThread()); 209 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerJobQueue::rejectCurrentJob, exception)); 210 } 211 212 void SWServerJobQueue::resolveWithRegistrationOnMainThread(SWServerRegistration& registration) 213 { 214 ASSERT(!isMainThread()); 215 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerJobQueue::resolveCurrentRegistrationJob, registration.data())); 216 } 217 218 void SWServerJobQueue::resolveCurrentRegistrationJobOnMainThead(uint64_t serviceWorkerIdentifier) 219 { 220 ASSERT(!isMainThread()); 221 auto* registration = m_server.getRegistration(m_registrationKey); 222 ASSERT(registration); 223 registration->setActiveServiceWorkerIdentifier(serviceWorkerIdentifier); 224 resolveWithRegistrationOnMainThread(*registration); 225 } 226 227 void SWServerJobQueue::resolveWithUnregistrationResultOnMainThread(bool unregistrationResult) 228 { 229 ASSERT(!isMainThread()); 230 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerJobQueue::resolveCurrentUnregistrationJob, unregistrationResult)); 231 } 232 233 void SWServerJobQueue::startScriptFetchFromMainThread() 234 { 235 ASSERT(!isMainThread()); 236 m_server.postTaskReply(createCrossThreadTask(*this, &SWServerJobQueue::startScriptFetchForCurrentJob)); 197 return rejectCurrentJob(ExceptionData { TypeError, ASCIILiteral("Cannot update a service worker with a requested script URL whose newest worker has a different script URL") }); 198 199 startScriptFetchForCurrentJob(); 237 200 } 238 201 239 202 void SWServerJobQueue::rejectCurrentJob(const ExceptionData& exceptionData) 240 203 { 241 ASSERT(isMainThread());242 204 ASSERT(m_currentJob); 243 205 … … 249 211 void SWServerJobQueue::resolveCurrentRegistrationJob(const ServiceWorkerRegistrationData& data) 250 212 { 251 ASSERT(isMainThread());252 213 ASSERT(m_currentJob); 253 214 ASSERT(m_currentJob->type == ServiceWorkerJobType::Register); … … 260 221 void SWServerJobQueue::resolveCurrentUnregistrationJob(bool unregistrationResult) 261 222 { 262 ASSERT(isMainThread());263 223 ASSERT(m_currentJob); 264 224 ASSERT(m_currentJob->type == ServiceWorkerJobType::Unregister); … … 271 231 void SWServerJobQueue::startScriptFetchForCurrentJob() 272 232 { 273 ASSERT(isMainThread());274 233 ASSERT(m_currentJob); 275 234 … … 279 238 void SWServerJobQueue::finishCurrentJob() 280 239 { 281 ASSERT(isMainThread());282 240 ASSERT(m_currentJob); 283 241 ASSERT(!m_jobTimer.isActive()); … … 287 245 return; 288 246 289 startNextJob(); 247 ASSERT(!m_jobTimer.isActive()); 248 m_jobTimer.startOneShot(0_s); 290 249 } 291 250 -
trunk/Source/WebCore/workers/service/server/SWServerJobQueue.h
r224301 r224306 59 59 void runUpdateJob(const ServiceWorkerJobData&); 60 60 61 void rejectWithExceptionOnMainThread(const ExceptionData&);62 void resolveWithRegistrationOnMainThread(SWServerRegistration&);63 void resolveCurrentRegistrationJobOnMainThead(uint64_t serviceWorkerIdentifier);64 void resolveWithUnregistrationResultOnMainThread(bool);65 void startScriptFetchFromMainThread();66 bool isEmpty();67 68 61 Deque<ServiceWorkerJobData> m_jobQueue; 69 62 std::unique_ptr<ServiceWorkerJobData> m_currentJob; -
trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp
r224301 r224306 29 29 #if ENABLE(SERVICE_WORKER) 30 30 31 #include "ExceptionData.h"32 31 #include "SWServer.h" 33 32 #include "SWServerWorker.h" 34 #include "SecurityOrigin.h"35 #include "ServiceWorkerFetchResult.h"36 #include "ServiceWorkerRegistrationData.h"37 33 #include "ServiceWorkerUpdateViaCache.h" 38 #include "WorkerType.h"39 34 40 35 namespace WebCore { … … 43 38 : m_registrationKey(key) 44 39 , m_updateViaCache(updateViaCache) 45 , m_scopeURL(scopeURL .isolatedCopy())46 , m_scriptURL(scriptURL .isolatedCopy())40 , m_scopeURL(scopeURL) 41 , m_scriptURL(scriptURL) 47 42 { 48 43 m_scopeURL.removeFragmentIdentifier(); … … 55 50 SWServerWorker* SWServerRegistration::getNewestWorker() 56 51 { 57 ASSERT(!isMainThread());58 52 if (m_installingWorker) 59 53 return m_installingWorker.get();
Note: See TracChangeset
for help on using the changeset viewer.