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

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: Fix test. 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(resource_context);
97 DCHECK(request_context_getter);
91 } 98 }
92 99
93 WorkerProcessHost::~WorkerProcessHost() { 100 WorkerProcessHost::~WorkerProcessHost() {
94 // If we crashed, tell the RenderViewHosts. 101 // If we crashed, tell the RenderViewHosts.
95 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { 102 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) {
96 const WorkerDocumentSet::DocumentInfoSet& parents = 103 const WorkerDocumentSet::DocumentInfoSet& parents =
97 i->worker_document_set()->documents(); 104 i->worker_document_set()->documents();
98 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter = 105 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter =
99 parents.begin(); parent_iter != parents.end(); ++parent_iter) { 106 parents.begin(); parent_iter != parents.end(); ++parent_iter) {
100 BrowserThread::PostTask( 107 BrowserThread::PostTask(
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 base::PLATFORM_FILE_TRUNCATE | 201 base::PLATFORM_FILE_TRUNCATE |
195 base::PLATFORM_FILE_WRITE_ATTRIBUTES); 202 base::PLATFORM_FILE_WRITE_ATTRIBUTES);
196 } 203 }
197 204
198 CreateMessageFilters(render_process_id); 205 CreateMessageFilters(render_process_id);
199 206
200 return true; 207 return true;
201 } 208 }
202 209
203 void WorkerProcessHost::CreateMessageFilters(int render_process_id) { 210 void WorkerProcessHost::CreateMessageFilters(int render_process_id) {
211 DCHECK(resource_context_);
204 ChromeURLRequestContext* chrome_url_context = GetChromeURLRequestContext(); 212 ChromeURLRequestContext* chrome_url_context = GetChromeURLRequestContext();
205 213
206 worker_message_filter_= new WorkerMessageFilter( 214 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter(
215 id(), WORKER_PROCESS, resource_context_, resource_dispatcher_host_);
216 resource_message_filter->set_url_request_context_override(
217 new URLRequestContextOverride(chrome_url_context));
218 AddFilter(resource_message_filter);
219
220 worker_message_filter_ = new WorkerMessageFilter(
207 render_process_id, 221 render_process_id,
208 request_context_, 222 request_context_getter_,
209 resource_dispatcher_host(), 223 resource_context_,
224 resource_dispatcher_host_,
210 NewCallbackWithReturnValue( 225 NewCallbackWithReturnValue(
211 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); 226 WorkerService::GetInstance(), &WorkerService::next_worker_route_id));
212 AddFilter(worker_message_filter_); 227 AddFilter(worker_message_filter_);
213 AddFilter(new AppCacheDispatcherHost(chrome_url_context, id())); 228 AddFilter(new AppCacheDispatcherHost(chrome_url_context, id()));
214 AddFilter(new FileSystemDispatcherHost(chrome_url_context)); 229 AddFilter(new FileSystemDispatcherHost(chrome_url_context));
215 AddFilter(new FileUtilitiesMessageFilter(id())); 230 AddFilter(new FileUtilitiesMessageFilter(id()));
216 AddFilter( 231 AddFilter(
217 new BlobMessageFilter(id(), chrome_url_context->blob_storage_context())); 232 new BlobMessageFilter(id(), chrome_url_context->blob_storage_context()));
218 AddFilter(new MimeRegistryMessageFilter()); 233 AddFilter(new MimeRegistryMessageFilter());
219 AddFilter(new DatabaseMessageFilter( 234 AddFilter(new DatabaseMessageFilter(
220 chrome_url_context->database_tracker(), 235 resource_context_->database_tracker(),
221 chrome_url_context->host_content_settings_map())); 236 chrome_url_context->host_content_settings_map()));
222 237
223 SocketStreamDispatcherHost* socket_stream_dispatcher_host = 238 SocketStreamDispatcherHost* socket_stream_dispatcher_host =
224 new SocketStreamDispatcherHost(); 239 new SocketStreamDispatcherHost();
225 socket_stream_dispatcher_host->set_url_request_context_override( 240 socket_stream_dispatcher_host->set_url_request_context_override(
226 new URLRequestContextOverride(chrome_url_context)); 241 new URLRequestContextOverride(chrome_url_context));
227 AddFilter(socket_stream_dispatcher_host); 242 AddFilter(socket_stream_dispatcher_host);
228 } 243 }
229 244
230 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { 245 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (!display_title.empty()) 481 if (!display_title.empty())
467 display_title += ", "; 482 display_title += ", ";
468 display_title += *i; 483 display_title += *i;
469 } 484 }
470 485
471 set_name(ASCIIToWide(display_title)); 486 set_name(ASCIIToWide(display_title));
472 } 487 }
473 488
474 ChromeURLRequestContext* WorkerProcessHost::GetChromeURLRequestContext() { 489 ChromeURLRequestContext* WorkerProcessHost::GetChromeURLRequestContext() {
475 return static_cast<ChromeURLRequestContext*>( 490 return static_cast<ChromeURLRequestContext*>(
476 request_context_->GetURLRequestContext()); 491 request_context_getter_->GetURLRequestContext());
477 } 492 }
478 493
479 void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter, 494 void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter,
480 unsigned long long document_id) { 495 unsigned long long document_id) {
481 // Walk all instances and remove the document from their document set. 496 // Walk all instances and remove the document from their document set.
482 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { 497 for (Instances::iterator i = instances_.begin(); i != instances_.end();) {
483 if (!i->shared()) { 498 if (!i->shared()) {
484 ++i; 499 ++i;
485 } else { 500 } else {
486 i->worker_document_set()->Remove(filter, document_id); 501 i->worker_document_set()->Remove(filter, document_id);
(...skipping 10 matching lines...) Expand all
497 512
498 WorkerProcessHost::WorkerInstance::WorkerInstance( 513 WorkerProcessHost::WorkerInstance::WorkerInstance(
499 const GURL& url, 514 const GURL& url,
500 bool shared, 515 bool shared,
501 bool incognito, 516 bool incognito,
502 const string16& name, 517 const string16& name,
503 int worker_route_id, 518 int worker_route_id,
504 int parent_process_id, 519 int parent_process_id,
505 int parent_appcache_host_id, 520 int parent_appcache_host_id,
506 int64 main_resource_appcache_id, 521 int64 main_resource_appcache_id,
507 net::URLRequestContextGetter* request_context) 522 net::URLRequestContextGetter* request_context_getter,
523 const content::ResourceContext& resource_context)
508 : url_(url), 524 : url_(url),
509 shared_(shared), 525 shared_(shared),
510 incognito_(incognito), 526 incognito_(incognito),
511 closed_(false), 527 closed_(false),
512 name_(name), 528 name_(name),
513 worker_route_id_(worker_route_id), 529 worker_route_id_(worker_route_id),
514 parent_process_id_(parent_process_id), 530 parent_process_id_(parent_process_id),
515 parent_appcache_host_id_(parent_appcache_host_id), 531 parent_appcache_host_id_(parent_appcache_host_id),
516 main_resource_appcache_id_(main_resource_appcache_id), 532 main_resource_appcache_id_(main_resource_appcache_id),
517 request_context_(request_context), 533 request_context_getter_(request_context_getter),
518 worker_document_set_(new WorkerDocumentSet()) { 534 worker_document_set_(new WorkerDocumentSet()),
535 resource_context_(&resource_context) {
536 DCHECK(request_context_getter_);
537 DCHECK(resource_context_);
538 }
539
540 WorkerProcessHost::WorkerInstance::WorkerInstance(
541 const GURL& url,
542 bool shared,
543 bool incognito,
544 const string16& name)
545 : url_(url),
546 shared_(shared),
547 incognito_(incognito),
548 closed_(false),
549 name_(name),
550 worker_route_id_(MSG_ROUTING_NONE),
551 parent_process_id_(0),
552 parent_appcache_host_id_(0),
553 main_resource_appcache_id_(0),
554 request_context_getter_(NULL),
555 worker_document_set_(new WorkerDocumentSet()),
556 resource_context_(NULL) {
519 } 557 }
520 558
521 WorkerProcessHost::WorkerInstance::~WorkerInstance() { 559 WorkerProcessHost::WorkerInstance::~WorkerInstance() {
522 } 560 }
523 561
524 // Compares an instance based on the algorithm in the WebWorkers spec - an 562 // Compares an instance based on the algorithm in the WebWorkers spec - an
525 // instance matches if the origins of the URLs match, and: 563 // instance matches if the origins of the URLs match, and:
526 // a) the names are non-empty and equal 564 // a) the names are non-empty and equal
527 // -or- 565 // -or-
528 // b) the names are both empty, and the urls are equal 566 // b) the names are both empty, and the urls are equal
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 639 }
602 } 640 }
603 return false; 641 return false;
604 } 642 }
605 643
606 WorkerProcessHost::WorkerInstance::FilterInfo 644 WorkerProcessHost::WorkerInstance::FilterInfo
607 WorkerProcessHost::WorkerInstance::GetFilter() const { 645 WorkerProcessHost::WorkerInstance::GetFilter() const {
608 DCHECK(NumFilters() == 1); 646 DCHECK(NumFilters() == 1);
609 return *filters_.begin(); 647 return *filters_.begin();
610 } 648 }
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