| 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/renderer/service_worker/service_worker_context_client.h" | 5 #include "content/renderer/service_worker/service_worker_context_client.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| 11 #include "content/child/thread_safe_sender.h" | 11 #include "content/child/thread_safe_sender.h" |
| 12 #include "content/common/service_worker_messages.h" |
| 12 #include "content/renderer/render_thread_impl.h" | 13 #include "content/renderer/render_thread_impl.h" |
| 13 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 14 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
| 14 #include "ipc/ipc_message_macros.h" | 15 #include "ipc/ipc_message_macros.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 #include "webkit/child/worker_task_runner.h" | 17 #include "webkit/child/worker_task_runner.h" |
| 17 | 18 |
| 18 using webkit_glue::WorkerTaskRunner; | 19 using webkit_glue::WorkerTaskRunner; |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 proxy_(NULL) { | 55 proxy_(NULL) { |
| 55 } | 56 } |
| 56 | 57 |
| 57 ServiceWorkerContextClient::~ServiceWorkerContextClient() { | 58 ServiceWorkerContextClient::~ServiceWorkerContextClient() { |
| 58 DCHECK(g_worker_client_tls.Pointer()->Get() != NULL); | 59 DCHECK(g_worker_client_tls.Pointer()->Get() != NULL); |
| 59 g_worker_client_tls.Pointer()->Set(NULL); | 60 g_worker_client_tls.Pointer()->Set(NULL); |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool ServiceWorkerContextClient::OnMessageReceived( | 63 bool ServiceWorkerContextClient::OnMessageReceived( |
| 63 const IPC::Message& msg) { | 64 const IPC::Message& msg) { |
| 64 NOTIMPLEMENTED(); | 65 bool handled = true; |
| 65 return false; | 66 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, msg) |
| 67 IPC_MESSAGE_HANDLER(ServiceWorkerContextMsg_FetchEvent, OnFetchEvent) |
| 68 IPC_MESSAGE_UNHANDLED(handled = false) |
| 69 IPC_END_MESSAGE_MAP() |
| 70 return handled; |
| 66 } | 71 } |
| 67 | 72 |
| 68 void ServiceWorkerContextClient::workerContextFailedToStart() | 73 void ServiceWorkerContextClient::workerContextFailedToStart() { |
| 69 { | |
| 70 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); | 74 DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); |
| 71 DCHECK(!proxy_); | 75 DCHECK(!proxy_); |
| 72 | 76 |
| 73 RenderThreadImpl::current()->embedded_worker_dispatcher()-> | 77 RenderThreadImpl::current()->embedded_worker_dispatcher()-> |
| 74 WorkerContextDestroyed(embedded_worker_id_); | 78 WorkerContextDestroyed(embedded_worker_id_); |
| 75 } | 79 } |
| 76 | 80 |
| 77 void ServiceWorkerContextClient::workerContextStarted( | 81 void ServiceWorkerContextClient::workerContextStarted( |
| 78 blink::WebServiceWorkerContextProxy* proxy) { | 82 blink::WebServiceWorkerContextProxy* proxy) { |
| 79 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); | 83 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); |
| 80 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); | 84 DCHECK(g_worker_client_tls.Pointer()->Get() == NULL); |
| 81 g_worker_client_tls.Pointer()->Set(this); | 85 g_worker_client_tls.Pointer()->Set(this); |
| 82 proxy_ = proxy; | 86 proxy_ = proxy; |
| 83 | 87 |
| 84 // TODO(kinuko): Send WorkerStarted message to the browser with the | 88 sender_->Send(new ServiceWorkerHostMsg_WorkerStarted( |
| 85 // current thread ID so that the browser can start sending embedded worker | 89 WorkerTaskRunner::Instance()->CurrentWorkerId(), |
| 86 // messages directly to this client. | 90 embedded_worker_id_)); |
| 87 } | 91 } |
| 88 | 92 |
| 89 void ServiceWorkerContextClient::workerContextDestroyed() { | 93 void ServiceWorkerContextClient::workerContextDestroyed() { |
| 90 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); | 94 DCHECK_NE(0, WorkerTaskRunner::Instance()->CurrentWorkerId()); |
| 91 proxy_ = NULL; | 95 proxy_ = NULL; |
| 92 main_thread_proxy_->PostTask( | 96 main_thread_proxy_->PostTask( |
| 93 FROM_HERE, | 97 FROM_HERE, |
| 94 base::Bind(&CallWorkerContextDestroyedOnMainThread, | 98 base::Bind(&CallWorkerContextDestroyedOnMainThread, |
| 95 embedded_worker_id_)); | 99 embedded_worker_id_)); |
| 96 } | 100 } |
| 97 | 101 |
| 102 void ServiceWorkerContextClient::OnFetchEvent( |
| 103 int thread_id, |
| 104 int embedded_worker_id, |
| 105 const ServiceWorkerFetchRequest& request) { |
| 106 // TODO(kinuko): Implement. |
| 107 // This is to call WebServiceWorkerContextProxy's dispatchFetchEvent method. |
| 108 NOTIMPLEMENTED(); |
| 109 } |
| 110 |
| 98 } // namespace content | 111 } // namespace content |
| OLD | NEW |