Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: content/browser/worker_host/worker_process_host.cc

Issue 6825038: Create a content::ResourceContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, fix tests. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/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/metrics/user_metrics.h" 15 #include "chrome/browser/metrics/user_metrics.h"
16 #include "content/common/content_switches.h" 16 #include "content/common/content_switches.h"
17 #include "content/browser/appcache/appcache_dispatcher_host.h" 17 #include "content/browser/appcache/appcache_dispatcher_host.h"
18 #include "content/browser/browser_thread.h" 18 #include "content/browser/browser_thread.h"
19 #include "content/browser/child_process_security_policy.h" 19 #include "content/browser/child_process_security_policy.h"
20 #include "content/browser/file_system/file_system_dispatcher_host.h" 20 #include "content/browser/file_system/file_system_dispatcher_host.h"
21 #include "content/browser/mime_registry_message_filter.h" 21 #include "content/browser/mime_registry_message_filter.h"
22 #include "content/browser/renderer_host/blob_message_filter.h" 22 #include "content/browser/renderer_host/blob_message_filter.h"
23 #include "content/browser/renderer_host/database_message_filter.h" 23 #include "content/browser/renderer_host/database_message_filter.h"
24 #include "content/browser/renderer_host/file_utilities_message_filter.h" 24 #include "content/browser/renderer_host/file_utilities_message_filter.h"
25 #include "content/browser/renderer_host/render_view_host.h" 25 #include "content/browser/renderer_host/render_view_host.h"
26 #include "content/browser/renderer_host/render_view_host_delegate.h" 26 #include "content/browser/renderer_host/render_view_host_delegate.h"
27 #include "content/browser/renderer_host/render_view_host_notification_task.h" 27 #include "content/browser/renderer_host/render_view_host_notification_task.h"
28 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" 28 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h"
29 #include "content/browser/resource_context.h"
29 #include "content/browser/worker_host/message_port_service.h" 30 #include "content/browser/worker_host/message_port_service.h"
30 #include "content/browser/worker_host/worker_message_filter.h" 31 #include "content/browser/worker_host/worker_message_filter.h"
31 #include "content/browser/worker_host/worker_service.h" 32 #include "content/browser/worker_host/worker_service.h"
32 #include "content/common/debug_flags.h" 33 #include "content/common/debug_flags.h"
33 #include "content/common/result_codes.h" 34 #include "content/common/result_codes.h"
34 #include "content/common/view_messages.h" 35 #include "content/common/view_messages.h"
35 #include "content/common/worker_messages.h" 36 #include "content/common/worker_messages.h"
36 #include "net/base/mime_util.h" 37 #include "net/base/mime_util.h"
37 #include "ipc/ipc_switches.h" 38 #include "ipc/ipc_switches.h"
38 #include "net/base/registry_controlled_domain.h" 39 #include "net/base/registry_controlled_domain.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if (host) 78 if (host)
78 host->delegate()->WorkerCrashed(); 79 host->delegate()->WorkerCrashed();
79 } 80 }
80 81
81 private: 82 private:
82 int render_process_unique_id_; 83 int render_process_unique_id_;
83 int render_view_id_; 84 int render_view_id_;
84 }; 85 };
85 86
86 WorkerProcessHost::WorkerProcessHost( 87 WorkerProcessHost::WorkerProcessHost(
87 ResourceDispatcherHost* resource_dispatcher_host, 88 net::URLRequestContextGetter* request_context_getter,
88 net::URLRequestContextGetter* request_context) 89 const content::ResourceContext& resource_context,
89 : BrowserChildProcessHost(WORKER_PROCESS, resource_dispatcher_host), 90 ResourceDispatcherHost* resource_dispatcher_host)
90 request_context_(request_context) { 91 : BrowserChildProcessHost(WORKER_PROCESS),
92 request_context_getter_(request_context_getter),
93 resource_context_(&resource_context),
94 resource_dispatcher_host_(resource_dispatcher_host) {
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
96 DCHECK(request_context_getter);
91 } 97 }
92 98
93 WorkerProcessHost::~WorkerProcessHost() { 99 WorkerProcessHost::~WorkerProcessHost() {
94 // If we crashed, tell the RenderViewHosts. 100 // If we crashed, tell the RenderViewHosts.
95 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { 101 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) {
96 const WorkerDocumentSet::DocumentInfoSet& parents = 102 const WorkerDocumentSet::DocumentInfoSet& parents =
97 i->worker_document_set()->documents(); 103 i->worker_document_set()->documents();
98 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter = 104 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter =
99 parents.begin(); parent_iter != parents.end(); ++parent_iter) { 105 parents.begin(); parent_iter != parents.end(); ++parent_iter) {
100 BrowserThread::PostTask( 106 BrowserThread::PostTask(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 base::PLATFORM_FILE_TRUNCATE | 200 base::PLATFORM_FILE_TRUNCATE |
195 base::PLATFORM_FILE_WRITE_ATTRIBUTES); 201 base::PLATFORM_FILE_WRITE_ATTRIBUTES);
196 } 202 }
197 203
198 CreateMessageFilters(render_process_id); 204 CreateMessageFilters(render_process_id);
199 205
200 return true; 206 return true;
201 } 207 }
202 208
203 void WorkerProcessHost::CreateMessageFilters(int render_process_id) { 209 void WorkerProcessHost::CreateMessageFilters(int render_process_id) {
210 DCHECK(resource_context_);
204 ChromeURLRequestContext* chrome_url_context = GetChromeURLRequestContext(); 211 ChromeURLRequestContext* chrome_url_context = GetChromeURLRequestContext();
205 212
206 worker_message_filter_= new WorkerMessageFilter( 213 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter(
214 id(), WORKER_PROCESS, *resource_context_, resource_dispatcher_host_);
215 resource_message_filter->set_url_request_context_override(
216 new URLRequestContextOverride(chrome_url_context));
217 AddFilter(resource_message_filter);
218
219 worker_message_filter_ = new WorkerMessageFilter(
207 render_process_id, 220 render_process_id,
208 request_context_, 221 request_context_getter_,
209 resource_dispatcher_host(), 222 *resource_context_,
223 resource_dispatcher_host_,
jam 2011/04/13 19:20:30 why pass this in instead of using the getter from
willchan no longer on Chromium 2011/04/13 22:16:26 It's NULL in the parent, since I got rid of that d
210 NewCallbackWithReturnValue( 224 NewCallbackWithReturnValue(
211 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); 225 WorkerService::GetInstance(), &WorkerService::next_worker_route_id));
212 AddFilter(worker_message_filter_); 226 AddFilter(worker_message_filter_);
213 AddFilter(new AppCacheDispatcherHost(chrome_url_context, id())); 227 AddFilter(new AppCacheDispatcherHost(chrome_url_context, id()));
214 AddFilter(new FileSystemDispatcherHost(chrome_url_context)); 228 AddFilter(new FileSystemDispatcherHost(chrome_url_context));
215 AddFilter(new FileUtilitiesMessageFilter(id())); 229 AddFilter(new FileUtilitiesMessageFilter(id()));
216 AddFilter( 230 AddFilter(
217 new BlobMessageFilter(id(), chrome_url_context->blob_storage_context())); 231 new BlobMessageFilter(id(), chrome_url_context->blob_storage_context()));
218 AddFilter(new MimeRegistryMessageFilter()); 232 AddFilter(new MimeRegistryMessageFilter());
219 AddFilter(new DatabaseMessageFilter( 233 AddFilter(new DatabaseMessageFilter(
220 chrome_url_context->database_tracker(), 234 resource_context_->database_tracker(),
221 chrome_url_context->host_content_settings_map())); 235 chrome_url_context->host_content_settings_map()));
222 236
223 SocketStreamDispatcherHost* socket_stream_dispatcher_host = 237 SocketStreamDispatcherHost* socket_stream_dispatcher_host =
224 new SocketStreamDispatcherHost(); 238 new SocketStreamDispatcherHost();
225 socket_stream_dispatcher_host->set_url_request_context_override( 239 socket_stream_dispatcher_host->set_url_request_context_override(
226 new URLRequestContextOverride(chrome_url_context)); 240 new URLRequestContextOverride(chrome_url_context));
227 AddFilter(socket_stream_dispatcher_host); 241 AddFilter(socket_stream_dispatcher_host);
228 } 242 }
229 243
230 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { 244 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (!display_title.empty()) 480 if (!display_title.empty())
467 display_title += ", "; 481 display_title += ", ";
468 display_title += *i; 482 display_title += *i;
469 } 483 }
470 484
471 set_name(ASCIIToWide(display_title)); 485 set_name(ASCIIToWide(display_title));
472 } 486 }
473 487
474 ChromeURLRequestContext* WorkerProcessHost::GetChromeURLRequestContext() { 488 ChromeURLRequestContext* WorkerProcessHost::GetChromeURLRequestContext() {
475 return static_cast<ChromeURLRequestContext*>( 489 return static_cast<ChromeURLRequestContext*>(
476 request_context_->GetURLRequestContext()); 490 request_context_getter_->GetURLRequestContext());
477 } 491 }
478 492
479 void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter, 493 void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter,
480 unsigned long long document_id) { 494 unsigned long long document_id) {
481 // Walk all instances and remove the document from their document set. 495 // Walk all instances and remove the document from their document set.
482 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { 496 for (Instances::iterator i = instances_.begin(); i != instances_.end();) {
483 if (!i->shared()) { 497 if (!i->shared()) {
484 ++i; 498 ++i;
485 } else { 499 } else {
486 i->worker_document_set()->Remove(filter, document_id); 500 i->worker_document_set()->Remove(filter, document_id);
(...skipping 10 matching lines...) Expand all
497 511
498 WorkerProcessHost::WorkerInstance::WorkerInstance( 512 WorkerProcessHost::WorkerInstance::WorkerInstance(
499 const GURL& url, 513 const GURL& url,
500 bool shared, 514 bool shared,
501 bool incognito, 515 bool incognito,
502 const string16& name, 516 const string16& name,
503 int worker_route_id, 517 int worker_route_id,
504 int parent_process_id, 518 int parent_process_id,
505 int parent_appcache_host_id, 519 int parent_appcache_host_id,
506 int64 main_resource_appcache_id, 520 int64 main_resource_appcache_id,
507 net::URLRequestContextGetter* request_context) 521 net::URLRequestContextGetter* request_context_getter,
522 const content::ResourceContext& resource_context)
508 : url_(url), 523 : url_(url),
509 shared_(shared), 524 shared_(shared),
510 incognito_(incognito), 525 incognito_(incognito),
511 closed_(false), 526 closed_(false),
512 name_(name), 527 name_(name),
513 worker_route_id_(worker_route_id), 528 worker_route_id_(worker_route_id),
514 parent_process_id_(parent_process_id), 529 parent_process_id_(parent_process_id),
515 parent_appcache_host_id_(parent_appcache_host_id), 530 parent_appcache_host_id_(parent_appcache_host_id),
516 main_resource_appcache_id_(main_resource_appcache_id), 531 main_resource_appcache_id_(main_resource_appcache_id),
517 request_context_(request_context), 532 request_context_getter_(request_context_getter),
518 worker_document_set_(new WorkerDocumentSet()) { 533 worker_document_set_(new WorkerDocumentSet()),
534 resource_context_(&resource_context) {
535 DCHECK(request_context_getter_);
536 DCHECK(resource_context_);
537 }
538
539 WorkerProcessHost::WorkerInstance::WorkerInstance(
540 const GURL& url,
541 bool shared,
542 bool incognito,
543 const string16& name)
544 : url_(url),
545 shared_(shared),
546 incognito_(incognito),
547 closed_(false),
548 name_(name),
549 worker_route_id_(MSG_ROUTING_NONE),
550 parent_process_id_(0),
551 parent_appcache_host_id_(0),
552 main_resource_appcache_id_(0),
553 request_context_getter_(NULL),
554 worker_document_set_(new WorkerDocumentSet()),
555 resource_context_(NULL) {
519 } 556 }
520 557
521 WorkerProcessHost::WorkerInstance::~WorkerInstance() { 558 WorkerProcessHost::WorkerInstance::~WorkerInstance() {
522 } 559 }
523 560
524 // Compares an instance based on the algorithm in the WebWorkers spec - an 561 // Compares an instance based on the algorithm in the WebWorkers spec - an
525 // instance matches if the origins of the URLs match, and: 562 // instance matches if the origins of the URLs match, and:
526 // a) the names are non-empty and equal 563 // a) the names are non-empty and equal
527 // -or- 564 // -or-
528 // b) the names are both empty, and the urls are equal 565 // b) the names are both empty, and the urls are equal
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 638 }
602 } 639 }
603 return false; 640 return false;
604 } 641 }
605 642
606 WorkerProcessHost::WorkerInstance::FilterInfo 643 WorkerProcessHost::WorkerInstance::FilterInfo
607 WorkerProcessHost::WorkerInstance::GetFilter() const { 644 WorkerProcessHost::WorkerInstance::GetFilter() const {
608 DCHECK(NumFilters() == 1); 645 DCHECK(NumFilters() == 1);
609 return *filters_.begin(); 646 return *filters_.begin();
610 } 647 }
OLDNEW
« no previous file with comments | « content/browser/worker_host/worker_process_host.h ('k') | content/browser/worker_host/worker_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698