OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/service_worker/service_worker_provider_host.h" | 5 #include "content/browser/service_worker/service_worker_provider_host.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "content/browser/message_port_message_filter.h" | 8 #include "content/browser/message_port_message_filter.h" |
9 #include "content/browser/service_worker/service_worker_context_core.h" | 9 #include "content/browser/service_worker/service_worker_context_core.h" |
10 #include "content/browser/service_worker/service_worker_context_request_handler.
h" | 10 #include "content/browser/service_worker/service_worker_context_request_handler.
h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; | 48 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; |
49 active_version_ = version; | 49 active_version_ = version; |
50 if (version) | 50 if (version) |
51 version->AddControllee(this); | 51 version->AddControllee(this); |
52 if (previous_version) | 52 if (previous_version) |
53 previous_version->RemoveControllee(this); | 53 previous_version->RemoveControllee(this); |
54 | 54 |
55 if (!dispatcher_host_) | 55 if (!dispatcher_host_) |
56 return; // Could be NULL in some tests. | 56 return; // Could be NULL in some tests. |
57 | 57 |
| 58 dispatcher_host_->Send(new ServiceWorkerMsg_SetCurrentServiceWorker( |
| 59 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); |
| 60 } |
| 61 |
| 62 ServiceWorkerObjectInfo ServiceWorkerProviderHost::CreateHandleAndPass( |
| 63 ServiceWorkerVersion* version) { |
58 ServiceWorkerObjectInfo info; | 64 ServiceWorkerObjectInfo info; |
59 if (context_ && version) { | 65 if (context_ && version) { |
60 scoped_ptr<ServiceWorkerHandle> handle = | 66 scoped_ptr<ServiceWorkerHandle> handle = |
61 ServiceWorkerHandle::Create(context_, dispatcher_host_, | 67 ServiceWorkerHandle::Create(context_, dispatcher_host_, |
62 kDocumentMainThreadId, version); | 68 kDocumentMainThreadId, version); |
63 info = handle->GetObjectInfo(); | 69 info = handle->GetObjectInfo(); |
64 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); | 70 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); |
65 } | 71 } |
66 dispatcher_host_->Send( | 72 return info; |
67 new ServiceWorkerMsg_SetCurrentServiceWorker( | |
68 kDocumentMainThreadId, provider_id(), info)); | |
69 } | 73 } |
70 | 74 |
71 void ServiceWorkerProviderHost::SetWaitingVersion( | 75 void ServiceWorkerProviderHost::SetWaitingVersion( |
72 ServiceWorkerVersion* version) { | 76 ServiceWorkerVersion* version) { |
73 if (version == waiting_version_) | 77 if (version == waiting_version_) |
74 return; | 78 return; |
75 scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_; | 79 scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_; |
76 waiting_version_ = version; | 80 waiting_version_ = version; |
77 if (version) | 81 if (version) |
78 version->AddWaitingControllee(this); | 82 version->AddWaitingControllee(this); |
79 if (previous_version) | 83 if (previous_version) |
80 previous_version->RemoveWaitingControllee(this); | 84 previous_version->RemoveWaitingControllee(this); |
81 | 85 |
82 if (!dispatcher_host_) | 86 if (!dispatcher_host_) |
83 return; // Could be NULL in some tests. | 87 return; // Could be NULL in some tests. |
84 | 88 |
85 // TODO(kinuko): dispatch pendingchange event to the document. | 89 dispatcher_host_->Send(new ServiceWorkerMsg_SetWaitingServiceWorker( |
| 90 kDocumentMainThreadId, provider_id(), CreateHandleAndPass(version))); |
86 } | 91 } |
87 | 92 |
88 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 93 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
89 if (!context_) | 94 if (!context_) |
90 return true; // System is shutting down. | 95 return true; // System is shutting down. |
91 if (active_version_) | 96 if (active_version_) |
92 return false; // Unexpected bad message. | 97 return false; // Unexpected bad message. |
93 | 98 |
94 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); | 99 ServiceWorkerVersion* live_version = context_->GetLiveVersion(version_id); |
95 if (!live_version) | 100 if (!live_version) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 143 |
139 dispatcher_host_->Send( | 144 dispatcher_host_->Send( |
140 new ServiceWorkerMsg_MessageToDocument( | 145 new ServiceWorkerMsg_MessageToDocument( |
141 kDocumentMainThreadId, provider_id(), | 146 kDocumentMainThreadId, provider_id(), |
142 message, | 147 message, |
143 sent_message_port_ids, | 148 sent_message_port_ids, |
144 new_routing_ids)); | 149 new_routing_ids)); |
145 } | 150 } |
146 | 151 |
147 } // namespace content | 152 } // namespace content |
OLD | NEW |