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/child/service_worker/web_service_worker_provider_impl.h" | 5 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/child/child_thread.h" | 9 #include "content/child/child_thread.h" |
10 #include "content/child/service_worker/service_worker_dispatcher.h" | 10 #include "content/child/service_worker/service_worker_dispatcher.h" |
11 #include "content/child/service_worker/service_worker_handle_reference.h" | 11 #include "content/child/service_worker/service_worker_handle_reference.h" |
12 #include "content/child/service_worker/service_worker_provider_context.h" | 12 #include "content/child/service_worker/service_worker_provider_context.h" |
| 13 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
13 #include "content/child/service_worker/web_service_worker_impl.h" | 14 #include "content/child/service_worker/web_service_worker_impl.h" |
| 15 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
14 #include "content/child/thread_safe_sender.h" | 16 #include "content/child/thread_safe_sender.h" |
15 #include "content/common/service_worker/service_worker_messages.h" | 17 #include "content/common/service_worker/service_worker_messages.h" |
16 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h" | 18 #include "third_party/WebKit/public/platform/WebServiceWorkerProviderClient.h" |
17 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
18 | 20 |
19 using blink::WebURL; | 21 using blink::WebURL; |
20 | 22 |
21 namespace content { | 23 namespace content { |
22 | 24 |
23 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl( | 25 WebServiceWorkerProviderImpl::WebServiceWorkerProviderImpl( |
(...skipping 16 matching lines...) Expand all Loading... |
40 return; | 42 return; |
41 } | 43 } |
42 | 44 |
43 // TODO(kinuko): Here we could also register the current thread ID | 45 // TODO(kinuko): Here we could also register the current thread ID |
44 // on the provider context so that multiple WebServiceWorkerProviderImpl | 46 // on the provider context so that multiple WebServiceWorkerProviderImpl |
45 // (e.g. on document and on dedicated workers) can properly share | 47 // (e.g. on document and on dedicated workers) can properly share |
46 // the single provider context across threads. (http://crbug.com/366538 | 48 // the single provider context across threads. (http://crbug.com/366538 |
47 // for more context) | 49 // for more context) |
48 GetDispatcher()->AddScriptClient(provider_id_, client); | 50 GetDispatcher()->AddScriptClient(provider_id_, client); |
49 | 51 |
| 52 if (!context_->registration()) { |
| 53 // This provider is not associated with any registration. |
| 54 return; |
| 55 } |
| 56 |
| 57 // Set .ready if the associated registration has the active service worker. |
| 58 if (context_->active_handle_id() != kInvalidServiceWorkerHandleId) { |
| 59 WebServiceWorkerRegistrationImpl* registration = |
| 60 GetDispatcher()->FindServiceWorkerRegistration( |
| 61 context_->registration()->info(), false); |
| 62 if (!registration) { |
| 63 registration = GetDispatcher()->CreateServiceWorkerRegistration( |
| 64 context_->registration()->info(), false); |
| 65 ServiceWorkerVersionAttributes attrs = context_->GetVersionAttributes(); |
| 66 registration->SetInstalling( |
| 67 GetDispatcher()->GetServiceWorker(attrs.installing, false)); |
| 68 registration->SetWaiting( |
| 69 GetDispatcher()->GetServiceWorker(attrs.waiting, false)); |
| 70 registration->SetActive( |
| 71 GetDispatcher()->GetServiceWorker(attrs.active, false)); |
| 72 } |
| 73 client->setReadyRegistration(registration); |
| 74 } |
| 75 |
50 if (context_->controller_handle_id() != kInvalidServiceWorkerHandleId) { | 76 if (context_->controller_handle_id() != kInvalidServiceWorkerHandleId) { |
51 client->setController(GetDispatcher()->GetServiceWorker( | 77 client->setController(GetDispatcher()->GetServiceWorker( |
52 context_->controller()->info(), false)); | 78 context_->controller()->info(), false)); |
53 } | 79 } |
54 } | 80 } |
55 | 81 |
56 void WebServiceWorkerProviderImpl::registerServiceWorker( | 82 void WebServiceWorkerProviderImpl::registerServiceWorker( |
57 const WebURL& pattern, | 83 const WebURL& pattern, |
58 const WebURL& script_url, | 84 const WebURL& script_url, |
59 WebServiceWorkerRegistrationCallbacks* callbacks) { | 85 WebServiceWorkerRegistrationCallbacks* callbacks) { |
(...skipping 16 matching lines...) Expand all Loading... |
76 if (dispatcher) | 102 if (dispatcher) |
77 dispatcher->RemoveScriptClient(provider_id_); | 103 dispatcher->RemoveScriptClient(provider_id_); |
78 } | 104 } |
79 | 105 |
80 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { | 106 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { |
81 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 107 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
82 thread_safe_sender_.get()); | 108 thread_safe_sender_.get()); |
83 } | 109 } |
84 | 110 |
85 } // namespace content | 111 } // namespace content |
OLD | NEW |