| 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/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
| 10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( | 41 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| 42 int render_process_id, | 42 int render_process_id, |
| 43 MessagePortMessageFilter* message_port_message_filter) | 43 MessagePortMessageFilter* message_port_message_filter) |
| 44 : BrowserMessageFilter(kFilteredMessageClasses, | 44 : BrowserMessageFilter(kFilteredMessageClasses, |
| 45 arraysize(kFilteredMessageClasses)), | 45 arraysize(kFilteredMessageClasses)), |
| 46 render_process_id_(render_process_id), | 46 render_process_id_(render_process_id), |
| 47 message_port_message_filter_(message_port_message_filter) {} | 47 message_port_message_filter_(message_port_message_filter), |
| 48 channel_ready_(false) { |
| 49 } |
| 48 | 50 |
| 49 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { | 51 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { |
| 50 if (context_) { | 52 if (context_) { |
| 51 context_->RemoveAllProviderHostsForProcess(render_process_id_); | 53 context_->RemoveAllProviderHostsForProcess(render_process_id_); |
| 52 context_->embedded_worker_registry()->RemoveChildProcessSender( | 54 context_->embedded_worker_registry()->RemoveChildProcessSender( |
| 53 render_process_id_); | 55 render_process_id_); |
| 54 } | 56 } |
| 55 } | 57 } |
| 56 | 58 |
| 57 void ServiceWorkerDispatcherHost::Init( | 59 void ServiceWorkerDispatcherHost::Init( |
| 58 ServiceWorkerContextWrapper* context_wrapper) { | 60 ServiceWorkerContextWrapper* context_wrapper) { |
| 59 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 61 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 60 BrowserThread::PostTask( | 62 BrowserThread::PostTask( |
| 61 BrowserThread::IO, FROM_HERE, | 63 BrowserThread::IO, FROM_HERE, |
| 62 base::Bind(&ServiceWorkerDispatcherHost::Init, | 64 base::Bind(&ServiceWorkerDispatcherHost::Init, |
| 63 this, make_scoped_refptr(context_wrapper))); | 65 this, make_scoped_refptr(context_wrapper))); |
| 64 return; | 66 return; |
| 65 } | 67 } |
| 66 context_ = context_wrapper->context()->AsWeakPtr(); | 68 context_ = context_wrapper->context()->AsWeakPtr(); |
| 67 context_->embedded_worker_registry()->AddChildProcessSender( | 69 context_->embedded_worker_registry()->AddChildProcessSender( |
| 68 render_process_id_, this); | 70 render_process_id_, this); |
| 69 } | 71 } |
| 70 | 72 |
| 73 void ServiceWorkerDispatcherHost::OnFilterAdded(IPC::Channel* channel) { |
| 74 BrowserMessageFilter::OnFilterAdded(channel); |
| 75 channel_ready_ = true; |
| 76 std::vector<IPC::Message*> messages; |
| 77 pending_messages_.release(&messages); |
| 78 for (size_t i = 0; i < messages.size(); ++i) { |
| 79 BrowserMessageFilter::Send(messages[i]); |
| 80 } |
| 81 } |
| 82 |
| 71 void ServiceWorkerDispatcherHost::OnDestruct() const { | 83 void ServiceWorkerDispatcherHost::OnDestruct() const { |
| 72 BrowserThread::DeleteOnIOThread::Destruct(this); | 84 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 73 } | 85 } |
| 74 | 86 |
| 75 bool ServiceWorkerDispatcherHost::OnMessageReceived( | 87 bool ServiceWorkerDispatcherHost::OnMessageReceived( |
| 76 const IPC::Message& message, | 88 const IPC::Message& message, |
| 77 bool* message_was_ok) { | 89 bool* message_was_ok) { |
| 78 bool handled = true; | 90 bool handled = true; |
| 79 IPC_BEGIN_MESSAGE_MAP_EX( | 91 IPC_BEGIN_MESSAGE_MAP_EX( |
| 80 ServiceWorkerDispatcherHost, message, *message_was_ok) | 92 ServiceWorkerDispatcherHost, message, *message_was_ok) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 109 | 121 |
| 110 if (!handled && context_) { | 122 if (!handled && context_) { |
| 111 handled = context_->embedded_worker_registry()->OnMessageReceived(message); | 123 handled = context_->embedded_worker_registry()->OnMessageReceived(message); |
| 112 if (!handled) | 124 if (!handled) |
| 113 BadMessageReceived(); | 125 BadMessageReceived(); |
| 114 } | 126 } |
| 115 | 127 |
| 116 return handled; | 128 return handled; |
| 117 } | 129 } |
| 118 | 130 |
| 131 bool ServiceWorkerDispatcherHost::Send(IPC::Message* message) { |
| 132 if (channel_ready_) { |
| 133 BrowserMessageFilter::Send(message); |
| 134 // Don't bother passing through Send()'s result: it's not reliable. |
| 135 return true; |
| 136 } |
| 137 |
| 138 pending_messages_.push_back(message); |
| 139 return true; |
| 140 } |
| 141 |
| 119 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( | 142 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( |
| 120 scoped_ptr<ServiceWorkerHandle> handle) { | 143 scoped_ptr<ServiceWorkerHandle> handle) { |
| 121 int handle_id = handle->handle_id(); | 144 int handle_id = handle->handle_id(); |
| 122 handles_.AddWithID(handle.release(), handle_id); | 145 handles_.AddWithID(handle.release(), handle_id); |
| 123 } | 146 } |
| 124 | 147 |
| 125 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( | 148 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
| 126 int thread_id, | 149 int thread_id, |
| 127 int request_id, | 150 int request_id, |
| 128 int provider_id, | 151 int provider_id, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 ServiceWorkerStatusCode status) { | 399 ServiceWorkerStatusCode status) { |
| 377 base::string16 error_message; | 400 base::string16 error_message; |
| 378 blink::WebServiceWorkerError::ErrorType error_type; | 401 blink::WebServiceWorkerError::ErrorType error_type; |
| 379 GetServiceWorkerRegistrationStatusResponse( | 402 GetServiceWorkerRegistrationStatusResponse( |
| 380 status, &error_type, &error_message); | 403 status, &error_type, &error_message); |
| 381 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 404 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 382 thread_id, request_id, error_type, error_message)); | 405 thread_id, request_id, error_type, error_message)); |
| 383 } | 406 } |
| 384 | 407 |
| 385 } // namespace content | 408 } // namespace content |
| OLD | NEW |