Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: content/renderer/service_worker/embedded_worker_context_client.cc

Issue 885443006: ServiceWorker: Get registration info and its version attributes in one lock operation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/child/service_worker/web_service_worker_provider_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/service_worker/embedded_worker_context_client.h" 5 #include "content/renderer/service_worker/embedded_worker_context_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 worker_task_runner_ = new WorkerThreadTaskRunner( 173 worker_task_runner_ = new WorkerThreadTaskRunner(
174 WorkerTaskRunner::Instance()->CurrentWorkerId()); 174 WorkerTaskRunner::Instance()->CurrentWorkerId());
175 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); 175 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId());
176 // g_worker_client_tls.Pointer()->Get() could return NULL if this context 176 // g_worker_client_tls.Pointer()->Get() could return NULL if this context
177 // gets deleted before workerContextStarted() is called. 177 // gets deleted before workerContextStarted() is called.
178 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); 178 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL);
179 DCHECK(!script_context_); 179 DCHECK(!script_context_);
180 g_worker_client_tls.Pointer()->Set(this); 180 g_worker_client_tls.Pointer()->Set(this);
181 script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); 181 script_context_.reset(new ServiceWorkerScriptContext(this, proxy));
182 182
183 // This can be nullptr on EmbeddedWorkerBrowserTests. 183 SetRegistrationInServiceWorkerGlobalScope();
184 // TODO(nhiroki): Remove this workaround. |registration()| should always be
185 // valid other than the test because the registration association message
186 // arrives before starting the worker context.
187 if (provider_context_->registration())
188 SetRegistrationInServiceWorkerGlobalScope();
189 184
190 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded( 185 Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded(
191 embedded_worker_id_, 186 embedded_worker_id_,
192 WorkerTaskRunner::Instance()->CurrentWorkerId())); 187 WorkerTaskRunner::Instance()->CurrentWorkerId()));
193 188
194 // Schedule a task to send back WorkerStarted asynchronously, 189 // Schedule a task to send back WorkerStarted asynchronously,
195 // so that at the time we send it we can be sure that the worker 190 // so that at the time we send it we can be sure that the worker
196 // script has been evaluated and worker run loop has been started. 191 // script has been evaluated and worker run loop has been started.
197 worker_task_runner_->PostTask( 192 worker_task_runner_->PostTask(
198 FROM_HERE, 193 FROM_HERE,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 "EmbeddedWorkerContextClient::StartingWorkerContext", 407 "EmbeddedWorkerContextClient::StartingWorkerContext",
413 this); 408 this);
414 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_)); 409 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_));
415 } 410 }
416 411
417 void EmbeddedWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope() { 412 void EmbeddedWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope() {
418 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 413 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
419 DCHECK(provider_context_); 414 DCHECK(provider_context_);
420 DCHECK(script_context_); 415 DCHECK(script_context_);
421 416
417 ServiceWorkerRegistrationObjectInfo info;
418 ServiceWorkerVersionAttributes attrs;
419 bool found =
420 provider_context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs);
421 if (!found)
422 return; // Cannot be associated with a registration in some tests.
423
422 ServiceWorkerDispatcher* dispatcher = 424 ServiceWorkerDispatcher* dispatcher =
423 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( 425 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
424 thread_safe_sender()); 426 thread_safe_sender());
425 427
426 // Register a registration with the dispatcher living on the worker thread. 428 // Register a registration and its version attributes with the dispatcher
427 DCHECK(provider_context_->registration()); 429 // living on the worker thread.
428 scoped_ptr<WebServiceWorkerRegistrationImpl> registration( 430 scoped_ptr<WebServiceWorkerRegistrationImpl> registration(
429 dispatcher->CreateServiceWorkerRegistration( 431 dispatcher->CreateServiceWorkerRegistration(info, false));
430 provider_context_->registration()->info(), false));
431
432 // Register workers with the dispatcher living on the worker thread.
433 ServiceWorkerVersionAttributes attrs =
434 provider_context_->GetVersionAttributes();
435 registration->SetInstalling( 432 registration->SetInstalling(
436 dispatcher->GetServiceWorker(attrs.installing, false)); 433 dispatcher->GetServiceWorker(attrs.installing, false));
437 registration->SetWaiting( 434 registration->SetWaiting(
438 dispatcher->GetServiceWorker(attrs.waiting, false)); 435 dispatcher->GetServiceWorker(attrs.waiting, false));
439 registration->SetActive( 436 registration->SetActive(
440 dispatcher->GetServiceWorker(attrs.active, false)); 437 dispatcher->GetServiceWorker(attrs.active, false));
441 438
442 script_context_->SetRegistrationInServiceWorkerGlobalScope( 439 script_context_->SetRegistrationInServiceWorkerGlobalScope(
443 registration.Pass()); 440 registration.Pass());
444 } 441 }
445 442
446 } // namespace content 443 } // namespace content
OLDNEW
« no previous file with comments | « content/child/service_worker/web_service_worker_provider_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698