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

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

Issue 354643003: ServiceWorker: Support navigator.serviceWorker.active (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fix Created 6 years, 5 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 28 matching lines...) Expand all
39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::installing() { 39 ServiceWorkerHandleReference* ServiceWorkerProviderContext::installing() {
40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 40 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
41 return installing_.get(); 41 return installing_.get();
42 } 42 }
43 43
44 ServiceWorkerHandleReference* ServiceWorkerProviderContext::waiting() { 44 ServiceWorkerHandleReference* ServiceWorkerProviderContext::waiting() {
45 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 45 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
46 return waiting_.get(); 46 return waiting_.get();
47 } 47 }
48 48
49 ServiceWorkerHandleReference* ServiceWorkerProviderContext::active() {
50 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
51 return active_.get();
52 }
53
49 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() { 54 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() {
50 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 55 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
51 return controller_.get(); 56 return controller_.get();
52 } 57 }
53 58
54 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged( 59 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged(
55 int handle_id, 60 int handle_id,
56 blink::WebServiceWorkerState state) { 61 blink::WebServiceWorkerState state) {
57 ServiceWorkerHandleReference* which = NULL; 62 ServiceWorkerHandleReference* which = NULL;
58 if (handle_id == controller_handle_id()) { 63 if (handle_id == controller_handle_id())
59 which = controller_.get(); 64 which = controller_.get();
60 } else if (handle_id == waiting_handle_id()) { 65 else if (handle_id == active_handle_id())
66 which = active_.get();
67 else if (handle_id == waiting_handle_id())
61 which = waiting_.get(); 68 which = waiting_.get();
62 } else if (handle_id == installing_handle_id()) { 69 else if (handle_id == installing_handle_id())
63 which = installing_.get(); 70 which = installing_.get();
64 }
65 71
66 // We should only get messages for ServiceWorkers associated with 72 // We should only get messages for ServiceWorkers associated with
67 // this provider. 73 // this provider.
68 DCHECK(which); 74 DCHECK(which);
69 75
70 which->set_state(state); 76 which->set_state(state);
71 77
72 // TODO(kinuko): We can forward the message to other threads here 78 // TODO(kinuko): We can forward the message to other threads here
73 // when we support navigator.serviceWorker in dedicated workers. 79 // when we support navigator.serviceWorker in dedicated workers.
74 } 80 }
75 81
76 void ServiceWorkerProviderContext::OnSetInstallingServiceWorker( 82 void ServiceWorkerProviderContext::OnSetInstallingServiceWorker(
77 int provider_id, 83 int provider_id,
78 const ServiceWorkerObjectInfo& info) { 84 const ServiceWorkerObjectInfo& info) {
79 DCHECK_EQ(provider_id_, provider_id); 85 DCHECK_EQ(provider_id_, provider_id);
80 installing_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 86 installing_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
81 } 87 }
82 88
83 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker( 89 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker(
84 int provider_id, 90 int provider_id,
85 const ServiceWorkerObjectInfo& info) { 91 const ServiceWorkerObjectInfo& info) {
86 DCHECK_EQ(provider_id_, provider_id); 92 DCHECK_EQ(provider_id_, provider_id);
87 waiting_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 93 waiting_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
88 } 94 }
89 95
96 void ServiceWorkerProviderContext::OnSetActiveServiceWorker(
97 int provider_id,
98 const ServiceWorkerObjectInfo& info) {
99 DCHECK_EQ(provider_id_, provider_id);
100 active_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
101 }
102
90 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( 103 void ServiceWorkerProviderContext::OnSetControllerServiceWorker(
91 int provider_id, 104 int provider_id,
92 const ServiceWorkerObjectInfo& info) { 105 const ServiceWorkerObjectInfo& info) {
93 DCHECK_EQ(provider_id_, provider_id); 106 DCHECK_EQ(provider_id_, provider_id);
94 107
95 // This context is is the primary owner of this handle, keeps the 108 // This context is is the primary owner of this handle, keeps the
96 // initial reference until it goes away. 109 // initial reference until it goes away.
97 controller_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); 110 controller_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_);
98 111
99 // TODO(kinuko): We can forward the message to other threads here 112 // TODO(kinuko): We can forward the message to other threads here
100 // when we support navigator.serviceWorker in dedicated workers. 113 // when we support navigator.serviceWorker in dedicated workers.
101 } 114 }
102 115
103 int ServiceWorkerProviderContext::installing_handle_id() const { 116 int ServiceWorkerProviderContext::installing_handle_id() const {
104 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 117 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
105 return installing_ ? installing_->info().handle_id 118 return installing_ ? installing_->info().handle_id
106 : kInvalidServiceWorkerHandleId; 119 : kInvalidServiceWorkerHandleId;
107 } 120 }
108 121
109 int ServiceWorkerProviderContext::waiting_handle_id() const { 122 int ServiceWorkerProviderContext::waiting_handle_id() const {
110 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 123 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
111 return waiting_ ? waiting_->info().handle_id 124 return waiting_ ? waiting_->info().handle_id
112 : kInvalidServiceWorkerHandleId; 125 : kInvalidServiceWorkerHandleId;
113 } 126 }
114 127
128 int ServiceWorkerProviderContext::active_handle_id() const {
129 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
130 return active_ ? active_->info().handle_id
131 : kInvalidServiceWorkerHandleId;
132 }
133
115 int ServiceWorkerProviderContext::controller_handle_id() const { 134 int ServiceWorkerProviderContext::controller_handle_id() const {
116 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); 135 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread());
117 return controller_ ? controller_->info().handle_id 136 return controller_ ? controller_->info().handle_id
118 : kInvalidServiceWorkerHandleId; 137 : kInvalidServiceWorkerHandleId;
119 } 138 }
120 139
121 } // namespace content 140 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698