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_message_filter.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_message_filter.h" |
24 #include "chrome/browser/renderer_host/database_dispatcher_host.h" | 24 #include "chrome/browser/renderer_host/database_dispatcher_host.h" |
25 #include "chrome/browser/renderer_host/file_utilities_dispatcher_host.h" | 25 #include "chrome/browser/renderer_host/file_utilities_message_filter.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" |
35 #include "chrome/common/render_messages.h" | 35 #include "chrome/common/render_messages.h" |
(...skipping 25 matching lines...) Expand all Loading... |
61 | 61 |
62 private: | 62 private: |
63 int render_process_unique_id_; | 63 int render_process_unique_id_; |
64 int render_view_id_; | 64 int render_view_id_; |
65 }; | 65 }; |
66 | 66 |
67 WorkerProcessHost::WorkerProcessHost( | 67 WorkerProcessHost::WorkerProcessHost( |
68 ResourceDispatcherHost* resource_dispatcher_host, | 68 ResourceDispatcherHost* resource_dispatcher_host, |
69 ChromeURLRequestContext *request_context) | 69 ChromeURLRequestContext *request_context) |
70 : BrowserChildProcessHost(WORKER_PROCESS, resource_dispatcher_host), | 70 : BrowserChildProcessHost(WORKER_PROCESS, resource_dispatcher_host), |
71 request_context_(request_context), | 71 request_context_(request_context) { |
72 ALLOW_THIS_IN_INITIALIZER_LIST(blob_dispatcher_host_( | |
73 new BlobDispatcherHost( | |
74 this->id(), request_context->blob_storage_context()))), | |
75 ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( | |
76 new FileSystemDispatcherHost(this, request_context))), | |
77 ALLOW_THIS_IN_INITIALIZER_LIST(file_utilities_dispatcher_host_( | |
78 new FileUtilitiesDispatcherHost(this, this->id()))), | |
79 ALLOW_THIS_IN_INITIALIZER_LIST(mime_registry_dispatcher_( | |
80 new MimeRegistryDispatcher(this))) { | |
81 next_route_id_callback_.reset(NewCallbackWithReturnValue( | 72 next_route_id_callback_.reset(NewCallbackWithReturnValue( |
82 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); | 73 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); |
83 db_dispatcher_host_ = new DatabaseDispatcherHost( | 74 db_dispatcher_host_ = new DatabaseDispatcherHost( |
84 request_context->database_tracker(), this, | 75 request_context->database_tracker(), this, |
85 request_context_->host_content_settings_map()); | 76 request_context_->host_content_settings_map()); |
86 } | 77 } |
87 | 78 |
88 WorkerProcessHost::~WorkerProcessHost() { | 79 WorkerProcessHost::~WorkerProcessHost() { |
89 for (size_t i = 0; i < filters_.size(); ++i) { | 80 for (size_t i = 0; i < filters_.size(); ++i) { |
90 filters_[i]->OnChannelClosing(); | 81 filters_[i]->OnChannelClosing(); |
91 filters_[i]->OnFilterRemoved(); | 82 filters_[i]->OnFilterRemoved(); |
92 } | 83 } |
93 | 84 |
94 // Shut down the database dispatcher host. | 85 // Shut down the database dispatcher host. |
95 db_dispatcher_host_->Shutdown(); | 86 db_dispatcher_host_->Shutdown(); |
96 | 87 |
97 // Shut down the blob dispatcher host. | |
98 blob_dispatcher_host_->Shutdown(); | |
99 | |
100 // Shut down the file system dispatcher host. | |
101 file_system_dispatcher_host_->Shutdown(); | |
102 | |
103 // Shut down the file utilities dispatcher host. | |
104 file_utilities_dispatcher_host_->Shutdown(); | |
105 | |
106 // Shut down the mime registry dispatcher host. | |
107 mime_registry_dispatcher_->Shutdown(); | |
108 | |
109 // Let interested observers know we are being deleted. | 88 // Let interested observers know we are being deleted. |
110 NotificationService::current()->Notify( | 89 NotificationService::current()->Notify( |
111 NotificationType::WORKER_PROCESS_HOST_SHUTDOWN, | 90 NotificationType::WORKER_PROCESS_HOST_SHUTDOWN, |
112 Source<WorkerProcessHost>(this), | 91 Source<WorkerProcessHost>(this), |
113 NotificationService::NoDetails()); | 92 NotificationService::NoDetails()); |
114 | 93 |
115 // If we crashed, tell the RenderViewHosts. | 94 // If we crashed, tell the RenderViewHosts. |
116 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 95 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
117 const WorkerDocumentSet::DocumentInfoSet& parents = | 96 const WorkerDocumentSet::DocumentInfoSet& parents = |
118 i->worker_document_set()->documents(); | 97 i->worker_document_set()->documents(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 base::PLATFORM_FILE_WRITE_ATTRIBUTES); | 196 base::PLATFORM_FILE_WRITE_ATTRIBUTES); |
218 } | 197 } |
219 | 198 |
220 CreateMessageFilters(); | 199 CreateMessageFilters(); |
221 | 200 |
222 return true; | 201 return true; |
223 } | 202 } |
224 | 203 |
225 void WorkerProcessHost::CreateMessageFilters() { | 204 void WorkerProcessHost::CreateMessageFilters() { |
226 filters_.push_back(new AppCacheDispatcherHost(request_context_, id())); | 205 filters_.push_back(new AppCacheDispatcherHost(request_context_, id())); |
| 206 filters_.push_back(new FileSystemDispatcherHost(request_context_)); |
| 207 filters_.push_back(new FileUtilitiesMessageFilter(id())); |
| 208 filters_.push_back( |
| 209 new BlobMessageFilter(id(), request_context_->blob_storage_context())); |
| 210 filters_.push_back(new MimeRegistryMessageFilter()); |
227 | 211 |
228 for (size_t i = 0; i < filters_.size(); ++i) | 212 for (size_t i = 0; i < filters_.size(); ++i) |
229 filters_[i]->OnFilterAdded(channel()); | 213 filters_[i]->OnFilterAdded(channel()); |
230 } | 214 } |
231 | 215 |
232 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { | 216 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { |
233 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( | 217 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( |
234 id(), instance.url()); | 218 id(), instance.url()); |
235 | 219 |
236 instances_.push_back(instance); | 220 instances_.push_back(instance); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 276 |
293 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { | 277 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { |
294 for (size_t i = 0; i < filters_.size(); ++i) { | 278 for (size_t i = 0; i < filters_.size(); ++i) { |
295 if (filters_[i]->OnMessageReceived(message)) | 279 if (filters_[i]->OnMessageReceived(message)) |
296 return; | 280 return; |
297 } | 281 } |
298 | 282 |
299 bool msg_is_ok = true; | 283 bool msg_is_ok = true; |
300 bool handled = | 284 bool handled = |
301 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 285 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
302 blob_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | |
303 file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | |
304 file_utilities_dispatcher_host_->OnMessageReceived(message) || | |
305 mime_registry_dispatcher_->OnMessageReceived(message) || | |
306 MessagePortDispatcher::GetInstance()->OnMessageReceived( | 286 MessagePortDispatcher::GetInstance()->OnMessageReceived( |
307 message, this, next_route_id_callback_.get(), &msg_is_ok); | 287 message, this, next_route_id_callback_.get(), &msg_is_ok); |
308 | 288 |
309 if (!handled) { | 289 if (!handled) { |
310 handled = true; | 290 handled = true; |
311 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) | 291 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) |
312 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWorker, OnCreateWorker) | 292 IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWorker, OnCreateWorker) |
313 IPC_MESSAGE_HANDLER(ViewHostMsg_LookupSharedWorker, OnLookupSharedWorker) | 293 IPC_MESSAGE_HANDLER(ViewHostMsg_LookupSharedWorker, OnLookupSharedWorker) |
314 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelCreateDedicatedWorker, | 294 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelCreateDedicatedWorker, |
315 OnCancelCreateDedicatedWorker) | 295 OnCancelCreateDedicatedWorker) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 filters_[i]->OnChannelConnected(peer_pid); | 336 filters_[i]->OnChannelConnected(peer_pid); |
357 } | 337 } |
358 | 338 |
359 void WorkerProcessHost::OnChannelError() { | 339 void WorkerProcessHost::OnChannelError() { |
360 for (size_t i = 0; i < filters_.size(); ++i) | 340 for (size_t i = 0; i < filters_.size(); ++i) |
361 filters_[i]->OnChannelError(); | 341 filters_[i]->OnChannelError(); |
362 } | 342 } |
363 | 343 |
364 void WorkerProcessHost::OnProcessLaunched() { | 344 void WorkerProcessHost::OnProcessLaunched() { |
365 db_dispatcher_host_->Init(handle()); | 345 db_dispatcher_host_->Init(handle()); |
366 file_system_dispatcher_host_->Init(handle()); | |
367 file_utilities_dispatcher_host_->Init(handle()); | |
368 } | 346 } |
369 | 347 |
370 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( | 348 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( |
371 IPC::Message::Sender* sender) { | 349 IPC::Message::Sender* sender) { |
372 // We don't keep callbacks for senders associated with workers, so figure out | 350 // 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 | 351 // what kind of sender this is, and cast it to the correct class to get the |
374 // callback. | 352 // callback. |
375 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); | 353 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::WORKER_PROCESS); |
376 !iter.Done(); ++iter) { | 354 !iter.Done(); ++iter) { |
377 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); | 355 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 } | 689 } |
712 } | 690 } |
713 return false; | 691 return false; |
714 } | 692 } |
715 | 693 |
716 WorkerProcessHost::WorkerInstance::SenderInfo | 694 WorkerProcessHost::WorkerInstance::SenderInfo |
717 WorkerProcessHost::WorkerInstance::GetSender() const { | 695 WorkerProcessHost::WorkerInstance::GetSender() const { |
718 DCHECK(NumSenders() == 1); | 696 DCHECK(NumSenders() == 1); |
719 return *senders_.begin(); | 697 return *senders_.begin(); |
720 } | 698 } |
OLD | NEW |