| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/worker_host/worker_process_host.h" | 5 #include "chrome/browser/worker_host/worker_process_host.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/appcache/appcache_dispatcher_host.h" | 15 #include "chrome/browser/appcache/appcache_dispatcher_host.h" |
| 16 #include "chrome/browser/browser_thread.h" | 16 #include "chrome/browser/browser_thread.h" |
| 17 #include "chrome/browser/child_process_security_policy.h" | 17 #include "chrome/browser/child_process_security_policy.h" |
| 18 #include "chrome/browser/content_settings/host_content_settings_map.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 19 #include "chrome/browser/file_system/file_system_dispatcher_host.h" | 19 #include "chrome/browser/file_system/file_system_dispatcher_host.h" |
| 20 #include "chrome/browser/mime_registry_dispatcher.h" | 20 #include "chrome/browser/mime_registry_dispatcher.h" |
| 21 #include "chrome/browser/net/chrome_url_request_context.h" | 21 #include "chrome/browser/net/chrome_url_request_context.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/renderer_host/blob_dispatcher_host.h" | 23 #include "chrome/browser/renderer_host/blob_dispatcher_host.h" |
| 24 #include "chrome/browser/renderer_host/database_dispatcher_host.h" | 24 #include "chrome/browser/renderer_host/database_message_filter.h" |
| 25 #include "chrome/browser/renderer_host/file_utilities_dispatcher_host.h" | 25 #include "chrome/browser/renderer_host/file_utilities_dispatcher_host.h" |
| 26 #include "chrome/browser/renderer_host/render_view_host.h" | 26 #include "chrome/browser/renderer_host/render_view_host.h" |
| 27 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 27 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 28 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" | 28 #include "chrome/browser/renderer_host/render_view_host_notification_task.h" |
| 29 #include "chrome/browser/renderer_host/resource_message_filter.h" | 29 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 30 #include "chrome/browser/worker_host/message_port_dispatcher.h" | 30 #include "chrome/browser/worker_host/message_port_dispatcher.h" |
| 31 #include "chrome/browser/worker_host/worker_service.h" | 31 #include "chrome/browser/worker_host/worker_service.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/debug_flags.h" | 33 #include "chrome/common/debug_flags.h" |
| 34 #include "chrome/common/notification_service.h" | 34 #include "chrome/common/notification_service.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 new BlobDispatcherHost( | 73 new BlobDispatcherHost( |
| 74 this->id(), request_context->blob_storage_context()))), | 74 this->id(), request_context->blob_storage_context()))), |
| 75 ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( | 75 ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( |
| 76 new FileSystemDispatcherHost(this, request_context))), | 76 new FileSystemDispatcherHost(this, request_context))), |
| 77 ALLOW_THIS_IN_INITIALIZER_LIST(file_utilities_dispatcher_host_( | 77 ALLOW_THIS_IN_INITIALIZER_LIST(file_utilities_dispatcher_host_( |
| 78 new FileUtilitiesDispatcherHost(this, this->id()))), | 78 new FileUtilitiesDispatcherHost(this, this->id()))), |
| 79 ALLOW_THIS_IN_INITIALIZER_LIST(mime_registry_dispatcher_( | 79 ALLOW_THIS_IN_INITIALIZER_LIST(mime_registry_dispatcher_( |
| 80 new MimeRegistryDispatcher(this))) { | 80 new MimeRegistryDispatcher(this))) { |
| 81 next_route_id_callback_.reset(NewCallbackWithReturnValue( | 81 next_route_id_callback_.reset(NewCallbackWithReturnValue( |
| 82 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); | 82 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); |
| 83 db_dispatcher_host_ = new DatabaseDispatcherHost( | |
| 84 request_context->database_tracker(), this, | |
| 85 request_context_->host_content_settings_map()); | |
| 86 } | 83 } |
| 87 | 84 |
| 88 WorkerProcessHost::~WorkerProcessHost() { | 85 WorkerProcessHost::~WorkerProcessHost() { |
| 89 for (size_t i = 0; i < filters_.size(); ++i) { | 86 for (size_t i = 0; i < filters_.size(); ++i) { |
| 90 filters_[i]->OnChannelClosing(); | 87 filters_[i]->OnChannelClosing(); |
| 91 filters_[i]->OnFilterRemoved(); | 88 filters_[i]->OnFilterRemoved(); |
| 92 } | 89 } |
| 93 | 90 |
| 94 // Shut down the database dispatcher host. | |
| 95 db_dispatcher_host_->Shutdown(); | |
| 96 | |
| 97 // Shut down the blob dispatcher host. | 91 // Shut down the blob dispatcher host. |
| 98 blob_dispatcher_host_->Shutdown(); | 92 blob_dispatcher_host_->Shutdown(); |
| 99 | 93 |
| 100 // Shut down the file system dispatcher host. | 94 // Shut down the file system dispatcher host. |
| 101 file_system_dispatcher_host_->Shutdown(); | 95 file_system_dispatcher_host_->Shutdown(); |
| 102 | 96 |
| 103 // Shut down the file utilities dispatcher host. | 97 // Shut down the file utilities dispatcher host. |
| 104 file_utilities_dispatcher_host_->Shutdown(); | 98 file_utilities_dispatcher_host_->Shutdown(); |
| 105 | 99 |
| 106 // Shut down the mime registry dispatcher host. | 100 // Shut down the mime registry dispatcher host. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 base::PLATFORM_FILE_WRITE_ATTRIBUTES); | 211 base::PLATFORM_FILE_WRITE_ATTRIBUTES); |
| 218 } | 212 } |
| 219 | 213 |
| 220 CreateMessageFilters(); | 214 CreateMessageFilters(); |
| 221 | 215 |
| 222 return true; | 216 return true; |
| 223 } | 217 } |
| 224 | 218 |
| 225 void WorkerProcessHost::CreateMessageFilters() { | 219 void WorkerProcessHost::CreateMessageFilters() { |
| 226 filters_.push_back(new AppCacheDispatcherHost(request_context_, id())); | 220 filters_.push_back(new AppCacheDispatcherHost(request_context_, id())); |
| 221 filters_.push_back(new DatabaseMessageFilter( |
| 222 request_context_->database_tracker(), |
| 223 request_context_->host_content_settings_map())); |
| 227 | 224 |
| 228 for (size_t i = 0; i < filters_.size(); ++i) | 225 for (size_t i = 0; i < filters_.size(); ++i) |
| 229 filters_[i]->OnFilterAdded(channel()); | 226 filters_[i]->OnFilterAdded(channel()); |
| 230 } | 227 } |
| 231 | 228 |
| 232 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { | 229 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { |
| 233 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( | 230 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( |
| 234 id(), instance.url()); | 231 id(), instance.url()); |
| 235 | 232 |
| 236 instances_.push_back(instance); | 233 instances_.push_back(instance); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 288 } |
| 292 | 289 |
| 293 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { | 290 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 294 for (size_t i = 0; i < filters_.size(); ++i) { | 291 for (size_t i = 0; i < filters_.size(); ++i) { |
| 295 if (filters_[i]->OnMessageReceived(message)) | 292 if (filters_[i]->OnMessageReceived(message)) |
| 296 return; | 293 return; |
| 297 } | 294 } |
| 298 | 295 |
| 299 bool msg_is_ok = true; | 296 bool msg_is_ok = true; |
| 300 bool handled = | 297 bool handled = |
| 301 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | |
| 302 blob_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 298 blob_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
| 303 file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 299 file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
| 304 file_utilities_dispatcher_host_->OnMessageReceived(message) || | 300 file_utilities_dispatcher_host_->OnMessageReceived(message) || |
| 305 mime_registry_dispatcher_->OnMessageReceived(message) || | 301 mime_registry_dispatcher_->OnMessageReceived(message) || |
| 306 MessagePortDispatcher::GetInstance()->OnMessageReceived( | 302 MessagePortDispatcher::GetInstance()->OnMessageReceived( |
| 307 message, this, next_route_id_callback_.get(), &msg_is_ok); | 303 message, this, next_route_id_callback_.get(), &msg_is_ok); |
| 308 | 304 |
| 309 if (!handled) { | 305 if (!handled) { |
| 310 handled = true; | 306 handled = true; |
| 311 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) | 307 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 for (size_t i = 0; i < filters_.size(); ++i) | 351 for (size_t i = 0; i < filters_.size(); ++i) |
| 356 filters_[i]->OnChannelConnected(peer_pid); | 352 filters_[i]->OnChannelConnected(peer_pid); |
| 357 } | 353 } |
| 358 | 354 |
| 359 void WorkerProcessHost::OnChannelError() { | 355 void WorkerProcessHost::OnChannelError() { |
| 360 for (size_t i = 0; i < filters_.size(); ++i) | 356 for (size_t i = 0; i < filters_.size(); ++i) |
| 361 filters_[i]->OnChannelError(); | 357 filters_[i]->OnChannelError(); |
| 362 } | 358 } |
| 363 | 359 |
| 364 void WorkerProcessHost::OnProcessLaunched() { | 360 void WorkerProcessHost::OnProcessLaunched() { |
| 365 db_dispatcher_host_->Init(handle()); | |
| 366 file_system_dispatcher_host_->Init(handle()); | 361 file_system_dispatcher_host_->Init(handle()); |
| 367 file_utilities_dispatcher_host_->Init(handle()); | 362 file_utilities_dispatcher_host_->Init(handle()); |
| 368 } | 363 } |
| 369 | 364 |
| 370 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( | 365 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( |
| 371 IPC::Message::Sender* sender) { | 366 IPC::Message::Sender* sender) { |
| 372 // We don't keep callbacks for senders associated with workers, so figure out | 367 // We don't keep callbacks for senders associated with workers, so figure out |
| 373 // what kind of sender this is, and cast it to the correct class to get the | 368 // what kind of sender this is, and cast it to the correct class to get the |
| 374 // callback. | 369 // callback. |
| 375 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); | 370 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 } | 706 } |
| 712 } | 707 } |
| 713 return false; | 708 return false; |
| 714 } | 709 } |
| 715 | 710 |
| 716 WorkerProcessHost::WorkerInstance::SenderInfo | 711 WorkerProcessHost::WorkerInstance::SenderInfo |
| 717 WorkerProcessHost::WorkerInstance::GetSender() const { | 712 WorkerProcessHost::WorkerInstance::GetSender() const { |
| 718 DCHECK(NumSenders() == 1); | 713 DCHECK(NumSenders() == 1); |
| 719 return *senders_.begin(); | 714 return *senders_.begin(); |
| 720 } | 715 } |
| OLD | NEW |