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

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

Issue 10885044: Remove storage context accessors from ResourceContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged to ToT Created 8 years, 3 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) 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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } // namespace 87 } // namespace
88 88
89 // Notifies RenderViewHost that one or more worker objects crashed. 89 // Notifies RenderViewHost that one or more worker objects crashed.
90 void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { 90 void WorkerCrashCallback(int render_process_unique_id, int render_view_id) {
91 RenderViewHostImpl* host = 91 RenderViewHostImpl* host =
92 RenderViewHostImpl::FromID(render_process_unique_id, render_view_id); 92 RenderViewHostImpl::FromID(render_process_unique_id, render_view_id);
93 if (host) 93 if (host)
94 host->GetDelegate()->WorkerCrashed(); 94 host->GetDelegate()->WorkerCrashed();
95 } 95 }
96 96
97 WorkerProcessHost::WorkerProcessHost(ResourceContext* resource_context) 97 WorkerProcessHost::WorkerProcessHost(
98 : resource_context_(resource_context) { 98 const std::string& partition_id,
99 ResourceContext* resource_context,
100 ChromeAppCacheService* appcache_service,
101 fileapi::FileSystemContext* filesystem_context,
102 webkit_database::DatabaseTracker* database_tracker,
103 IndexedDBContextImpl* indexed_db_context)
104 : partition_id_(partition_id),
105 resource_context_(resource_context),
106 appcache_service_(appcache_service),
107 filesystem_context_(filesystem_context),
108 database_tracker_(database_tracker),
109 indexed_db_context_(indexed_db_context) {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
100 DCHECK(resource_context); 111 DCHECK(resource_context_);
101 process_.reset( 112 process_.reset(
102 new BrowserChildProcessHostImpl(content::PROCESS_TYPE_WORKER, this)); 113 new BrowserChildProcessHostImpl(content::PROCESS_TYPE_WORKER, this));
103 } 114 }
104 115
105 WorkerProcessHost::~WorkerProcessHost() { 116 WorkerProcessHost::~WorkerProcessHost() {
106 // If we crashed, tell the RenderViewHosts. 117 // If we crashed, tell the RenderViewHosts.
107 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { 118 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) {
108 const WorkerDocumentSet::DocumentInfoSet& parents = 119 const WorkerDocumentSet::DocumentInfoSet& parents =
109 i->worker_document_set()->documents(); 120 i->worker_document_set()->documents();
110 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter = 121 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter =
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 204
194 process_->Launch( 205 process_->Launch(
195 #if defined(OS_WIN) 206 #if defined(OS_WIN)
196 FilePath(), 207 FilePath(),
197 #elif defined(OS_POSIX) 208 #elif defined(OS_POSIX)
198 use_zygote, 209 use_zygote,
199 base::EnvironmentVector(), 210 base::EnvironmentVector(),
200 #endif 211 #endif
201 cmd_line); 212 cmd_line);
202 213
203 fileapi::FileSystemContext* file_system_context =
204 GetFileSystemContextForResourceContext(resource_context_);
205 ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker( 214 ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker(
206 process_->GetData().id, render_process_id); 215 process_->GetData().id, render_process_id);
207 if (!CommandLine::ForCurrentProcess()->HasSwitch( 216 if (!CommandLine::ForCurrentProcess()->HasSwitch(
208 switches::kDisableFileSystem)) { 217 switches::kDisableFileSystem)) {
209 // Grant most file permissions to this worker. 218 // Grant most file permissions to this worker.
210 // PLATFORM_FILE_TEMPORARY, PLATFORM_FILE_HIDDEN and 219 // PLATFORM_FILE_TEMPORARY, PLATFORM_FILE_HIDDEN and
211 // PLATFORM_FILE_DELETE_ON_CLOSE are not granted, because no existing API 220 // PLATFORM_FILE_DELETE_ON_CLOSE are not granted, because no existing API
212 // requests them. 221 // requests them.
213 // This is for the filesystem sandbox. 222 // This is for the filesystem sandbox.
214 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( 223 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile(
215 process_->GetData().id, 224 process_->GetData().id,
216 file_system_context->sandbox_provider()->new_base_path(), 225 filesystem_context_->sandbox_provider()->new_base_path(),
217 base::PLATFORM_FILE_OPEN | 226 base::PLATFORM_FILE_OPEN |
218 base::PLATFORM_FILE_CREATE | 227 base::PLATFORM_FILE_CREATE |
219 base::PLATFORM_FILE_OPEN_ALWAYS | 228 base::PLATFORM_FILE_OPEN_ALWAYS |
220 base::PLATFORM_FILE_CREATE_ALWAYS | 229 base::PLATFORM_FILE_CREATE_ALWAYS |
221 base::PLATFORM_FILE_OPEN_TRUNCATED | 230 base::PLATFORM_FILE_OPEN_TRUNCATED |
222 base::PLATFORM_FILE_READ | 231 base::PLATFORM_FILE_READ |
223 base::PLATFORM_FILE_WRITE | 232 base::PLATFORM_FILE_WRITE |
224 base::PLATFORM_FILE_EXCLUSIVE_READ | 233 base::PLATFORM_FILE_EXCLUSIVE_READ |
225 base::PLATFORM_FILE_EXCLUSIVE_WRITE | 234 base::PLATFORM_FILE_EXCLUSIVE_WRITE |
226 base::PLATFORM_FILE_ASYNC | 235 base::PLATFORM_FILE_ASYNC |
227 base::PLATFORM_FILE_WRITE_ATTRIBUTES | 236 base::PLATFORM_FILE_WRITE_ATTRIBUTES |
228 base::PLATFORM_FILE_ENUMERATE); 237 base::PLATFORM_FILE_ENUMERATE);
229 // This is so that we can read and move stuff out of the old filesystem 238 // This is so that we can read and move stuff out of the old filesystem
230 // sandbox. 239 // sandbox.
231 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( 240 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile(
232 process_->GetData().id, 241 process_->GetData().id,
233 file_system_context->sandbox_provider()->old_base_path(), 242 filesystem_context_->sandbox_provider()->old_base_path(),
234 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE | 243 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE |
235 base::PLATFORM_FILE_WRITE_ATTRIBUTES | 244 base::PLATFORM_FILE_WRITE_ATTRIBUTES |
236 base::PLATFORM_FILE_ENUMERATE); 245 base::PLATFORM_FILE_ENUMERATE);
237 // This is so that we can rename the old sandbox out of the way so that 246 // This is so that we can rename the old sandbox out of the way so that
238 // we know we've taken care of it. 247 // we know we've taken care of it.
239 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( 248 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile(
240 process_->GetData().id, 249 process_->GetData().id,
241 file_system_context->sandbox_provider()->renamed_old_base_path(), 250 filesystem_context_->sandbox_provider()->renamed_old_base_path(),
242 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_CREATE_ALWAYS | 251 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_CREATE_ALWAYS |
243 base::PLATFORM_FILE_WRITE); 252 base::PLATFORM_FILE_WRITE);
244 } 253 }
245 254
246 CreateMessageFilters(render_process_id); 255 CreateMessageFilters(render_process_id);
247 256
248 return true; 257 return true;
249 } 258 }
250 259
251 void WorkerProcessHost::CreateMessageFilters(int render_process_id) { 260 void WorkerProcessHost::CreateMessageFilters(int render_process_id) {
252 net::URLRequestContext* request_context = 261 net::URLRequestContext* request_context =
253 resource_context_->GetRequestContext(); 262 resource_context_->GetRequestContext();
254 263
255 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( 264 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter(
256 process_->GetData().id, content::PROCESS_TYPE_WORKER, resource_context_, 265 process_->GetData().id, content::PROCESS_TYPE_WORKER, resource_context_,
257 new URLRequestContextSelector(request_context)); 266 new URLRequestContextSelector(request_context));
258 process_->GetHost()->AddFilter(resource_message_filter); 267 process_->GetHost()->AddFilter(resource_message_filter);
259 268
260 worker_message_filter_ = new WorkerMessageFilter( 269 worker_message_filter_ = new WorkerMessageFilter(
261 render_process_id, resource_context_, 270 render_process_id, partition_id_, resource_context_, appcache_service_,
271 filesystem_context_, database_tracker_, indexed_db_context_,
262 base::Bind(&WorkerServiceImpl::next_worker_route_id, 272 base::Bind(&WorkerServiceImpl::next_worker_route_id,
263 base::Unretained(WorkerServiceImpl::GetInstance()))); 273 base::Unretained(WorkerServiceImpl::GetInstance())));
264 process_->GetHost()->AddFilter(worker_message_filter_); 274 process_->GetHost()->AddFilter(worker_message_filter_);
265 process_->GetHost()->AddFilter(new AppCacheDispatcherHost( 275 process_->GetHost()->AddFilter(new AppCacheDispatcherHost(
266 static_cast<ChromeAppCacheService*>( 276 static_cast<ChromeAppCacheService*>(
267 ResourceContext::GetAppCacheService(resource_context_)), 277 ResourceContext::GetAppCacheService(resource_context_)),
268 process_->GetData().id)); 278 process_->GetData().id));
269 process_->GetHost()->AddFilter(new FileAPIMessageFilter( 279 process_->GetHost()->AddFilter(new FileAPIMessageFilter(
270 process_->GetData().id, 280 process_->GetData().id,
271 request_context, 281 request_context,
272 GetFileSystemContextForResourceContext(resource_context_), 282 filesystem_context_,
273 content::GetChromeBlobStorageContextForResourceContext( 283 content::GetChromeBlobStorageContextForResourceContext(
274 resource_context_))); 284 resource_context_)));
275 process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter( 285 process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter(
276 process_->GetData().id)); 286 process_->GetData().id));
277 process_->GetHost()->AddFilter(new MimeRegistryMessageFilter()); 287 process_->GetHost()->AddFilter(new MimeRegistryMessageFilter());
278 process_->GetHost()->AddFilter(new DatabaseMessageFilter( 288 process_->GetHost()->AddFilter(new DatabaseMessageFilter(database_tracker_));
279 content::GetDatabaseTrackerForResourceContext(resource_context_)));
280 289
281 SocketStreamDispatcherHost* socket_stream_dispatcher_host = 290 SocketStreamDispatcherHost* socket_stream_dispatcher_host =
282 new SocketStreamDispatcherHost(render_process_id, 291 new SocketStreamDispatcherHost(render_process_id,
283 new URLRequestContextSelector(request_context), resource_context_); 292 new URLRequestContextSelector(request_context), resource_context_);
284 process_->GetHost()->AddFilter(socket_stream_dispatcher_host); 293 process_->GetHost()->AddFilter(socket_stream_dispatcher_host);
285 process_->GetHost()->AddFilter( 294 process_->GetHost()->AddFilter(
286 new content::WorkerDevToolsMessageFilter(process_->GetData().id)); 295 new content::WorkerDevToolsMessageFilter(process_->GetData().id));
287 process_->GetHost()->AddFilter(new IndexedDBDispatcherHost( 296 process_->GetHost()->AddFilter(new IndexedDBDispatcherHost(
288 process_->GetData().id, 297 process_->GetData().id, indexed_db_context_));
289 content::GetIndexedDBContextForResourceContext(resource_context_)));
290 } 298 }
291 299
292 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { 300 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) {
293 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( 301 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL(
294 process_->GetData().id, instance.url()); 302 process_->GetData().id, instance.url());
295 303
296 instances_.push_back(instance); 304 instances_.push_back(instance);
297 305
298 WorkerProcessMsg_CreateWorker_Params params; 306 WorkerProcessMsg_CreateWorker_Params params;
299 params.url = instance.url(); 307 params.url = instance.url();
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 } 579 }
572 return result; 580 return result;
573 } 581 }
574 582
575 WorkerProcessHost::WorkerInstance::WorkerInstance( 583 WorkerProcessHost::WorkerInstance::WorkerInstance(
576 const GURL& url, 584 const GURL& url,
577 const string16& name, 585 const string16& name,
578 int worker_route_id, 586 int worker_route_id,
579 int parent_process_id, 587 int parent_process_id,
580 int64 main_resource_appcache_id, 588 int64 main_resource_appcache_id,
581 content::ResourceContext* resource_context) 589 const std::string& partition_id,
590 content::ResourceContext* resource_context,
591 ChromeAppCacheService* appcache_service,
592 fileapi::FileSystemContext* filesystem_context,
593 webkit_database::DatabaseTracker* database_tracker,
594 IndexedDBContextImpl* indexed_db_context)
582 : url_(url), 595 : url_(url),
583 closed_(false), 596 closed_(false),
584 name_(name), 597 name_(name),
585 worker_route_id_(worker_route_id), 598 worker_route_id_(worker_route_id),
586 parent_process_id_(parent_process_id), 599 parent_process_id_(parent_process_id),
587 main_resource_appcache_id_(main_resource_appcache_id), 600 main_resource_appcache_id_(main_resource_appcache_id),
588 worker_document_set_(new WorkerDocumentSet()), 601 worker_document_set_(new WorkerDocumentSet()),
589 resource_context_(resource_context) { 602 partition_id_(partition_id),
603 resource_context_(resource_context),
604 appcache_service_(appcache_service),
605 filesystem_context_(filesystem_context),
606 database_tracker_(database_tracker),
607 indexed_db_context_(indexed_db_context) {
590 DCHECK(resource_context_); 608 DCHECK(resource_context_);
591 } 609 }
592 610
593 WorkerProcessHost::WorkerInstance::WorkerInstance( 611 WorkerProcessHost::WorkerInstance::WorkerInstance(
594 const GURL& url, 612 const GURL& url,
595 bool shared, 613 bool shared,
596 const string16& name, 614 const string16& name,
597 content::ResourceContext* resource_context) 615 const std::string& partition_id,
616 content::ResourceContext* resource_context,
617 ChromeAppCacheService* appcache_service,
618 fileapi::FileSystemContext* filesystem_context,
619 webkit_database::DatabaseTracker* database_tracker,
620 IndexedDBContextImpl* indexed_db_context)
598 : url_(url), 621 : url_(url),
599 closed_(false), 622 closed_(false),
600 name_(name), 623 name_(name),
601 worker_route_id_(MSG_ROUTING_NONE), 624 worker_route_id_(MSG_ROUTING_NONE),
602 parent_process_id_(0), 625 parent_process_id_(0),
603 main_resource_appcache_id_(0), 626 main_resource_appcache_id_(0),
604 worker_document_set_(new WorkerDocumentSet()), 627 worker_document_set_(new WorkerDocumentSet()),
605 resource_context_(resource_context) { 628 partition_id_(partition_id),
629 resource_context_(resource_context),
630 appcache_service_(appcache_service),
631 filesystem_context_(filesystem_context),
632 database_tracker_(database_tracker),
633 indexed_db_context_(indexed_db_context) {
606 DCHECK(resource_context_); 634 DCHECK(resource_context_);
607 } 635 }
608 636
609 WorkerProcessHost::WorkerInstance::~WorkerInstance() { 637 WorkerProcessHost::WorkerInstance::~WorkerInstance() {
610 } 638 }
611 639
612 // Compares an instance based on the algorithm in the WebWorkers spec - an 640 // Compares an instance based on the algorithm in the WebWorkers spec - an
613 // instance matches if the origins of the URLs match, and: 641 // instance matches if the origins of the URLs match, and:
614 // a) the names are non-empty and equal 642 // a) the names are non-empty and equal
615 // -or- 643 // -or-
616 // b) the names are both empty, and the urls are equal 644 // b) the names are both empty, and the urls are equal
617 bool WorkerProcessHost::WorkerInstance::Matches( 645 bool WorkerProcessHost::WorkerInstance::Matches(
618 const GURL& match_url, 646 const GURL& match_url,
619 const string16& match_name, 647 const string16& match_name,
648 const std::string& partition_id,
620 content::ResourceContext* resource_context) const { 649 content::ResourceContext* resource_context) const {
621 // Only match open shared workers. 650 // Only match open shared workers.
622 if (closed_) 651 if (closed_)
623 return false; 652 return false;
624 653
625 // ResourceContext equivalence is being used as a proxy to ensure we only 654 // ResourceContext equivalence is being used as a proxy to ensure we only
626 // matched shared workers within the same BrowserContext. 655 // matched shared workers within the same BrowserContext.
627 if (resource_context_ != resource_context) 656 if (resource_context_ != resource_context)
628 return false; 657 return false;
629 658
659 // We must be in the same storage partition otherwise sharing will violate
660 // isolation. All of the FileSystemContext, AppCacheService, etc., objects
661 // that are normally contained in StoragePartition come from one partition so
662 // this check is equivalent to examing each of those pointers for equality.
663 if (partition_id_ != partition_id)
664 return false;
665
630 if (url_.GetOrigin() != match_url.GetOrigin()) 666 if (url_.GetOrigin() != match_url.GetOrigin())
631 return false; 667 return false;
632 668
633 if (name_.empty() && match_name.empty()) 669 if (name_.empty() && match_name.empty())
634 return url_ == match_url; 670 return url_ == match_url;
635 671
636 return name_ == match_name; 672 return name_ == match_name;
637 } 673 }
638 674
639 void WorkerProcessHost::WorkerInstance::AddFilter(WorkerMessageFilter* filter, 675 void WorkerProcessHost::WorkerInstance::AddFilter(WorkerMessageFilter* filter,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 726 }
691 } 727 }
692 return false; 728 return false;
693 } 729 }
694 730
695 WorkerProcessHost::WorkerInstance::FilterInfo 731 WorkerProcessHost::WorkerInstance::FilterInfo
696 WorkerProcessHost::WorkerInstance::GetFilter() const { 732 WorkerProcessHost::WorkerInstance::GetFilter() const {
697 DCHECK(NumFilters() == 1); 733 DCHECK(NumFilters() == 1);
698 return *filters_.begin(); 734 return *filters_.begin();
699 } 735 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698