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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 if (!client) { | 38 if (!client) { |
39 RemoveScriptClient(); | 39 RemoveScriptClient(); |
40 return; | 40 return; |
41 } | 41 } |
42 | 42 |
43 // TODO(kinuko): Here we could also register the current thread ID | 43 // TODO(kinuko): Here we could also register the current thread ID |
44 // on the provider context so that multiple WebServiceWorkerProviderImpl | 44 // on the provider context so that multiple WebServiceWorkerProviderImpl |
45 // (e.g. on document and on dedicated workers) can properly share | 45 // (e.g. on document and on dedicated workers) can properly share |
46 // the single provider context across threads. (http://crbug.com/366538 | 46 // the single provider context across threads. (http://crbug.com/366538 |
47 // for more context) | 47 // for more context) |
48 scoped_ptr<ServiceWorkerHandleReference> current = | |
49 context_->GetCurrentServiceWorkerHandle(); | |
50 GetDispatcher()->AddScriptClient(provider_id_, client); | 48 GetDispatcher()->AddScriptClient(provider_id_, client); |
51 if (!current) | 49 |
| 50 int handle_id = context_->current_handle_id(); |
| 51 if (handle_id == kInvalidServiceWorkerHandleId) |
52 return; | 52 return; |
53 | 53 |
54 int handle_id = current->info().handle_id; | 54 client->setCurrentServiceWorker( |
55 if (handle_id != kInvalidServiceWorkerHandleId) { | 55 GetDispatcher()->GetServiceWorker(context_->current()->info(), false)); |
56 scoped_ptr<WebServiceWorkerImpl> worker( | |
57 new WebServiceWorkerImpl(current.Pass(), thread_safe_sender_)); | |
58 client->setCurrentServiceWorker(worker.release()); | |
59 } | |
60 } | 56 } |
61 | 57 |
62 void WebServiceWorkerProviderImpl::registerServiceWorker( | 58 void WebServiceWorkerProviderImpl::registerServiceWorker( |
63 const WebURL& pattern, | 59 const WebURL& pattern, |
64 const WebURL& script_url, | 60 const WebURL& script_url, |
65 WebServiceWorkerCallbacks* callbacks) { | 61 WebServiceWorkerCallbacks* callbacks) { |
66 GetDispatcher()->RegisterServiceWorker( | 62 GetDispatcher()->RegisterServiceWorker( |
67 provider_id_, pattern, script_url, callbacks); | 63 provider_id_, pattern, script_url, callbacks); |
68 } | 64 } |
69 | 65 |
(...skipping 12 matching lines...) Expand all Loading... |
82 if (dispatcher) | 78 if (dispatcher) |
83 dispatcher->RemoveScriptClient(provider_id_); | 79 dispatcher->RemoveScriptClient(provider_id_); |
84 } | 80 } |
85 | 81 |
86 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { | 82 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { |
87 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 83 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
88 thread_safe_sender_); | 84 thread_safe_sender_); |
89 } | 85 } |
90 | 86 |
91 } // namespace content | 87 } // namespace content |
OLD | NEW |