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/browser_thread.h" | 17 #include "chrome/browser/browser_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/file_system/file_system_dispatcher_host.h" |
20 #include "chrome/browser/net/chrome_url_request_context.h" | 20 #include "chrome/browser/net/chrome_url_request_context.h" |
21 #include "chrome/browser/profile.h" | 21 #include "chrome/browser/profile.h" |
22 #include "chrome/browser/renderer_host/blob_dispatcher_host.h" | 22 #include "chrome/browser/renderer_host/blob_dispatcher_host.h" |
23 #include "chrome/browser/renderer_host/database_dispatcher_host.h" | 23 #include "chrome/browser/renderer_host/database_dispatcher_host.h" |
| 24 #include "chrome/browser/renderer_host/file_utilities_dispatcher_host.h" |
24 #include "chrome/browser/renderer_host/render_view_host.h" | 25 #include "chrome/browser/renderer_host/render_view_host.h" |
25 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 26 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
26 #include "chrome/browser/renderer_host/resource_message_filter.h" | 27 #include "chrome/browser/renderer_host/resource_message_filter.h" |
27 #include "chrome/browser/worker_host/message_port_dispatcher.h" | 28 #include "chrome/browser/worker_host/message_port_dispatcher.h" |
28 #include "chrome/browser/worker_host/worker_service.h" | 29 #include "chrome/browser/worker_host/worker_service.h" |
29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
30 #include "chrome/common/debug_flags.h" | 31 #include "chrome/common/debug_flags.h" |
31 #include "chrome/common/notification_service.h" | 32 #include "chrome/common/notification_service.h" |
32 #include "chrome/common/render_messages.h" | 33 #include "chrome/common/render_messages.h" |
33 #include "chrome/common/render_messages_params.h" | 34 #include "chrome/common/render_messages_params.h" |
34 #include "chrome/common/result_codes.h" | 35 #include "chrome/common/result_codes.h" |
35 #include "chrome/common/worker_messages.h" | 36 #include "chrome/common/worker_messages.h" |
| 37 #include "net/base/mime_util.h" |
36 #include "ipc/ipc_switches.h" | 38 #include "ipc/ipc_switches.h" |
37 #include "net/base/registry_controlled_domain.h" | 39 #include "net/base/registry_controlled_domain.h" |
38 | 40 |
39 // Notifies RenderViewHost that one or more worker objects crashed. | 41 // Notifies RenderViewHost that one or more worker objects crashed. |
40 class WorkerCrashTask : public Task { | 42 class WorkerCrashTask : public Task { |
41 public: | 43 public: |
42 WorkerCrashTask(int render_process_unique_id, int render_view_id) | 44 WorkerCrashTask(int render_process_unique_id, int render_view_id) |
43 : render_process_unique_id_(render_process_unique_id), | 45 : render_process_unique_id_(render_process_unique_id), |
44 render_view_id_(render_view_id) { } | 46 render_view_id_(render_view_id) { } |
45 | 47 |
(...skipping 17 matching lines...) Expand all Loading... |
63 ResourceDispatcherHost* resource_dispatcher_host, | 65 ResourceDispatcherHost* resource_dispatcher_host, |
64 ChromeURLRequestContext *request_context) | 66 ChromeURLRequestContext *request_context) |
65 : BrowserChildProcessHost(WORKER_PROCESS, resource_dispatcher_host), | 67 : BrowserChildProcessHost(WORKER_PROCESS, resource_dispatcher_host), |
66 request_context_(request_context), | 68 request_context_(request_context), |
67 appcache_dispatcher_host_( | 69 appcache_dispatcher_host_( |
68 new AppCacheDispatcherHost(request_context)), | 70 new AppCacheDispatcherHost(request_context)), |
69 ALLOW_THIS_IN_INITIALIZER_LIST(blob_dispatcher_host_( | 71 ALLOW_THIS_IN_INITIALIZER_LIST(blob_dispatcher_host_( |
70 new BlobDispatcherHost( | 72 new BlobDispatcherHost( |
71 this->id(), request_context->blob_storage_context()))), | 73 this->id(), request_context->blob_storage_context()))), |
72 ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( | 74 ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( |
73 new FileSystemDispatcherHost(this, request_context))) { | 75 new FileSystemDispatcherHost(this, request_context))), |
| 76 ALLOW_THIS_IN_INITIALIZER_LIST(file_utilities_dispatcher_host_( |
| 77 new FileUtilitiesDispatcherHost(this, this->id()))) { |
74 next_route_id_callback_.reset(NewCallbackWithReturnValue( | 78 next_route_id_callback_.reset(NewCallbackWithReturnValue( |
75 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); | 79 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); |
76 db_dispatcher_host_ = new DatabaseDispatcherHost( | 80 db_dispatcher_host_ = new DatabaseDispatcherHost( |
77 request_context->database_tracker(), this, | 81 request_context->database_tracker(), this, |
78 request_context_->host_content_settings_map()); | 82 request_context_->host_content_settings_map()); |
79 appcache_dispatcher_host_->Initialize(this); | 83 appcache_dispatcher_host_->Initialize(this); |
80 } | 84 } |
81 | 85 |
82 WorkerProcessHost::~WorkerProcessHost() { | 86 WorkerProcessHost::~WorkerProcessHost() { |
83 // Shut down the database dispatcher host. | 87 // Shut down the database dispatcher host. |
84 db_dispatcher_host_->Shutdown(); | 88 db_dispatcher_host_->Shutdown(); |
85 | 89 |
86 // Shut down the blob dispatcher host. | 90 // Shut down the blob dispatcher host. |
87 blob_dispatcher_host_->Shutdown(); | 91 blob_dispatcher_host_->Shutdown(); |
88 | 92 |
89 // Shut down the file system dispatcher host. | 93 // Shut down the file system dispatcher host. |
90 file_system_dispatcher_host_->Shutdown(); | 94 file_system_dispatcher_host_->Shutdown(); |
91 | 95 |
| 96 // Shut down the file utilities dispatcher host. |
| 97 file_utilities_dispatcher_host_->Shutdown(); |
| 98 |
92 // Let interested observers know we are being deleted. | 99 // Let interested observers know we are being deleted. |
93 NotificationService::current()->Notify( | 100 NotificationService::current()->Notify( |
94 NotificationType::WORKER_PROCESS_HOST_SHUTDOWN, | 101 NotificationType::WORKER_PROCESS_HOST_SHUTDOWN, |
95 Source<WorkerProcessHost>(this), | 102 Source<WorkerProcessHost>(this), |
96 NotificationService::NoDetails()); | 103 NotificationService::NoDetails()); |
97 | 104 |
98 // If we crashed, tell the RenderViewHosts. | 105 // If we crashed, tell the RenderViewHosts. |
99 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 106 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
100 const WorkerDocumentSet::DocumentInfoSet& parents = | 107 const WorkerDocumentSet::DocumentInfoSet& parents = |
101 i->worker_document_set()->documents(); | 108 i->worker_document_set()->documents(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 } | 249 } |
243 } | 250 } |
244 | 251 |
245 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { | 252 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { |
246 bool msg_is_ok = true; | 253 bool msg_is_ok = true; |
247 bool handled = | 254 bool handled = |
248 appcache_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 255 appcache_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
249 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 256 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
250 blob_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 257 blob_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
251 file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 258 file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
| 259 file_utilities_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
252 MessagePortDispatcher::GetInstance()->OnMessageReceived( | 260 MessagePortDispatcher::GetInstance()->OnMessageReceived( |
253 message, this, next_route_id_callback_.get(), &msg_is_ok); | 261 message, this, next_route_id_callback_.get(), &msg_is_ok); |
254 | 262 |
255 if (!handled) { | 263 if (!handled) { |
256 handled = true; | 264 handled = true; |
257 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) | 265 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) |
258 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWorker, OnCreateWorker) | 266 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWorker, OnCreateWorker) |
259 IPC_MESSAGE_HANDLER(ViewHostMsg_LookupSharedWorker, OnLookupSharedWorker) | 267 IPC_MESSAGE_HANDLER(ViewHostMsg_LookupSharedWorker, OnLookupSharedWorker) |
260 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelCreateDedicatedWorker, | 268 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelCreateDedicatedWorker, |
261 OnCancelCreateDedicatedWorker) | 269 OnCancelCreateDedicatedWorker) |
262 IPC_MESSAGE_HANDLER(WorkerHostMsg_WorkerContextClosed, | 270 IPC_MESSAGE_HANDLER(WorkerHostMsg_WorkerContextClosed, |
263 OnWorkerContextClosed); | 271 OnWorkerContextClosed); |
264 IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardToWorker, | 272 IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardToWorker, |
265 OnForwardToWorker) | 273 OnForwardToWorker) |
| 274 IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromExtension, |
| 275 OnGetMimeTypeFromExtension) |
| 276 IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromFile, |
| 277 OnGetMimeTypeFromFile) |
| 278 IPC_MESSAGE_HANDLER(ViewHostMsg_GetPreferredExtensionForMimeType, |
| 279 OnGetPreferredExtensionForMimeType) |
266 IPC_MESSAGE_UNHANDLED(handled = false) | 280 IPC_MESSAGE_UNHANDLED(handled = false) |
267 IPC_END_MESSAGE_MAP_EX() | 281 IPC_END_MESSAGE_MAP_EX() |
268 } | 282 } |
269 | 283 |
270 if (!msg_is_ok) { | 284 if (!msg_is_ok) { |
271 NOTREACHED(); | 285 NOTREACHED(); |
272 base::KillProcess(handle(), ResultCodes::KILLED_BAD_MESSAGE, false); | 286 base::KillProcess(handle(), ResultCodes::KILLED_BAD_MESSAGE, false); |
273 } | 287 } |
274 | 288 |
275 if (handled) | 289 if (handled) |
(...skipping 15 matching lines...) Expand all Loading... |
291 UpdateTitle(); | 305 UpdateTitle(); |
292 } | 306 } |
293 break; | 307 break; |
294 } | 308 } |
295 } | 309 } |
296 } | 310 } |
297 | 311 |
298 void WorkerProcessHost::OnProcessLaunched() { | 312 void WorkerProcessHost::OnProcessLaunched() { |
299 db_dispatcher_host_->Init(handle()); | 313 db_dispatcher_host_->Init(handle()); |
300 file_system_dispatcher_host_->Init(handle()); | 314 file_system_dispatcher_host_->Init(handle()); |
| 315 file_utilities_dispatcher_host_->Init(handle()); |
301 } | 316 } |
302 | 317 |
303 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( | 318 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( |
304 IPC::Message::Sender* sender) { | 319 IPC::Message::Sender* sender) { |
305 // We don't keep callbacks for senders associated with workers, so figure out | 320 // We don't keep callbacks for senders associated with workers, so figure out |
306 // what kind of sender this is, and cast it to the correct class to get the | 321 // what kind of sender this is, and cast it to the correct class to get the |
307 // callback. | 322 // callback. |
308 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); | 323 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); |
309 !iter.Done(); ++iter) { | 324 !iter.Done(); ++iter) { |
310 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); | 325 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 } | 495 } |
481 | 496 |
482 void WorkerProcessHost::OnCancelCreateDedicatedWorker(int route_id) { | 497 void WorkerProcessHost::OnCancelCreateDedicatedWorker(int route_id) { |
483 WorkerService::GetInstance()->CancelCreateDedicatedWorker(this, route_id); | 498 WorkerService::GetInstance()->CancelCreateDedicatedWorker(this, route_id); |
484 } | 499 } |
485 | 500 |
486 void WorkerProcessHost::OnForwardToWorker(const IPC::Message& message) { | 501 void WorkerProcessHost::OnForwardToWorker(const IPC::Message& message) { |
487 WorkerService::GetInstance()->ForwardMessage(message, this); | 502 WorkerService::GetInstance()->ForwardMessage(message, this); |
488 } | 503 } |
489 | 504 |
| 505 void WorkerProcessHost::OnGetMimeTypeFromExtension( |
| 506 const FilePath::StringType& ext, std::string* mime_type) { |
| 507 net::GetMimeTypeFromExtension(ext, mime_type); |
| 508 } |
| 509 |
| 510 void WorkerProcessHost::OnGetMimeTypeFromFile( |
| 511 const FilePath& file_path, std::string* mime_type) { |
| 512 net::GetMimeTypeFromFile(file_path, mime_type); |
| 513 } |
| 514 |
| 515 void WorkerProcessHost::OnGetPreferredExtensionForMimeType( |
| 516 const std::string& mime_type, FilePath::StringType* ext) { |
| 517 net::GetPreferredExtensionForMimeType(mime_type, ext); |
| 518 } |
| 519 |
490 void WorkerProcessHost::DocumentDetached(IPC::Message::Sender* parent, | 520 void WorkerProcessHost::DocumentDetached(IPC::Message::Sender* parent, |
491 unsigned long long document_id) { | 521 unsigned long long document_id) { |
492 // Walk all instances and remove the document from their document set. | 522 // Walk all instances and remove the document from their document set. |
493 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { | 523 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { |
494 if (!i->shared()) { | 524 if (!i->shared()) { |
495 ++i; | 525 ++i; |
496 } else { | 526 } else { |
497 i->worker_document_set()->Remove(parent, document_id); | 527 i->worker_document_set()->Remove(parent, document_id); |
498 if (i->worker_document_set()->IsEmpty()) { | 528 if (i->worker_document_set()->IsEmpty()) { |
499 // This worker has no more associated documents - shut it down. | 529 // This worker has no more associated documents - shut it down. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 } | 644 } |
615 } | 645 } |
616 return false; | 646 return false; |
617 } | 647 } |
618 | 648 |
619 WorkerProcessHost::WorkerInstance::SenderInfo | 649 WorkerProcessHost::WorkerInstance::SenderInfo |
620 WorkerProcessHost::WorkerInstance::GetSender() const { | 650 WorkerProcessHost::WorkerInstance::GetSender() const { |
621 DCHECK(NumSenders() == 1); | 651 DCHECK(NumSenders() == 1); |
622 return *senders_.begin(); | 652 return *senders_.begin(); |
623 } | 653 } |
OLD | NEW |