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

Side by Side Diff: content/browser/worker_host/worker_service.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
« no previous file with comments | « content/browser/worker_host/worker_service.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_service.h" 5 #include "content/browser/worker_host/worker_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h"
10 #include "base/sys_info.h" 11 #include "base/sys_info.h"
11 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "content/browser/worker_host/worker_message_filter.h" 14 #include "content/browser/worker_host/worker_message_filter.h"
14 #include "content/browser/worker_host/worker_process_host.h" 15 #include "content/browser/worker_host/worker_process_host.h"
15 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
16 #include "content/common/worker_messages.h" 17 #include "content/common/worker_messages.h"
17 #include "net/base/registry_controlled_domain.h" 18 #include "net/base/registry_controlled_domain.h"
18 19
19 const int WorkerService::kMaxWorkerProcessesWhenSharing = 10; 20 const int WorkerService::kMaxWorkerProcessesWhenSharing = 10;
20 const int WorkerService::kMaxWorkersWhenSeparate = 64; 21 const int WorkerService::kMaxWorkersWhenSeparate = 64;
21 const int WorkerService::kMaxWorkersPerTabWhenSeparate = 16; 22 const int WorkerService::kMaxWorkersPerTabWhenSeparate = 16;
22 23
23 WorkerService* WorkerService::GetInstance() { 24 WorkerService* WorkerService::GetInstance() {
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
24 return Singleton<WorkerService>::get(); 26 return Singleton<WorkerService>::get();
25 } 27 }
26 28
27 WorkerService::WorkerService() : next_worker_route_id_(0) { 29 WorkerService::WorkerService() : next_worker_route_id_(0) {
28 } 30 }
29 31
30 WorkerService::~WorkerService() { 32 WorkerService::~WorkerService() {
31 } 33 }
32 34
33 void WorkerService::OnWorkerMessageFilterClosing(WorkerMessageFilter* filter) { 35 void WorkerService::OnWorkerMessageFilterClosing(WorkerMessageFilter* filter) {
(...skipping 30 matching lines...) Expand all
64 // the queued workers, or a renderer has shut down, in which case it doesn't 66 // the queued workers, or a renderer has shut down, in which case it doesn't
65 // affect anything. We call this function in both scenarios because then we 67 // affect anything. We call this function in both scenarios because then we
66 // don't have to keep track which filters are from worker processes. 68 // don't have to keep track which filters are from worker processes.
67 TryStartingQueuedWorker(); 69 TryStartingQueuedWorker();
68 } 70 }
69 71
70 void WorkerService::CreateWorker( 72 void WorkerService::CreateWorker(
71 const ViewHostMsg_CreateWorker_Params& params, 73 const ViewHostMsg_CreateWorker_Params& params,
72 int route_id, 74 int route_id,
73 WorkerMessageFilter* filter, 75 WorkerMessageFilter* filter,
74 net::URLRequestContextGetter* request_context) { 76 net::URLRequestContextGetter* request_context_getter,
75 77 const content::ResourceContext& resource_context) {
78 // TODO(willchan): Eliminate the need for this downcast.
76 ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>( 79 ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>(
77 request_context->GetURLRequestContext()); 80 request_context_getter->GetURLRequestContext());
78 81
79 // Generate a unique route id for the browser-worker communication that's 82 // Generate a unique route id for the browser-worker communication that's
80 // unique among all worker processes. That way when the worker process sends 83 // unique among all worker processes. That way when the worker process sends
81 // a wrapped IPC message through us, we know which WorkerProcessHost to give 84 // a wrapped IPC message through us, we know which WorkerProcessHost to give
82 // it to. 85 // it to.
83 WorkerProcessHost::WorkerInstance instance( 86 WorkerProcessHost::WorkerInstance instance(
84 params.url, 87 params.url,
85 params.is_shared, 88 params.is_shared,
86 context->is_incognito(), 89 context->is_incognito(),
87 params.name, 90 params.name,
88 next_worker_route_id(), 91 next_worker_route_id(),
89 params.is_shared ? 0 : filter->render_process_id(), 92 params.is_shared ? 0 : filter->render_process_id(),
90 params.is_shared ? 0 : params.parent_appcache_host_id, 93 params.is_shared ? 0 : params.parent_appcache_host_id,
91 params.is_shared ? params.script_resource_appcache_id : 0, 94 params.is_shared ? params.script_resource_appcache_id : 0,
92 request_context); 95 request_context_getter,
96 resource_context);
93 instance.AddFilter(filter, route_id); 97 instance.AddFilter(filter, route_id);
94 instance.worker_document_set()->Add( 98 instance.worker_document_set()->Add(
95 filter, params.document_id, filter->render_process_id(), 99 filter, params.document_id, filter->render_process_id(),
96 params.render_view_route_id); 100 params.render_view_route_id);
97 101
98 CreateWorkerFromInstance(instance); 102 CreateWorkerFromInstance(instance);
99 } 103 }
100 104
101 void WorkerService::LookupSharedWorker( 105 void WorkerService::LookupSharedWorker(
102 const ViewHostMsg_CreateWorker_Params& params, 106 const ViewHostMsg_CreateWorker_Params& params,
103 int route_id, 107 int route_id,
104 WorkerMessageFilter* filter, 108 WorkerMessageFilter* filter,
105 bool incognito, 109 bool incognito,
106 bool* exists, 110 bool* exists,
107 bool* url_mismatch) { 111 bool* url_mismatch) {
108
109 *exists = true; 112 *exists = true;
110 WorkerProcessHost::WorkerInstance* instance = FindSharedWorkerInstance( 113 WorkerProcessHost::WorkerInstance* instance = FindSharedWorkerInstance(
111 params.url, params.name, incognito); 114 params.url, params.name, incognito);
112 115
113 if (!instance) { 116 if (!instance) {
114 // If no worker instance currently exists, we need to create a pending 117 // If no worker instance currently exists, we need to create a pending
115 // instance - this is to make sure that any subsequent lookups passing a 118 // instance - this is to make sure that any subsequent lookups passing a
116 // mismatched URL get the appropriate url_mismatch error at lookup time. 119 // mismatched URL get the appropriate url_mismatch error at lookup time.
117 // Having named shared workers was a Really Bad Idea due to details like 120 // Having named shared workers was a Really Bad Idea due to details like
118 // this. 121 // this.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 iter = queued_workers_.erase(iter); 305 iter = queued_workers_.erase(iter);
303 } else { 306 } else {
304 ++iter; 307 ++iter;
305 } 308 }
306 } 309 }
307 } 310 }
308 311
309 if (!worker) { 312 if (!worker) {
310 WorkerMessageFilter* first_filter = instance.filters().begin()->first; 313 WorkerMessageFilter* first_filter = instance.filters().begin()->first;
311 worker = new WorkerProcessHost( 314 worker = new WorkerProcessHost(
312 first_filter->resource_dispatcher_host(), 315 instance.request_context_getter(),
313 instance.request_context()); 316 &instance.resource_context(),
317 first_filter->resource_dispatcher_host());
314 // TODO(atwilson): This won't work if the message is from a worker process. 318 // TODO(atwilson): This won't work if the message is from a worker process.
315 // We don't support that yet though (this message is only sent from 319 // We don't support that yet though (this message is only sent from
316 // renderers) but when we do, we'll need to add code to pass in the current 320 // renderers) but when we do, we'll need to add code to pass in the current
317 // worker's document set for nested workers. 321 // worker's document set for nested workers.
318 if (!worker->Init(first_filter->render_process_id())) { 322 if (!worker->Init(first_filter->render_process_id())) {
319 delete worker; 323 delete worker;
320 return false; 324 return false;
321 } 325 }
322 } 326 }
323 327
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 WorkerService::CreatePendingInstance(const GURL& url, 548 WorkerService::CreatePendingInstance(const GURL& url,
545 const string16& name, 549 const string16& name,
546 bool incognito) { 550 bool incognito) {
547 // Look for an existing pending shared worker. 551 // Look for an existing pending shared worker.
548 WorkerProcessHost::WorkerInstance* instance = 552 WorkerProcessHost::WorkerInstance* instance =
549 FindPendingInstance(url, name, incognito); 553 FindPendingInstance(url, name, incognito);
550 if (instance) 554 if (instance)
551 return instance; 555 return instance;
552 556
553 // No existing pending worker - create a new one. 557 // No existing pending worker - create a new one.
554 WorkerProcessHost::WorkerInstance pending( 558 WorkerProcessHost::WorkerInstance pending(url, true, incognito, name);
555 url, true, incognito, name, MSG_ROUTING_NONE, 0, 0, 0, NULL);
556 pending_shared_workers_.push_back(pending); 559 pending_shared_workers_.push_back(pending);
557 return &pending_shared_workers_.back(); 560 return &pending_shared_workers_.back();
558 } 561 }
OLDNEW
« no previous file with comments | « content/browser/worker_host/worker_service.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698