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

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

Issue 23851010: Modify ResourceMessageFilter so that it can support attaching to PluginProcessHost. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 7 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
11 #include "base/base_switches.h" 11 #include "base/base_switches.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "content/browser/appcache/appcache_dispatcher_host.h" 19 #include "content/browser/appcache/appcache_dispatcher_host.h"
20 #include "content/browser/appcache/chrome_appcache_service.h" 20 #include "content/browser/appcache/chrome_appcache_service.h"
21 #include "content/browser/browser_child_process_host_impl.h" 21 #include "content/browser/browser_child_process_host_impl.h"
22 #include "content/browser/child_process_security_policy_impl.h" 22 #include "content/browser/child_process_security_policy_impl.h"
23 #include "content/browser/devtools/worker_devtools_manager.h" 23 #include "content/browser/devtools/worker_devtools_manager.h"
24 #include "content/browser/devtools/worker_devtools_message_filter.h" 24 #include "content/browser/devtools/worker_devtools_message_filter.h"
25 #include "content/browser/fileapi/fileapi_message_filter.h" 25 #include "content/browser/fileapi/fileapi_message_filter.h"
26 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 26 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
27 #include "content/browser/loader/resource_message_filter.h"
27 #include "content/browser/mime_registry_message_filter.h" 28 #include "content/browser/mime_registry_message_filter.h"
28 #include "content/browser/quota_dispatcher_host.h" 29 #include "content/browser/quota_dispatcher_host.h"
29 #include "content/browser/renderer_host/database_message_filter.h" 30 #include "content/browser/renderer_host/database_message_filter.h"
30 #include "content/browser/renderer_host/file_utilities_message_filter.h" 31 #include "content/browser/renderer_host/file_utilities_message_filter.h"
31 #include "content/browser/renderer_host/render_view_host_delegate.h" 32 #include "content/browser/renderer_host/render_view_host_delegate.h"
32 #include "content/browser/renderer_host/render_view_host_impl.h" 33 #include "content/browser/renderer_host/render_view_host_impl.h"
33 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" 34 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h"
34 #include "content/browser/resource_context_impl.h" 35 #include "content/browser/resource_context_impl.h"
35 #include "content/browser/worker_host/message_port_service.h" 36 #include "content/browser/worker_host/message_port_service.h"
36 #include "content/browser/worker_host/worker_message_filter.h" 37 #include "content/browser/worker_host/worker_message_filter.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 WorkerSandboxedProcessLauncherDelegate() {} 69 WorkerSandboxedProcessLauncherDelegate() {}
69 virtual ~WorkerSandboxedProcessLauncherDelegate() {} 70 virtual ~WorkerSandboxedProcessLauncherDelegate() {}
70 71
71 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy, 72 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy,
72 bool* success) { 73 bool* success) {
73 AddBaseHandleClosePolicy(policy); 74 AddBaseHandleClosePolicy(policy);
74 } 75 }
75 }; 76 };
76 #endif // OS_WIN 77 #endif // OS_WIN
77 78
78 // Helper class that we pass to SocketStreamDispatcherHost so that it can find
79 // the right net::URLRequestContext for a request.
80 class URLRequestContextSelector
81 : public ResourceMessageFilter::URLRequestContextSelector {
82 public:
83 explicit URLRequestContextSelector(
84 net::URLRequestContextGetter* url_request_context,
85 net::URLRequestContextGetter* media_url_request_context)
86 : url_request_context_(url_request_context),
87 media_url_request_context_(media_url_request_context) {
88 }
89 virtual ~URLRequestContextSelector() {}
90
91 virtual net::URLRequestContext* GetRequestContext(
92 ResourceType::Type resource_type) OVERRIDE {
93 if (resource_type == ResourceType::MEDIA)
94 return media_url_request_context_->GetURLRequestContext();
95 return url_request_context_->GetURLRequestContext();
96 }
97
98 private:
99 net::URLRequestContextGetter* url_request_context_;
100 net::URLRequestContextGetter* media_url_request_context_;
101 };
102
103 } // namespace 79 } // namespace
104 80
105 // Notifies RenderViewHost that one or more worker objects crashed. 81 // Notifies RenderViewHost that one or more worker objects crashed.
106 void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { 82 void WorkerCrashCallback(int render_process_unique_id, int render_view_id) {
107 RenderViewHostImpl* host = 83 RenderViewHostImpl* host =
108 RenderViewHostImpl::FromID(render_process_unique_id, render_view_id); 84 RenderViewHostImpl::FromID(render_process_unique_id, render_view_id);
109 if (host) 85 if (host)
110 host->GetDelegate()->WorkerCrashed(); 86 host->GetDelegate()->WorkerCrashed();
111 } 87 }
112 88
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 203 }
228 204
229 void WorkerProcessHost::CreateMessageFilters(int render_process_id) { 205 void WorkerProcessHost::CreateMessageFilters(int render_process_id) {
230 ChromeBlobStorageContext* blob_storage_context = 206 ChromeBlobStorageContext* blob_storage_context =
231 GetChromeBlobStorageContextForResourceContext(resource_context_); 207 GetChromeBlobStorageContextForResourceContext(resource_context_);
232 StreamContext* stream_context = 208 StreamContext* stream_context =
233 GetStreamContextForResourceContext(resource_context_); 209 GetStreamContextForResourceContext(resource_context_);
234 210
235 net::URLRequestContextGetter* url_request_context = 211 net::URLRequestContextGetter* url_request_context =
236 partition_.url_request_context(); 212 partition_.url_request_context();
237 net::URLRequestContextGetter* media_url_request_context = 213
238 partition_.url_request_context(); 214 ResourceMessageFilter::GetContextsCallback get_contexts_callback(
215 base::Bind(&WorkerProcessHost::GetContexts,
216 base::Unretained(this)));
239 217
240 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( 218 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter(
241 process_->GetData().id, PROCESS_TYPE_WORKER, resource_context_, 219 process_->GetData().id, PROCESS_TYPE_WORKER,
242 partition_.appcache_service(), 220 partition_.appcache_service(),
243 blob_storage_context, 221 blob_storage_context,
244 partition_.filesystem_context(), 222 partition_.filesystem_context(),
245 new URLRequestContextSelector(url_request_context, 223 get_contexts_callback);
246 media_url_request_context));
247 process_->GetHost()->AddFilter(resource_message_filter); 224 process_->GetHost()->AddFilter(resource_message_filter);
248 225
249 worker_message_filter_ = new WorkerMessageFilter( 226 worker_message_filter_ = new WorkerMessageFilter(
250 render_process_id, resource_context_, partition_, 227 render_process_id, resource_context_, partition_,
251 base::Bind(&WorkerServiceImpl::next_worker_route_id, 228 base::Bind(&WorkerServiceImpl::next_worker_route_id,
252 base::Unretained(WorkerServiceImpl::GetInstance()))); 229 base::Unretained(WorkerServiceImpl::GetInstance())));
253 process_->GetHost()->AddFilter(worker_message_filter_.get()); 230 process_->GetHost()->AddFilter(worker_message_filter_.get());
254 process_->GetHost()->AddFilter(new AppCacheDispatcherHost( 231 process_->GetHost()->AddFilter(new AppCacheDispatcherHost(
255 partition_.appcache_service(), process_->GetData().id)); 232 partition_.appcache_service(), process_->GetData().id));
256 process_->GetHost()->AddFilter(new FileAPIMessageFilter( 233 process_->GetHost()->AddFilter(new FileAPIMessageFilter(
257 process_->GetData().id, 234 process_->GetData().id,
258 url_request_context, 235 url_request_context,
259 partition_.filesystem_context(), 236 partition_.filesystem_context(),
260 blob_storage_context, 237 blob_storage_context,
261 stream_context)); 238 stream_context));
262 process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter( 239 process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter(
263 process_->GetData().id)); 240 process_->GetData().id));
264 process_->GetHost()->AddFilter(new MimeRegistryMessageFilter()); 241 process_->GetHost()->AddFilter(new MimeRegistryMessageFilter());
265 process_->GetHost()->AddFilter( 242 process_->GetHost()->AddFilter(
266 new DatabaseMessageFilter(partition_.database_tracker())); 243 new DatabaseMessageFilter(partition_.database_tracker()));
267 process_->GetHost()->AddFilter(new QuotaDispatcherHost( 244 process_->GetHost()->AddFilter(new QuotaDispatcherHost(
268 process_->GetData().id, 245 process_->GetData().id,
269 partition_.quota_manager(), 246 partition_.quota_manager(),
270 GetContentClient()->browser()->CreateQuotaPermissionContext())); 247 GetContentClient()->browser()->CreateQuotaPermissionContext()));
271 248
249 SocketStreamDispatcherHost::GetRequestContextCallback
250 request_context_callback(
251 base::Bind(&WorkerProcessHost::GetRequestContext,
252 base::Unretained(this)));
253
272 SocketStreamDispatcherHost* socket_stream_dispatcher_host = 254 SocketStreamDispatcherHost* socket_stream_dispatcher_host =
273 new SocketStreamDispatcherHost( 255 new SocketStreamDispatcherHost(
274 render_process_id, 256 render_process_id,
275 new URLRequestContextSelector(url_request_context, 257 request_context_callback,
276 media_url_request_context),
277 resource_context_); 258 resource_context_);
278 socket_stream_dispatcher_host_ = socket_stream_dispatcher_host; 259 socket_stream_dispatcher_host_ = socket_stream_dispatcher_host;
279 process_->GetHost()->AddFilter(socket_stream_dispatcher_host); 260 process_->GetHost()->AddFilter(socket_stream_dispatcher_host);
280 process_->GetHost()->AddFilter( 261 process_->GetHost()->AddFilter(
281 new WorkerDevToolsMessageFilter(process_->GetData().id)); 262 new WorkerDevToolsMessageFilter(process_->GetData().id));
282 process_->GetHost()->AddFilter(new IndexedDBDispatcherHost( 263 process_->GetHost()->AddFilter(new IndexedDBDispatcherHost(
283 process_->GetData().id, partition_.indexed_db_context())); 264 process_->GetData().id, partition_.indexed_db_context()));
284 } 265 }
285 266
286 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { 267 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = 562 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
582 documents.begin(); doc != documents.end(); ++doc) { 563 documents.begin(); doc != documents.end(); ++doc) {
583 result.push_back( 564 result.push_back(
584 std::make_pair(doc->render_process_id(), doc->render_view_id())); 565 std::make_pair(doc->render_process_id(), doc->render_view_id()));
585 } 566 }
586 break; 567 break;
587 } 568 }
588 return result; 569 return result;
589 } 570 }
590 571
572 void WorkerProcessHost::GetContexts(const ResourceHostMsg_Request& request,
573 ResourceContext** resource_context,
574 net::URLRequestContext** request_context) {
575 *resource_context = resource_context_;
576 *request_context = partition_.url_request_context()->GetURLRequestContext();
577 }
578
579 net::URLRequestContext* WorkerProcessHost::GetRequestContext(
580 ResourceType::Type resource_type) {
581 return partition_.url_request_context()->GetURLRequestContext();
582 }
583
591 WorkerProcessHost::WorkerInstance::WorkerInstance( 584 WorkerProcessHost::WorkerInstance::WorkerInstance(
592 const GURL& url, 585 const GURL& url,
593 const string16& name, 586 const string16& name,
594 int worker_route_id, 587 int worker_route_id,
595 int parent_process_id, 588 int parent_process_id,
596 int64 main_resource_appcache_id, 589 int64 main_resource_appcache_id,
597 ResourceContext* resource_context, 590 ResourceContext* resource_context,
598 const WorkerStoragePartition& partition) 591 const WorkerStoragePartition& partition)
599 : url_(url), 592 : url_(url),
600 closed_(false), 593 closed_(false),
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 return false; 711 return false;
719 } 712 }
720 713
721 WorkerProcessHost::WorkerInstance::FilterInfo 714 WorkerProcessHost::WorkerInstance::FilterInfo
722 WorkerProcessHost::WorkerInstance::GetFilter() const { 715 WorkerProcessHost::WorkerInstance::GetFilter() const {
723 DCHECK(NumFilters() == 1); 716 DCHECK(NumFilters() == 1);
724 return *filters_.begin(); 717 return *filters_.begin();
725 } 718 }
726 719
727 } // namespace content 720 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/worker_host/worker_process_host.h ('k') | content/public/common/content_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698