Chromium Code Reviews| 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" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 appcache_dispatcher_host_( | |
| 73 new AppCacheDispatcherHost(request_context)), | |
| 74 ALLOW_THIS_IN_INITIALIZER_LIST(blob_dispatcher_host_( | 72 ALLOW_THIS_IN_INITIALIZER_LIST(blob_dispatcher_host_( |
| 75 new BlobDispatcherHost( | 73 new BlobDispatcherHost( |
| 76 this->id(), request_context->blob_storage_context()))), | 74 this->id(), request_context->blob_storage_context()))), |
| 77 ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( | 75 ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_( |
| 78 new FileSystemDispatcherHost(this, request_context))), | 76 new FileSystemDispatcherHost(this, request_context))), |
| 79 ALLOW_THIS_IN_INITIALIZER_LIST(file_utilities_dispatcher_host_( | 77 ALLOW_THIS_IN_INITIALIZER_LIST(file_utilities_dispatcher_host_( |
| 80 new FileUtilitiesDispatcherHost(this, this->id()))), | 78 new FileUtilitiesDispatcherHost(this, this->id()))), |
| 81 ALLOW_THIS_IN_INITIALIZER_LIST(mime_registry_dispatcher_( | 79 ALLOW_THIS_IN_INITIALIZER_LIST(mime_registry_dispatcher_( |
| 82 new MimeRegistryDispatcher(this))) { | 80 new MimeRegistryDispatcher(this))) { |
| 83 next_route_id_callback_.reset(NewCallbackWithReturnValue( | 81 next_route_id_callback_.reset(NewCallbackWithReturnValue( |
| 84 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); | 82 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); |
| 85 db_dispatcher_host_ = new DatabaseDispatcherHost( | 83 db_dispatcher_host_ = new DatabaseDispatcherHost( |
| 86 request_context->database_tracker(), this, | 84 request_context->database_tracker(), this, |
| 87 request_context_->host_content_settings_map()); | 85 request_context_->host_content_settings_map()); |
| 88 appcache_dispatcher_host_->Initialize(this); | |
| 89 } | 86 } |
| 90 | 87 |
| 91 WorkerProcessHost::~WorkerProcessHost() { | 88 WorkerProcessHost::~WorkerProcessHost() { |
| 89 for (size_t i = 0; i < filters_.size(); ++i) { | |
| 90 filters_[i]->OnChannelClosing(); | |
| 91 filters_[i]->OnFilterRemoved(); | |
| 92 } | |
| 93 | |
| 92 // Shut down the database dispatcher host. | 94 // Shut down the database dispatcher host. |
| 93 db_dispatcher_host_->Shutdown(); | 95 db_dispatcher_host_->Shutdown(); |
| 94 | 96 |
| 95 // Shut down the blob dispatcher host. | 97 // Shut down the blob dispatcher host. |
| 96 blob_dispatcher_host_->Shutdown(); | 98 blob_dispatcher_host_->Shutdown(); |
| 97 | 99 |
| 98 // Shut down the file system dispatcher host. | 100 // Shut down the file system dispatcher host. |
| 99 file_system_dispatcher_host_->Shutdown(); | 101 file_system_dispatcher_host_->Shutdown(); |
| 100 | 102 |
| 101 // Shut down the file utilities dispatcher host. | 103 // Shut down the file utilities dispatcher host. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 base::PLATFORM_FILE_CREATE_ALWAYS | | 210 base::PLATFORM_FILE_CREATE_ALWAYS | |
| 209 base::PLATFORM_FILE_READ | | 211 base::PLATFORM_FILE_READ | |
| 210 base::PLATFORM_FILE_WRITE | | 212 base::PLATFORM_FILE_WRITE | |
| 211 base::PLATFORM_FILE_EXCLUSIVE_READ | | 213 base::PLATFORM_FILE_EXCLUSIVE_READ | |
| 212 base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 214 base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
| 213 base::PLATFORM_FILE_ASYNC | | 215 base::PLATFORM_FILE_ASYNC | |
| 214 base::PLATFORM_FILE_TRUNCATE | | 216 base::PLATFORM_FILE_TRUNCATE | |
| 215 base::PLATFORM_FILE_WRITE_ATTRIBUTES); | 217 base::PLATFORM_FILE_WRITE_ATTRIBUTES); |
| 216 } | 218 } |
| 217 | 219 |
| 220 CreateMessageFilters(); | |
| 221 | |
| 218 return true; | 222 return true; |
| 219 } | 223 } |
| 220 | 224 |
| 225 void WorkerProcessHost::CreateMessageFilters() { | |
| 226 filters_.push_back(new AppCacheDispatcherHost(request_context_, id())); | |
|
jennb
2010/12/04 00:31:51
I'm guessing you're switching the other dispatcher
| |
| 227 | |
| 228 for (size_t i = 0; i < filters_.size(); ++i) | |
| 229 filters_[i]->OnFilterAdded(channel()); | |
| 230 } | |
| 231 | |
| 221 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { | 232 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { |
| 222 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( | 233 ChildProcessSecurityPolicy::GetInstance()->GrantRequestURL( |
| 223 id(), instance.url()); | 234 id(), instance.url()); |
| 224 | 235 |
| 225 instances_.push_back(instance); | 236 instances_.push_back(instance); |
| 226 | 237 |
| 227 WorkerProcessMsg_CreateWorker_Params params; | 238 WorkerProcessMsg_CreateWorker_Params params; |
| 228 params.url = instance.url(); | 239 params.url = instance.url(); |
| 229 params.is_shared = instance.shared(); | 240 params.is_shared = instance.shared(); |
| 230 params.name = instance.name(); | 241 params.name = instance.name(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 // Set the closed flag - this will stop any further messages from | 284 // Set the closed flag - this will stop any further messages from |
| 274 // being sent to the worker (messages can still be sent from the worker, | 285 // being sent to the worker (messages can still be sent from the worker, |
| 275 // for exception reporting, etc). | 286 // for exception reporting, etc). |
| 276 i->set_closed(true); | 287 i->set_closed(true); |
| 277 break; | 288 break; |
| 278 } | 289 } |
| 279 } | 290 } |
| 280 } | 291 } |
| 281 | 292 |
| 282 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { | 293 void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) { |
| 294 for (size_t i = 0; i < filters_.size(); ++i) { | |
| 295 if (filters_[i]->OnMessageReceived(message)) | |
| 296 return; | |
| 297 } | |
| 298 | |
| 283 bool msg_is_ok = true; | 299 bool msg_is_ok = true; |
| 284 bool handled = | 300 bool handled = |
| 285 appcache_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | |
| 286 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 301 db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
|
jennb
2010/12/04 00:31:51
Will all these also become filters eventually?
| |
| 287 blob_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 302 blob_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
| 288 file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || | 303 file_system_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) || |
| 289 file_utilities_dispatcher_host_->OnMessageReceived(message) || | 304 file_utilities_dispatcher_host_->OnMessageReceived(message) || |
| 290 mime_registry_dispatcher_->OnMessageReceived(message) || | 305 mime_registry_dispatcher_->OnMessageReceived(message) || |
| 291 MessagePortDispatcher::GetInstance()->OnMessageReceived( | 306 MessagePortDispatcher::GetInstance()->OnMessageReceived( |
| 292 message, this, next_route_id_callback_.get(), &msg_is_ok); | 307 message, this, next_route_id_callback_.get(), &msg_is_ok); |
| 293 | 308 |
| 294 if (!handled) { | 309 if (!handled) { |
| 295 handled = true; | 310 handled = true; |
| 296 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) | 311 IPC_BEGIN_MESSAGE_MAP_EX(WorkerProcessHost, message, msg_is_ok) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 | 344 |
| 330 if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) { | 345 if (message.type() == WorkerHostMsg_WorkerContextDestroyed::ID) { |
| 331 instances_.erase(i); | 346 instances_.erase(i); |
| 332 UpdateTitle(); | 347 UpdateTitle(); |
| 333 } | 348 } |
| 334 break; | 349 break; |
| 335 } | 350 } |
| 336 } | 351 } |
| 337 } | 352 } |
| 338 | 353 |
| 354 void WorkerProcessHost::OnChannelConnected(int32 peer_pid) { | |
| 355 for (size_t i = 0; i < filters_.size(); ++i) | |
| 356 filters_[i]->OnChannelConnected(peer_pid); | |
| 357 } | |
| 358 | |
| 359 void WorkerProcessHost::OnChannelError() { | |
| 360 for (size_t i = 0; i < filters_.size(); ++i) | |
| 361 filters_[i]->OnChannelError(); | |
| 362 } | |
| 363 | |
| 339 void WorkerProcessHost::OnProcessLaunched() { | 364 void WorkerProcessHost::OnProcessLaunched() { |
| 340 db_dispatcher_host_->Init(handle()); | 365 db_dispatcher_host_->Init(handle()); |
| 341 file_system_dispatcher_host_->Init(handle()); | 366 file_system_dispatcher_host_->Init(handle()); |
| 342 file_utilities_dispatcher_host_->Init(handle()); | 367 file_utilities_dispatcher_host_->Init(handle()); |
| 343 } | 368 } |
| 344 | 369 |
| 345 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( | 370 CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback( |
| 346 IPC::Message::Sender* sender) { | 371 IPC::Message::Sender* sender) { |
| 347 // We don't keep callbacks for senders associated with workers, so figure out | 372 // We don't keep callbacks for senders associated with workers, so figure out |
| 348 // what kind of sender this is, and cast it to the correct class to get the | 373 // what kind of sender this is, and cast it to the correct class to get the |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 } | 711 } |
| 687 } | 712 } |
| 688 return false; | 713 return false; |
| 689 } | 714 } |
| 690 | 715 |
| 691 WorkerProcessHost::WorkerInstance::SenderInfo | 716 WorkerProcessHost::WorkerInstance::SenderInfo |
| 692 WorkerProcessHost::WorkerInstance::GetSender() const { | 717 WorkerProcessHost::WorkerInstance::GetSender() const { |
| 693 DCHECK(NumSenders() == 1); | 718 DCHECK(NumSenders() == 1); |
| 694 return *senders_.begin(); | 719 return *senders_.begin(); |
| 695 } | 720 } |
| OLD | NEW |