Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/worker_host/worker_process_host.h" | 5 #include "content/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/base_switches.h" | 10 #include "base/base_switches.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "content/browser/appcache/appcache_dispatcher_host.h" | 18 #include "content/browser/appcache/appcache_dispatcher_host.h" |
| 19 #include "content/browser/browser_child_process_host_impl.h" | 19 #include "content/browser/browser_child_process_host_impl.h" |
| 20 #include "content/browser/child_process_security_policy.h" | 20 #include "content/browser/child_process_security_policy.h" |
| 21 #include "content/browser/debugger/worker_devtools_manager.h" | |
| 21 #include "content/browser/debugger/worker_devtools_message_filter.h" | 22 #include "content/browser/debugger/worker_devtools_message_filter.h" |
| 22 #include "content/browser/file_system/file_system_dispatcher_host.h" | 23 #include "content/browser/file_system/file_system_dispatcher_host.h" |
| 23 #include "content/browser/mime_registry_message_filter.h" | 24 #include "content/browser/mime_registry_message_filter.h" |
| 24 #include "content/browser/renderer_host/blob_message_filter.h" | 25 #include "content/browser/renderer_host/blob_message_filter.h" |
| 25 #include "content/browser/renderer_host/database_message_filter.h" | 26 #include "content/browser/renderer_host/database_message_filter.h" |
| 26 #include "content/browser/renderer_host/file_utilities_message_filter.h" | 27 #include "content/browser/renderer_host/file_utilities_message_filter.h" |
| 27 #include "content/browser/renderer_host/render_view_host.h" | 28 #include "content/browser/renderer_host/render_view_host.h" |
| 28 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" | 29 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" |
| 29 #include "content/browser/resource_context.h" | 30 #include "content/browser/resource_context.h" |
| 30 #include "content/browser/worker_host/message_port_service.h" | 31 #include "content/browser/worker_host/message_port_service.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 45 #include "net/base/registry_controlled_domain.h" | 46 #include "net/base/registry_controlled_domain.h" |
| 46 #include "ui/base/ui_base_switches.h" | 47 #include "ui/base/ui_base_switches.h" |
| 47 #include "webkit/fileapi/file_system_context.h" | 48 #include "webkit/fileapi/file_system_context.h" |
| 48 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 49 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
| 49 #include "webkit/glue/resource_type.h" | 50 #include "webkit/glue/resource_type.h" |
| 50 | 51 |
| 51 using content::BrowserThread; | 52 using content::BrowserThread; |
| 52 using content::ChildProcessData; | 53 using content::ChildProcessData; |
| 53 using content::ChildProcessHost; | 54 using content::ChildProcessHost; |
| 54 using content::UserMetricsAction; | 55 using content::UserMetricsAction; |
| 56 using content::WorkerDevToolsManager; | |
| 55 using content::WorkerServiceImpl; | 57 using content::WorkerServiceImpl; |
| 56 | 58 |
| 57 namespace { | 59 namespace { |
| 58 | 60 |
| 59 // Helper class that we pass to SocketStreamDispatcherHost so that it can find | 61 // Helper class that we pass to SocketStreamDispatcherHost so that it can find |
| 60 // the right net::URLRequestContext for a request. | 62 // the right net::URLRequestContext for a request. |
| 61 class URLRequestContextSelector | 63 class URLRequestContextSelector |
| 62 : public ResourceMessageFilter::URLRequestContextSelector { | 64 : public ResourceMessageFilter::URLRequestContextSelector { |
| 63 public: | 65 public: |
| 64 explicit URLRequestContextSelector( | 66 explicit URLRequestContextSelector( |
| 65 net::URLRequestContext* url_request_context) | 67 net::URLRequestContext* url_request_context) |
| 66 : url_request_context_(url_request_context) { | 68 : url_request_context_(url_request_context) { |
| 67 } | 69 } |
| 68 virtual ~URLRequestContextSelector() {} | 70 virtual ~URLRequestContextSelector() {} |
| 69 | 71 |
| 70 virtual net::URLRequestContext* GetRequestContext( | 72 virtual net::URLRequestContext* GetRequestContext( |
| 71 ResourceType::Type resource_type) { | 73 ResourceType::Type resource_type) { |
| 72 return url_request_context_; | 74 return url_request_context_; |
| 73 } | 75 } |
| 74 | 76 |
| 75 private: | 77 private: |
| 76 net::URLRequestContext* url_request_context_; | 78 net::URLRequestContext* url_request_context_; |
| 77 }; | 79 }; |
| 78 | 80 |
| 81 std::vector<std::pair<int, int> > GetRenderViewIDsForWorker( | |
| 82 WorkerProcessHost* process, | |
| 83 int worker_route_id) { | |
| 84 std::vector<std::pair<int, int> > result; | |
|
Andrew T Wilson (Slow)
2012/02/01 05:51:37
How many copies of the vector does this end up cre
jam
2012/02/01 16:53:53
yep: see http://en.wikipedia.org/wiki/Return_value
| |
| 85 WorkerProcessHost::Instances::const_iterator i; | |
| 86 for (i = process->instances().begin(); i != process->instances().end(); ++i) { | |
| 87 if (i->worker_route_id() != worker_route_id) | |
| 88 continue; | |
| 89 const WorkerDocumentSet::DocumentInfoSet& documents = | |
| 90 i->worker_document_set()->documents(); | |
| 91 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = | |
| 92 documents.begin(); doc != documents.end(); ++doc) { | |
| 93 result.push_back( | |
| 94 std::make_pair(doc->render_process_id(), doc->render_view_id())); | |
| 95 } | |
| 96 break; | |
| 97 } | |
| 98 return result; | |
| 99 } | |
| 100 | |
| 79 } // namespace | 101 } // namespace |
| 80 | 102 |
| 81 // Notifies RenderViewHost that one or more worker objects crashed. | 103 // Notifies RenderViewHost that one or more worker objects crashed. |
| 82 void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { | 104 void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { |
| 83 RenderViewHost* host = | 105 RenderViewHost* host = |
| 84 RenderViewHost::FromID(render_process_unique_id, render_view_id); | 106 RenderViewHost::FromID(render_process_unique_id, render_view_id); |
| 85 if (host) | 107 if (host) |
| 86 host->delegate()->WorkerCrashed(); | 108 host->delegate()->WorkerCrashed(); |
| 87 } | 109 } |
| 88 | 110 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 } | 388 } |
| 367 } | 389 } |
| 368 | 390 |
| 369 void WorkerProcessHost::OnAllowDatabase(int worker_route_id, | 391 void WorkerProcessHost::OnAllowDatabase(int worker_route_id, |
| 370 const GURL& url, | 392 const GURL& url, |
| 371 const string16& name, | 393 const string16& name, |
| 372 const string16& display_name, | 394 const string16& display_name, |
| 373 unsigned long estimated_size, | 395 unsigned long estimated_size, |
| 374 bool* result) { | 396 bool* result) { |
| 375 *result = content::GetContentClient()->browser()->AllowWorkerDatabase( | 397 *result = content::GetContentClient()->browser()->AllowWorkerDatabase( |
| 376 worker_route_id, url, name, display_name, estimated_size, this); | 398 url, name, display_name, estimated_size, *resource_context_, |
| 399 GetRenderViewIDsForWorker(this, worker_route_id)); | |
| 377 } | 400 } |
| 378 | 401 |
| 379 void WorkerProcessHost::OnAllowFileSystem(int worker_route_id, | 402 void WorkerProcessHost::OnAllowFileSystem(int worker_route_id, |
| 380 const GURL& url, | 403 const GURL& url, |
| 381 bool* result) { | 404 bool* result) { |
| 382 *result = content::GetContentClient()->browser()->AllowWorkerFileSystem( | 405 *result = content::GetContentClient()->browser()->AllowWorkerFileSystem( |
| 383 worker_route_id, url, this); | 406 url, *resource_context_, |
| 407 GetRenderViewIDsForWorker(this, worker_route_id)); | |
| 384 } | 408 } |
| 385 | 409 |
| 386 void WorkerProcessHost::RelayMessage( | 410 void WorkerProcessHost::RelayMessage( |
| 387 const IPC::Message& message, | 411 const IPC::Message& message, |
| 388 WorkerMessageFilter* filter, | 412 WorkerMessageFilter* filter, |
| 389 int route_id) { | 413 int route_id) { |
| 390 if (message.type() == WorkerMsg_PostMessage::ID) { | 414 if (message.type() == WorkerMsg_PostMessage::ID) { |
| 391 // We want to send the receiver a routing id for the new channel, so | 415 // We want to send the receiver a routing id for the new channel, so |
| 392 // crack the message first. | 416 // crack the message first. |
| 393 string16 msg; | 417 string16 msg; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 route_id, sent_message_port_id, new_routing_id)); | 457 route_id, sent_message_port_id, new_routing_id)); |
| 434 | 458 |
| 435 // Send any queued messages for the sent port. | 459 // Send any queued messages for the sent port. |
| 436 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible( | 460 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible( |
| 437 sent_message_port_id); | 461 sent_message_port_id); |
| 438 } else { | 462 } else { |
| 439 IPC::Message* new_message = new IPC::Message(message); | 463 IPC::Message* new_message = new IPC::Message(message); |
| 440 new_message->set_routing_id(route_id); | 464 new_message->set_routing_id(route_id); |
| 441 filter->Send(new_message); | 465 filter->Send(new_message); |
| 442 if (message.type() == WorkerMsg_StartWorkerContext::ID) { | 466 if (message.type() == WorkerMsg_StartWorkerContext::ID) { |
| 443 WorkerServiceImpl::GetInstance()->NotifyWorkerContextStarted( | 467 WorkerDevToolsManager::GetInstance()->WorkerContextStarted( |
| 444 this, route_id); | 468 this, route_id); |
| 445 } | 469 } |
| 446 return; | 470 return; |
| 447 } | 471 } |
| 448 } | 472 } |
| 449 | 473 |
| 450 void WorkerProcessHost::FilterShutdown(WorkerMessageFilter* filter) { | 474 void WorkerProcessHost::FilterShutdown(WorkerMessageFilter* filter) { |
| 451 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { | 475 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { |
| 452 bool shutdown = false; | 476 bool shutdown = false; |
| 453 i->RemoveFilters(filter); | 477 i->RemoveFilters(filter); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 } | 665 } |
| 642 } | 666 } |
| 643 return false; | 667 return false; |
| 644 } | 668 } |
| 645 | 669 |
| 646 WorkerProcessHost::WorkerInstance::FilterInfo | 670 WorkerProcessHost::WorkerInstance::FilterInfo |
| 647 WorkerProcessHost::WorkerInstance::GetFilter() const { | 671 WorkerProcessHost::WorkerInstance::GetFilter() const { |
| 648 DCHECK(NumFilters() == 1); | 672 DCHECK(NumFilters() == 1); |
| 649 return *filters_.begin(); | 673 return *filters_.begin(); |
| 650 } | 674 } |
| OLD | NEW |