| 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/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/threading/thread_local.h" | 8 #include "base/threading/thread_local.h" |
| 9 #include "content/child/service_worker/web_service_worker_impl.h" | 9 #include "content/child/service_worker/web_service_worker_impl.h" |
| 10 #include "content/child/thread_safe_sender.h" | 10 #include "content/child/thread_safe_sender.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 107 |
| 108 ServiceWorkerDispatcher* dispatcher = | 108 ServiceWorkerDispatcher* dispatcher = |
| 109 new ServiceWorkerDispatcher(thread_safe_sender); | 109 new ServiceWorkerDispatcher(thread_safe_sender); |
| 110 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) | 110 if (WorkerTaskRunner::Instance()->CurrentWorkerId()) |
| 111 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); | 111 WorkerTaskRunner::Instance()->AddStopObserver(dispatcher); |
| 112 return dispatcher; | 112 return dispatcher; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void ServiceWorkerDispatcher::OnRegistered(int32 thread_id, | 115 void ServiceWorkerDispatcher::OnRegistered(int32 thread_id, |
| 116 int32 request_id, | 116 int32 request_id, |
| 117 int64 version_id) { | 117 int handle_id) { |
| 118 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = | 118 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = |
| 119 pending_callbacks_.Lookup(request_id); | 119 pending_callbacks_.Lookup(request_id); |
| 120 DCHECK(callbacks); | 120 DCHECK(callbacks); |
| 121 if (!callbacks) | 121 if (!callbacks) |
| 122 return; | 122 return; |
| 123 | 123 |
| 124 // the browser has to generate the registration_id so the same | 124 // the browser has to generate the registration_id so the same |
| 125 // worker can be called from different renderer contexts. However, | 125 // worker can be called from different renderer contexts. However, |
| 126 // the impl object doesn't have to be the same instance across calls | 126 // the impl object doesn't have to be the same instance across calls |
| 127 // unless we require the DOM objects to be identical when there's a | 127 // unless we require the DOM objects to be identical when there's a |
| 128 // duplicate registration. So for now we mint a new object each | 128 // duplicate registration. So for now we mint a new object each |
| 129 // time. | 129 // time. |
| 130 scoped_ptr<WebServiceWorkerImpl> worker( | 130 scoped_ptr<WebServiceWorkerImpl> worker( |
| 131 new WebServiceWorkerImpl(version_id, thread_safe_sender_)); | 131 new WebServiceWorkerImpl(handle_id, thread_safe_sender_)); |
| 132 callbacks->onSuccess(worker.release()); | 132 callbacks->onSuccess(worker.release()); |
| 133 pending_callbacks_.Remove(request_id); | 133 pending_callbacks_.Remove(request_id); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void ServiceWorkerDispatcher::OnUnregistered( | 136 void ServiceWorkerDispatcher::OnUnregistered( |
| 137 int32 thread_id, | 137 int32 thread_id, |
| 138 int32 request_id) { | 138 int32 request_id) { |
| 139 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = | 139 WebServiceWorkerProvider::WebServiceWorkerCallbacks* callbacks = |
| 140 pending_callbacks_.Lookup(request_id); | 140 pending_callbacks_.Lookup(request_id); |
| 141 DCHECK(callbacks); | 141 DCHECK(callbacks); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 159 | 159 |
| 160 scoped_ptr<WebServiceWorkerError> error( | 160 scoped_ptr<WebServiceWorkerError> error( |
| 161 new WebServiceWorkerError(error_type, message)); | 161 new WebServiceWorkerError(error_type, message)); |
| 162 callbacks->onError(error.release()); | 162 callbacks->onError(error.release()); |
| 163 pending_callbacks_.Remove(request_id); | 163 pending_callbacks_.Remove(request_id); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void ServiceWorkerDispatcher::OnWorkerRunLoopStopped() { delete this; } | 166 void ServiceWorkerDispatcher::OnWorkerRunLoopStopped() { delete this; } |
| 167 | 167 |
| 168 } // namespace content | 168 } // namespace content |
| OLD | NEW |