OLD | NEW |
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" |
11 #include "content/child/service_worker/service_worker_dispatcher.h" | 11 #include "content/child/service_worker/service_worker_dispatcher.h" |
12 #include "content/child/service_worker/service_worker_handle_reference.h" | 12 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 13 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
13 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
14 #include "content/child/worker_task_runner.h" | 15 #include "content/child/worker_task_runner.h" |
15 #include "content/common/service_worker/service_worker_messages.h" | 16 #include "content/common/service_worker/service_worker_messages.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 ServiceWorkerProviderContext::ServiceWorkerProviderContext(int provider_id) | 20 ServiceWorkerProviderContext::ServiceWorkerProviderContext(int provider_id) |
20 : provider_id_(provider_id), | 21 : provider_id_(provider_id), |
21 main_thread_loop_proxy_(base::MessageLoopProxy::current()) { | 22 main_thread_loop_proxy_(base::MessageLoopProxy::current()) { |
22 if (!ChildThread::current()) | 23 if (!ChildThread::current()) |
(...skipping 26 matching lines...) Expand all Loading... |
49 ServiceWorkerHandleReference* ServiceWorkerProviderContext::active() { | 50 ServiceWorkerHandleReference* ServiceWorkerProviderContext::active() { |
50 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 51 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
51 return active_.get(); | 52 return active_.get(); |
52 } | 53 } |
53 | 54 |
54 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() { | 55 ServiceWorkerHandleReference* ServiceWorkerProviderContext::controller() { |
55 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 56 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
56 return controller_.get(); | 57 return controller_.get(); |
57 } | 58 } |
58 | 59 |
| 60 ServiceWorkerRegistrationHandleReference* |
| 61 ServiceWorkerProviderContext::registration() { |
| 62 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
| 63 return registration_.get(); |
| 64 } |
| 65 |
59 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged( | 66 void ServiceWorkerProviderContext::OnServiceWorkerStateChanged( |
60 int handle_id, | 67 int handle_id, |
61 blink::WebServiceWorkerState state) { | 68 blink::WebServiceWorkerState state) { |
62 ServiceWorkerHandleReference* which = NULL; | 69 ServiceWorkerHandleReference* which = NULL; |
63 if (handle_id == controller_handle_id()) | 70 if (handle_id == controller_handle_id()) |
64 which = controller_.get(); | 71 which = controller_.get(); |
65 else if (handle_id == active_handle_id()) | 72 else if (handle_id == active_handle_id()) |
66 which = active_.get(); | 73 which = active_.get(); |
67 else if (handle_id == waiting_handle_id()) | 74 else if (handle_id == waiting_handle_id()) |
68 which = waiting_.get(); | 75 which = waiting_.get(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 117 |
111 // This context is is the primary owner of this handle, keeps the | 118 // This context is is the primary owner of this handle, keeps the |
112 // initial reference until it goes away. | 119 // initial reference until it goes away. |
113 controller_ = | 120 controller_ = |
114 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 121 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
115 | 122 |
116 // TODO(kinuko): We can forward the message to other threads here | 123 // TODO(kinuko): We can forward the message to other threads here |
117 // when we support navigator.serviceWorker in dedicated workers. | 124 // when we support navigator.serviceWorker in dedicated workers. |
118 } | 125 } |
119 | 126 |
| 127 void ServiceWorkerProviderContext::AssociateRegistration( |
| 128 const ServiceWorkerRegistrationObjectInfo& info) { |
| 129 registration_ = ServiceWorkerRegistrationHandleReference::Adopt( |
| 130 info, thread_safe_sender_); |
| 131 } |
| 132 |
| 133 void ServiceWorkerProviderContext::UnassociateRegistration() { |
| 134 registration_.reset(); |
| 135 } |
| 136 |
120 int ServiceWorkerProviderContext::installing_handle_id() const { | 137 int ServiceWorkerProviderContext::installing_handle_id() const { |
121 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 138 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
122 return installing_ ? installing_->info().handle_id | 139 return installing_ ? installing_->info().handle_id |
123 : kInvalidServiceWorkerHandleId; | 140 : kInvalidServiceWorkerHandleId; |
124 } | 141 } |
125 | 142 |
126 int ServiceWorkerProviderContext::waiting_handle_id() const { | 143 int ServiceWorkerProviderContext::waiting_handle_id() const { |
127 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 144 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
128 return waiting_ ? waiting_->info().handle_id | 145 return waiting_ ? waiting_->info().handle_id |
129 : kInvalidServiceWorkerHandleId; | 146 : kInvalidServiceWorkerHandleId; |
130 } | 147 } |
131 | 148 |
132 int ServiceWorkerProviderContext::active_handle_id() const { | 149 int ServiceWorkerProviderContext::active_handle_id() const { |
133 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 150 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
134 return active_ ? active_->info().handle_id | 151 return active_ ? active_->info().handle_id |
135 : kInvalidServiceWorkerHandleId; | 152 : kInvalidServiceWorkerHandleId; |
136 } | 153 } |
137 | 154 |
138 int ServiceWorkerProviderContext::controller_handle_id() const { | 155 int ServiceWorkerProviderContext::controller_handle_id() const { |
139 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 156 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
140 return controller_ ? controller_->info().handle_id | 157 return controller_ ? controller_->info().handle_id |
141 : kInvalidServiceWorkerHandleId; | 158 : kInvalidServiceWorkerHandleId; |
142 } | 159 } |
143 | 160 |
| 161 int ServiceWorkerProviderContext::registration_handle_id() const { |
| 162 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
| 163 return registration_ ? registration_->info().handle_id |
| 164 : kInvalidServiceWorkerRegistrationHandleId; |
| 165 } |
| 166 |
144 } // namespace content | 167 } // namespace content |
OLD | NEW |