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

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

Issue 317953004: Set the "waiting" Service Worker of Service Worker providers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bring patch to head. Created 6 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/child/service_worker/service_worker_provider_context.h" 5 #include "content/child/service_worker/service_worker_provider_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "content/child/child_thread.h" 10 #include "content/child/child_thread.h"
(...skipping 18 matching lines...) Expand all
29 dispatcher->AddProviderContext(this); 29 dispatcher->AddProviderContext(this);
30 } 30 }
31 31
32 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() { 32 ServiceWorkerProviderContext::~ServiceWorkerProviderContext() {
33 if (ServiceWorkerDispatcher* dispatcher = 33 if (ServiceWorkerDispatcher* dispatcher =
34 ServiceWorkerDispatcher::GetThreadSpecificInstance()) { 34 ServiceWorkerDispatcher::GetThreadSpecificInstance()) {
35 dispatcher->RemoveProviderContext(this); 35 dispatcher->RemoveProviderContext(this);
36 } 36 }
37 } 37 }
38 38
39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::waiting() {
40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
41 return waiting_.get();
42 }
43
39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::current() { 44 ServiceWorkerHandleReference* ServiceWorkerProviderContext::current() {
40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 45 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
41 return current_.get(); 46 return current_.get();
42 } 47 }
43 48
44 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged( 49 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged(
45 int handle_id, 50 int handle_id,
46 blink::WebServiceWorkerState state) { 51 blink::WebServiceWorkerState state) {
47 // Currently .current is the only ServiceWorker associated to this provider. 52 ServiceWorkerHandleReference* which = NULL;
48 DCHECK_EQ(current_handle_id(), handle_id); 53 if (handle_id == current_handle_id()) {
49 current_->set_state(state); 54 which = current_.get();
55 } else if (handle_id == waiting_handle_id()) {
56 which = waiting_.get();
57 }
58
59 // We should only get messages for ServiceWorkers associated with
60 // this provider.
61 DCHECK(which);
62
63 which->set_state(state);
50 64
51 // TODO(kinuko): We can forward the message to other threads here 65 // TODO(kinuko): We can forward the message to other threads here
52 // when we support navigator.serviceWorker in dedicated workers. 66 // when we support navigator.serviceWorker in dedicated workers.
53 } 67 }
54 68
69 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker(
70 int provider_id,
71 const ServiceWorkerObjectInfo& info) {
72 DCHECK_EQ(provider_id_, provider_id);
73 waiting_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
74 }
75
55 void ServiceWorkerProviderContext::OnSetCurrentServiceWorker( 76 void ServiceWorkerProviderContext::OnSetCurrentServiceWorker(
56 int provider_id, 77 int provider_id,
57 const ServiceWorkerObjectInfo& info) { 78 const ServiceWorkerObjectInfo& info) {
58 DCHECK_EQ(provider_id_, provider_id); 79 DCHECK_EQ(provider_id_, provider_id);
59 80
60 // This context is is the primary owner of this handle, keeps the 81 // This context is is the primary owner of this handle, keeps the
61 // initial reference until it goes away. 82 // initial reference until it goes away.
62 current_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 83 current_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
63 84
64 // TODO(kinuko): We can forward the message to other threads here 85 // TODO(kinuko): We can forward the message to other threads here
65 // when we support navigator.serviceWorker in dedicated workers. 86 // when we support navigator.serviceWorker in dedicated workers.
66 } 87 }
67 88
68 int ServiceWorkerProviderContext::current_handle_id() const { 89 int ServiceWorkerProviderContext::current_handle_id() const {
69 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 90 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
70 return current_ ? current_->info().handle_id : kInvalidServiceWorkerHandleId; 91 return current_ ? current_->info().handle_id : kInvalidServiceWorkerHandleId;
71 } 92 }
72 93
94 int ServiceWorkerProviderContext::waiting_handle_id() const {
95 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
96 return waiting_ ? waiting_->info().handle_id : kInvalidServiceWorkerHandleId;
97 }
98
73 } // namespace content 99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698