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/thread_safe_sender.h" | 13 #include "content/child/thread_safe_sender.h" |
14 #include "content/child/worker_task_runner.h" | 14 #include "content/child/worker_task_runner.h" |
15 #include "content/common/service_worker/service_worker_messages.h" | 15 #include "content/common/service_worker/service_worker_messages.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 ServiceWorkerProviderContext::ServiceWorkerProviderContext(int provider_id) | 19 ServiceWorkerProviderContext::ServiceWorkerProviderContext(int provider_id) |
20 : provider_id_(provider_id), | 20 : provider_id_(provider_id), |
21 main_thread_loop_proxy_(base::MessageLoopProxy::current()) { | 21 main_thread_loop_proxy_(base::MessageLoopProxy::current()) { |
22 if (!ChildThread::current()) | 22 if (!ChildThread::current()) |
23 return; // May be null in some tests. | 23 return; // May be null in some tests. |
24 thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); | 24 thread_safe_sender_ = ChildThread::current()->thread_safe_sender(); |
25 ServiceWorkerDispatcher* dispatcher = | 25 ServiceWorkerDispatcher* dispatcher = |
26 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 26 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
27 thread_safe_sender_); | 27 thread_safe_sender_.get()); |
28 DCHECK(dispatcher); | 28 DCHECK(dispatcher); |
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 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 which->set_state(state); | 76 which->set_state(state); |
77 | 77 |
78 // TODO(kinuko): We can forward the message to other threads here | 78 // TODO(kinuko): We can forward the message to other threads here |
79 // when we support navigator.serviceWorker in dedicated workers. | 79 // when we support navigator.serviceWorker in dedicated workers. |
80 } | 80 } |
81 | 81 |
82 void ServiceWorkerProviderContext::OnSetInstallingServiceWorker( | 82 void ServiceWorkerProviderContext::OnSetInstallingServiceWorker( |
83 int provider_id, | 83 int provider_id, |
84 const ServiceWorkerObjectInfo& info) { | 84 const ServiceWorkerObjectInfo& info) { |
85 DCHECK_EQ(provider_id_, provider_id); | 85 DCHECK_EQ(provider_id_, provider_id); |
86 installing_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); | 86 installing_ = |
| 87 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
87 } | 88 } |
88 | 89 |
89 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker( | 90 void ServiceWorkerProviderContext::OnSetWaitingServiceWorker( |
90 int provider_id, | 91 int provider_id, |
91 const ServiceWorkerObjectInfo& info) { | 92 const ServiceWorkerObjectInfo& info) { |
92 DCHECK_EQ(provider_id_, provider_id); | 93 DCHECK_EQ(provider_id_, provider_id); |
93 waiting_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); | 94 waiting_ = |
| 95 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
94 } | 96 } |
95 | 97 |
96 void ServiceWorkerProviderContext::OnSetActiveServiceWorker( | 98 void ServiceWorkerProviderContext::OnSetActiveServiceWorker( |
97 int provider_id, | 99 int provider_id, |
98 const ServiceWorkerObjectInfo& info) { | 100 const ServiceWorkerObjectInfo& info) { |
99 DCHECK_EQ(provider_id_, provider_id); | 101 DCHECK_EQ(provider_id_, provider_id); |
100 active_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); | 102 active_ = |
| 103 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
101 } | 104 } |
102 | 105 |
103 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( | 106 void ServiceWorkerProviderContext::OnSetControllerServiceWorker( |
104 int provider_id, | 107 int provider_id, |
105 const ServiceWorkerObjectInfo& info) { | 108 const ServiceWorkerObjectInfo& info) { |
106 DCHECK_EQ(provider_id_, provider_id); | 109 DCHECK_EQ(provider_id_, provider_id); |
107 | 110 |
108 // This context is is the primary owner of this handle, keeps the | 111 // This context is is the primary owner of this handle, keeps the |
109 // initial reference until it goes away. | 112 // initial reference until it goes away. |
110 controller_ = ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); | 113 controller_ = |
| 114 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
111 | 115 |
112 // TODO(kinuko): We can forward the message to other threads here | 116 // TODO(kinuko): We can forward the message to other threads here |
113 // when we support navigator.serviceWorker in dedicated workers. | 117 // when we support navigator.serviceWorker in dedicated workers. |
114 } | 118 } |
115 | 119 |
116 int ServiceWorkerProviderContext::installing_handle_id() const { | 120 int ServiceWorkerProviderContext::installing_handle_id() const { |
117 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 121 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
118 return installing_ ? installing_->info().handle_id | 122 return installing_ ? installing_->info().handle_id |
119 : kInvalidServiceWorkerHandleId; | 123 : kInvalidServiceWorkerHandleId; |
120 } | 124 } |
(...skipping 10 matching lines...) Expand all Loading... |
131 : kInvalidServiceWorkerHandleId; | 135 : kInvalidServiceWorkerHandleId; |
132 } | 136 } |
133 | 137 |
134 int ServiceWorkerProviderContext::controller_handle_id() const { | 138 int ServiceWorkerProviderContext::controller_handle_id() const { |
135 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); | 139 DCHECK(main_thread_loop_proxy_->RunsTasksOnCurrentThread()); |
136 return controller_ ? controller_->info().handle_id | 140 return controller_ ? controller_->info().handle_id |
137 : kInvalidServiceWorkerHandleId; | 141 : kInvalidServiceWorkerHandleId; |
138 } | 142 } |
139 | 143 |
140 } // namespace content | 144 } // namespace content |
OLD | NEW |