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 14 matching lines...) Expand all Loading... |
25 ServiceWorkerDispatcherHost* dispatcher_host) | 25 ServiceWorkerDispatcherHost* dispatcher_host) |
26 : process_id_(process_id), | 26 : process_id_(process_id), |
27 provider_id_(provider_id), | 27 provider_id_(provider_id), |
28 context_(context), | 28 context_(context), |
29 dispatcher_host_(dispatcher_host) { | 29 dispatcher_host_(dispatcher_host) { |
30 } | 30 } |
31 | 31 |
32 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { | 32 ServiceWorkerProviderHost::~ServiceWorkerProviderHost() { |
33 if (active_version_) | 33 if (active_version_) |
34 active_version_->RemoveControllee(this); | 34 active_version_->RemoveControllee(this); |
35 if (pending_version_) | 35 if (waiting_version_) |
36 pending_version_->RemovePendingControllee(this); | 36 waiting_version_->RemoveWaitingControllee(this); |
37 } | 37 } |
38 | 38 |
39 void ServiceWorkerProviderHost::SetActiveVersion( | 39 void ServiceWorkerProviderHost::SetActiveVersion( |
40 ServiceWorkerVersion* version) { | 40 ServiceWorkerVersion* version) { |
41 if (version == active_version_) | 41 if (version == active_version_) |
42 return; | 42 return; |
43 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; | 43 scoped_refptr<ServiceWorkerVersion> previous_version = active_version_; |
44 active_version_ = version; | 44 active_version_ = version; |
45 if (version) | 45 if (version) |
46 version->AddControllee(this); | 46 version->AddControllee(this); |
47 if (previous_version) | 47 if (previous_version) |
48 previous_version->RemoveControllee(this); | 48 previous_version->RemoveControllee(this); |
49 | 49 |
50 if (!dispatcher_host_) | 50 if (!dispatcher_host_) |
51 return; // Could be NULL in some tests. | 51 return; // Could be NULL in some tests. |
52 | 52 |
53 ServiceWorkerObjectInfo info; | 53 ServiceWorkerObjectInfo info; |
54 if (context_ && version) { | 54 if (context_ && version) { |
55 scoped_ptr<ServiceWorkerHandle> handle = | 55 scoped_ptr<ServiceWorkerHandle> handle = |
56 ServiceWorkerHandle::Create(context_, dispatcher_host_, | 56 ServiceWorkerHandle::Create(context_, dispatcher_host_, |
57 kDocumentMainThreadId, version); | 57 kDocumentMainThreadId, version); |
58 info = handle->GetObjectInfo(); | 58 info = handle->GetObjectInfo(); |
59 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); | 59 dispatcher_host_->RegisterServiceWorkerHandle(handle.Pass()); |
60 } | 60 } |
61 dispatcher_host_->Send( | 61 dispatcher_host_->Send( |
62 new ServiceWorkerMsg_SetCurrentServiceWorker( | 62 new ServiceWorkerMsg_SetCurrentServiceWorker( |
63 kDocumentMainThreadId, provider_id(), info)); | 63 kDocumentMainThreadId, provider_id(), info)); |
64 } | 64 } |
65 | 65 |
66 void ServiceWorkerProviderHost::SetPendingVersion( | 66 void ServiceWorkerProviderHost::SetWaitingVersion( |
67 ServiceWorkerVersion* version) { | 67 ServiceWorkerVersion* version) { |
68 if (version == pending_version_) | 68 if (version == waiting_version_) |
69 return; | 69 return; |
70 scoped_refptr<ServiceWorkerVersion> previous_version = pending_version_; | 70 scoped_refptr<ServiceWorkerVersion> previous_version = waiting_version_; |
71 pending_version_ = version; | 71 waiting_version_ = version; |
72 if (version) | 72 if (version) |
73 version->AddPendingControllee(this); | 73 version->AddWaitingControllee(this); |
74 if (previous_version) | 74 if (previous_version) |
75 previous_version->RemovePendingControllee(this); | 75 previous_version->RemoveWaitingControllee(this); |
76 | 76 |
77 if (!dispatcher_host_) | 77 if (!dispatcher_host_) |
78 return; // Could be NULL in some tests. | 78 return; // Could be NULL in some tests. |
79 | 79 |
80 // TODO(kinuko): dispatch pendingchange event to the document. | 80 // TODO(kinuko): dispatch pendingchange event to the document. |
81 } | 81 } |
82 | 82 |
83 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { | 83 bool ServiceWorkerProviderHost::SetHostedVersionId(int64 version_id) { |
84 if (!context_) | 84 if (!context_) |
85 return true; // System is shutting down. | 85 return true; // System is shutting down. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 dispatcher_host_->Send( | 133 dispatcher_host_->Send( |
134 new ServiceWorkerMsg_MessageToDocument( | 134 new ServiceWorkerMsg_MessageToDocument( |
135 kDocumentMainThreadId, provider_id(), | 135 kDocumentMainThreadId, provider_id(), |
136 message, | 136 message, |
137 sent_message_port_ids, | 137 sent_message_port_ids, |
138 new_routing_ids)); | 138 new_routing_ids)); |
139 } | 139 } |
140 | 140 |
141 } // namespace content | 141 } // namespace content |
OLD | NEW |