| 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/debug_util.h" | 12 #include "base/debug_util.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/appcache/appcache_dispatcher_host.h" | 16 #include "chrome/browser/appcache/appcache_dispatcher_host.h" |
| 17 #include "chrome/browser/chrome_thread.h" | 17 #include "chrome/browser/chrome_thread.h" |
| 18 #include "chrome/browser/child_process_security_policy.h" | 18 #include "chrome/browser/child_process_security_policy.h" |
| 19 #include "chrome/browser/file_system/file_system_dispatcher_host.h" |
| 19 #include "chrome/browser/net/chrome_url_request_context.h" | 20 #include "chrome/browser/net/chrome_url_request_context.h" |
| 20 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
| 21 #include "chrome/browser/renderer_host/database_dispatcher_host.h" | 22 #include "chrome/browser/renderer_host/database_dispatcher_host.h" |
| 22 #include "chrome/browser/renderer_host/render_view_host.h" | 23 #include "chrome/browser/renderer_host/render_view_host.h" |
| 23 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 24 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 24 #include "chrome/browser/renderer_host/resource_message_filter.h" | 25 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 25 #include "chrome/browser/worker_host/message_port_dispatcher.h" | 26 #include "chrome/browser/worker_host/message_port_dispatcher.h" |
| 26 #include "chrome/browser/worker_host/worker_service.h" | 27 #include "chrome/browser/worker_host/worker_service.h" |
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/debug_flags.h" | 29 #include "chrome/common/debug_flags.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 56 int render_process_unique_id_; | 57 int render_process_unique_id_; |
| 57 int render_view_id_; | 58 int render_view_id_; |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 WorkerProcessHost::WorkerProcessHost( | 61 WorkerProcessHost::WorkerProcessHost( |
| 61 ResourceDispatcherHost* resource_dispatcher_host, | 62 ResourceDispatcherHost* resource_dispatcher_host, |
| 62 ChromeURLRequestContext *request_context) | 63 ChromeURLRequestContext *request_context) |
| 63 : BrowserChildProcessHost(WORKER_PROCESS, resource_dispatcher_host), | 64 : BrowserChildProcessHost(WORKER_PROCESS, resource_dispatcher_host), |
| 64 request_context_(request_context), | 65 request_context_(request_context), |
| 65 appcache_dispatcher_host_( | 66 appcache_dispatcher_host_( |
| 66 new AppCacheDispatcherHost(request_context)) { | 67 new AppCacheDispatcherHost(request_context)), |
| 68 ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( |
| 69 new FileSystemDispatcherHost(this, |
| 70 request_context->file_system_host_context(), |
| 71 request_context->host_content_settings_map()))) { |
| 67 next_route_id_callback_.reset(NewCallbackWithReturnValue( | 72 next_route_id_callback_.reset(NewCallbackWithReturnValue( |
| 68 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); | 73 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); |
| 69 db_dispatcher_host_ = new DatabaseDispatcherHost( | 74 db_dispatcher_host_ = new DatabaseDispatcherHost( |
| 70 request_context->database_tracker(), this, | 75 request_context->database_tracker(), this, |
| 71 request_context_->host_content_settings_map()); | 76 request_context_->host_content_settings_map()); |
| 72 appcache_dispatcher_host_->Initialize(this); | 77 appcache_dispatcher_host_->Initialize(this); |
| 73 } | 78 } |
| 74 | 79 |
| 75 WorkerProcessHost::~WorkerProcessHost() { | 80 WorkerProcessHost::~WorkerProcessHost() { |
| 76 // Shut down the database dispatcher host. | 81 // Shut down the database dispatcher host. |
| 77 db_dispatcher_host_->Shutdown(); | 82 db_dispatcher_host_->Shutdown(); |
| 78 | 83 |
| 84 // Shut down the file system dispatcher host. |
| 85 file_system_dispatcher_host_->Shutdown(); |
| 86 |
| 79 // Let interested observers know we are being deleted. | 87 // Let interested observers know we are being deleted. |
| 80 NotificationService::current()->Notify( | 88 NotificationService::current()->Notify( |
| 81 NotificationType::WORKER_PROCESS_HOST_SHUTDOWN, | 89 NotificationType::WORKER_PROCESS_HOST_SHUTDOWN, |
| 82 Source<WorkerProcessHost>(this), | 90 Source<WorkerProcessHost>(this), |
| 83 NotificationService::NoDetails()); | 91 NotificationService::NoDetails()); |
| 84 | 92 |
| 85 // If we crashed, tell the RenderViewHosts. | 93 // If we crashed, tell the RenderViewHosts. |
| 86 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 94 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
| 87 const WorkerDocumentSet::DocumentInfoSet& parents = | 95 const WorkerDocumentSet::DocumentInfoSet& parents = |
| 88 i->worker_document_set()->documents(); | 96 i->worker_document_set()->documents(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 115 switches::kEnableNativeWebWorkers, | 123 switches::kEnableNativeWebWorkers, |
| 116 switches::kWebWorkerShareProcesses, | 124 switches::kWebWorkerShareProcesses, |
| 117 switches::kDisableApplicationCache, | 125 switches::kDisableApplicationCache, |
| 118 switches::kDisableDatabases, | 126 switches::kDisableDatabases, |
| 119 switches::kEnableLogging, | 127 switches::kEnableLogging, |
| 120 switches::kLoggingLevel, | 128 switches::kLoggingLevel, |
| 121 switches::kDisableWebSockets, | 129 switches::kDisableWebSockets, |
| 122 #if defined(OS_WIN) | 130 #if defined(OS_WIN) |
| 123 switches::kDisableDesktopNotifications, | 131 switches::kDisableDesktopNotifications, |
| 124 #endif | 132 #endif |
| 133 switches::kEnableFileSystem, |
| 125 }; | 134 }; |
| 126 cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), kSwitchNames, | 135 cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(), kSwitchNames, |
| 127 arraysize(kSwitchNames)); | 136 arraysize(kSwitchNames)); |
| 128 | 137 |
| 129 #if defined(OS_POSIX) | 138 #if defined(OS_POSIX) |
| 130 bool use_zygote = true; | 139 bool use_zygote = true; |
| 131 | 140 |
| 132 if (CommandLine::ForCurrentProcess()->HasSwitch( | 141 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 133 switches::kWaitForDebuggerChildren)) { | 142 switches::kWaitForDebuggerChildren)) { |
| 134 // Look to pass-on the kWaitForDebugger flag. | 143 // Look to pass-on the kWaitForDebugger flag. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 break; | 235 break; |
| 227 } | 236 } |
| 228 } | 237 } |
| 229 } | 238 } |
| 230 | 239 |
| 231 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { | 240 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 232 bool msg_is_ok = true; | 241 bool msg_is_ok = true; |
| 233 bool handled = | 242 bool handled = |
| 234 appcache_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 243 appcache_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
| 235 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 244 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
| 245 file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
| 236 MessagePortDispatcher::GetInstance()->OnMessageReceived( | 246 MessagePortDispatcher::GetInstance()->OnMessageReceived( |
| 237 message, this, next_route_id_callback_.get(), &msg_is_ok); | 247 message, this, next_route_id_callback_.get(), &msg_is_ok); |
| 238 | 248 |
| 239 if (!handled) { | 249 if (!handled) { |
| 240 handled = true; | 250 handled = true; |
| 241 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) | 251 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) |
| 242 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWorker, OnCreateWorker) | 252 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWorker, OnCreateWorker) |
| 243 IPC_MESSAGE_HANDLER(ViewHostMsg_LookupSharedWorker, OnLookupSharedWorker) | 253 IPC_MESSAGE_HANDLER(ViewHostMsg_LookupSharedWorker, OnLookupSharedWorker) |
| 244 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelCreateDedicatedWorker, | 254 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelCreateDedicatedWorker, |
| 245 OnCancelCreateDedicatedWorker) | 255 OnCancelCreateDedicatedWorker) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 274 instances_.erase(i); | 284 instances_.erase(i); |
| 275 UpdateTitle(); | 285 UpdateTitle(); |
| 276 } | 286 } |
| 277 break; | 287 break; |
| 278 } | 288 } |
| 279 } | 289 } |
| 280 } | 290 } |
| 281 | 291 |
| 282 void WorkerProcessHost::OnProcessLaunched() { | 292 void WorkerProcessHost::OnProcessLaunched() { |
| 283 db_dispatcher_host_->Init(handle()); | 293 db_dispatcher_host_->Init(handle()); |
| 294 file_system_dispatcher_host_->Init(handle()); |
| 284 } | 295 } |
| 285 | 296 |
| 286 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( | 297 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( |
| 287 IPC::Message::Sender* sender) { | 298 IPC::Message::Sender* sender) { |
| 288 // We don't keep callbacks for senders associated with workers, so figure out | 299 // We don't keep callbacks for senders associated with workers, so figure out |
| 289 // what kind of sender this is, and cast it to the correct class to get the | 300 // what kind of sender this is, and cast it to the correct class to get the |
| 290 // callback. | 301 // callback. |
| 291 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); | 302 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); |
| 292 !iter.Done(); ++iter) { | 303 !iter.Done(); ++iter) { |
| 293 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); | 304 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 608 } |
| 598 } | 609 } |
| 599 return false; | 610 return false; |
| 600 } | 611 } |
| 601 | 612 |
| 602 WorkerProcessHost::WorkerInstance::SenderInfo | 613 WorkerProcessHost::WorkerInstance::SenderInfo |
| 603 WorkerProcessHost::WorkerInstance::GetSender() const { | 614 WorkerProcessHost::WorkerInstance::GetSender() const { |
| 604 DCHECK(NumSenders() == 1); | 615 DCHECK(NumSenders() == 1); |
| 605 return *senders_.begin(); | 616 return *senders_.begin(); |
| 606 } | 617 } |
| OLD | NEW |