Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/service_worker/service_worker_context_client.h" | |
| 6 | |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "base/message_loop/message_loop_proxy.h" | |
| 9 #include "base/pickle.h" | |
| 10 #include "base/threading/thread_local.h" | |
| 11 #include "content/child/thread_safe_sender.h" | |
| 12 #include "content/renderer/render_thread_impl.h" | |
| 13 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | |
| 14 #include "ipc/ipc_message_macros.h" | |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | |
| 16 #include "webkit/child/worker_task_runner.h" | |
| 17 | |
| 18 using webkit_glue::WorkerTaskRunner; | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 namespace { | |
| 23 | |
| 24 // For now client must be a per-thread instance. | |
| 25 // TODO(kinuko): This needs to be refactored when we start using thread pool | |
| 26 // or having multiple clients per one thread. | |
| 27 base::LazyInstance<base::ThreadLocalPointer<ServiceWorkerContextClient> >:: | |
| 28 Leaky g_worker_client_tls = LAZY_INSTANCE_INITIALIZER; | |
| 29 | |
| 30 void CallWorkerContextDestroyedOnMainThread(int embedded_worker_id) { | |
| 31 if (!RenderThreadImpl::current() || | |
| 32 !RenderThreadImpl::current()->embedded_worker_dispatcher()) | |
| 33 return; | |
| 34 RenderThreadImpl::current()->embedded_worker_dispatcher()-> | |
| 35 WorkerContextDestroyed(embedded_worker_id); | |
| 36 } | |
| 37 | |
| 38 } // namespace | |
| 39 | |
| 40 ServiceWorkerContextClient* | |
| 41 ServiceWorkerContextClient::ThreadSpecificInstance() { | |
| 42 return g_worker_client_tls.Pointer()->Get(); | |
| 43 } | |
| 44 | |
| 45 ServiceWorkerContextClient::ServiceWorkerContextClient( | |
| 46 int32 embedded_worker_id, | |
| 47 int64 service_worker_version_id, | |
| 48 const GURL& script_url) | |
| 49 : embedded_worker_id_(embedded_worker_id), | |
| 50 service_worker_version_id_(service_worker_version_id), | |
| 51 script_url_(script_url), | |
| 52 sender_(ChildThread::current()->thread_safe_sender()), | |
| 53 main_thread_proxy_(base::MessageLoopProxy::current()), | |
| 54 proxy_(NULL) { | |
| 55 } | |
| 56 | |
| 57 ServiceWorkerContextClient::~ServiceWorkerContextClient() { | |
| 58 DCHECK(g_worker_client_tls.Pointer()->Get() != NULL); | |
| 59 g_worker_client_tls.Pointer()->Set(NULL); | |
| 60 } | |
| 61 | |
| 62 void ServiceWorkerContextClient::OnMessageReceived( | |
| 63 const IPC::Message& msg) { | |
| 64 NOTIMPLEMENTED(); | |
| 65 } | |
| 66 | |
| 67 void ServiceWorkerContextClient::workerContextStarted( | |
| 68 blink::WebServiceWorkerContextProxy* proxy) { | |
| 69 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); | |
| 70 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | |
| 71 g_worker_client_tls.Pointer()->Set(this); | |
| 72 proxy_ = proxy; | |
| 73 | |
| 74 // TODO(kinuko): Send WorkerStarted message to the browser with the | |
| 75 // current thread ID so that the browser can start sending embedded worker | |
| 76 // messages directly to this client. | |
|
michaeln
2013/11/13 00:31:37
i guess you mean messages for this likes of oninst
kinuko
2013/11/18 14:09:48
Yep.
| |
| 77 } | |
| 78 | |
| 79 void ServiceWorkerContextClient::workerContextClosed() { | |
| 80 NOTIMPLEMENTED(); | |
| 81 } | |
| 82 | |
| 83 void ServiceWorkerContextClient::workerContextDestroyed() { | |
| 84 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); | |
| 85 proxy_ = NULL; | |
| 86 main_thread_proxy_->PostTask( | |
| 87 FROM_HERE, | |
| 88 base::Bind(&CallWorkerContextDestroyedOnMainThread, | |
| 89 embedded_worker_id_)); | |
| 90 } | |
| 91 | |
| 92 } // namespace content | |
| OLD | NEW |