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

Side by Side Diff: content/child/service_worker/service_worker_provider_context.cc

Issue 261533003: Populate .current when navigator.serviceWorker is accessed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dropped dedicated worker support Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/child/service_worker/service_worker_provider_context.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/stl_util.h"
10 #include "content/child/child_thread.h"
11 #include "content/child/service_worker/service_worker_dispatcher.h"
12 #include "content/child/service_worker/service_worker_handle_reference.h"
13 #include "content/child/thread_safe_sender.h"
14 #include "content/child/worker_task_runner.h"
15 #include "content/common/service_worker/service_worker_messages.h"
16
17 namespace content {
18
19 ServiceWorkerProviderContext::ServiceWorkerProviderContext(int provider_id)
20 : provider_id_(provider_id),
21 main_thread_loop_proxy_(base::MessageLoopProxy::current()),
22 thread_safe_sender_(ChildThread::current()->thread_safe_sender()) {
23 ServiceWorkerDispatcher* dispatcher =
24 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(
25 thread_safe_sender_);
26 DCHECK(dispatcher);
27 dispatcher->AddProviderContext(this);
28 }
29
30 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() {
31 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
32 if (ServiceWorkerDispatcher* dispatcher =
33 ServiceWorkerDispatcher::GetThreadSpecificInstance()) {
34 dispatcher->RemoveProviderContext(this);
35 }
36 }
37
38 void ServiceWorkerProviderContext::GetInitializationInfo(
39 scoped_ptr<ServiceWorkerHandleReference>* current) {
40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
41 if (current_) {
42 *current = ServiceWorkerHandleReference::Create(
43 current_->info(), thread_safe_sender_);
44 }
45 }
46
47 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged(
48 int thread_id,
49 int handle_id,
50 blink::WebServiceWorkerState state) {
51 // Currently .current is the only ServiceWorker associated to this provider.
52 DCHECK_EQ(current_handle_id(), handle_id);
53 current_->set_state(state);
54
55 // TODO(kinuko): Forward the message to other threads when we support
56 // navigator.serviceWorker in dedicated workers.
57 }
58
59 void ServiceWorkerProviderContext::OnSetCurrentServiceWorker(
60 int thread_id,
61 int provider_id,
62 const ServiceWorkerObjectInfo& info) {
63 DCHECK_EQ(provider_id_, provider_id);
64
65 // This context is is the primary owner of this handle, keeps the
66 // initial reference until it goes away.
67 current_ = ServiceWorkerHandleReference::CreateForDeleter(
68 info, thread_safe_sender_);
69
70 // TODO(kinuko): Forward the message to other threads when we support
71 // navigator.serviceWorker in dedicated workers.
72 }
73
74 int ServiceWorkerProviderContext::current_handle_id() const {
75 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
76 return current_ ? current_->info().handle_id : kInvalidServiceWorkerHandleId;
77 }
78
79 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698