summaryrefslogtreecommitdiffstats
path: root/chrome/browser/worker_host
diff options
context:
space:
mode:
authormichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-24 19:19:23 +0000
committermichaeln@chromium.org <michaeln@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-24 19:19:23 +0000
commitf9bc9c0bc9ddd0dbb989286d3abca0d740635172 (patch)
treebde968d4aba9a5ce7c07b0817350c2b841455e96 /chrome/browser/worker_host
parent87924d38251e94c46ba70d57cf57d8f50a73171c (diff)
downloadchromium_src-f9bc9c0bc9ddd0dbb989286d3abca0d740635172.zip
chromium_src-f9bc9c0bc9ddd0dbb989286d3abca0d740635172.tar.gz
chromium_src-f9bc9c0bc9ddd0dbb989286d3abca0d740635172.tar.bz2
Browser process scaffolding to support having appcache work in workers.
* Associate a RequestContext with a WorkerProcessHost. This corresponds to themain request context of the profile for which the worker process is running. Also associate the context with each WorkerInstance which comes into existance priorto the WorkerProcessHost that will host the instance. * Give the WorkerProcessHost an AppCacheDispatcherHost. * Fix up some recently botched IPC plumbing for ViewHostMsg_CreateWorker_Params. BUG=39368 TEST=there are no worker unit tests Review URL: http://codereview.chromium.org/2010010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48064 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/worker_host')
-rw-r--r--chrome/browser/worker_host/worker_process_host.cc43
-rw-r--r--chrome/browser/worker_host/worker_process_host.h30
-rw-r--r--chrome/browser/worker_host/worker_service.cc51
-rw-r--r--chrome/browser/worker_host/worker_service.h12
4 files changed, 73 insertions, 63 deletions
diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc
index e7133bc..aecb07c 100644
--- a/chrome/browser/worker_host/worker_process_host.cc
+++ b/chrome/browser/worker_host/worker_process_host.cc
@@ -12,6 +12,7 @@
#include "base/debug_util.h"
#include "base/message_loop.h"
#include "base/string_util.h"
+#include "chrome/browser/appcache/appcache_dispatcher_host.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/child_process_security_policy.h"
#include "chrome/browser/net/chrome_url_request_context.h"
@@ -54,17 +55,18 @@ class WorkerCrashTask : public Task {
int render_view_id_;
};
-
WorkerProcessHost::WorkerProcessHost(
ResourceDispatcherHost* resource_dispatcher_host,
- webkit_database::DatabaseTracker *db_tracker,
- HostContentSettingsMap *host_content_settings_map)
+ ChromeURLRequestContext *request_context)
: ChildProcessHost(WORKER_PROCESS, resource_dispatcher_host),
- host_content_settings_map_(host_content_settings_map) {
+ request_context_(request_context),
+ appcache_dispatcher_host_(
+ new AppCacheDispatcherHost(request_context)) {
next_route_id_callback_.reset(NewCallbackWithReturnValue(
WorkerService::GetInstance(), &WorkerService::next_worker_route_id));
- db_dispatcher_host_ =
- new DatabaseDispatcherHost(db_tracker, this, host_content_settings_map);
+ db_dispatcher_host_ = new DatabaseDispatcherHost(
+ request_context->database_tracker(), this,
+ request_context_->host_content_settings_map());
}
WorkerProcessHost::~WorkerProcessHost() {
@@ -242,7 +244,7 @@ bool WorkerProcessHost::FilterMessage(const IPC::Message& message,
URLRequestContext* WorkerProcessHost::GetRequestContext(
uint32 request_id,
const ViewHostMsg_Resource_Request& request_data) {
- return NULL;
+ return request_context_;
}
// Sent to notify the browser process when a worker context invokes close(), so
@@ -261,7 +263,9 @@ void WorkerProcessHost::OnWorkerContextClosed(int worker_route_id) {
void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) {
bool msg_is_ok = true;
- bool handled = db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
+ bool handled =
+ appcache_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
+ db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
MessagePortDispatcher::GetInstance()->OnMessageReceived(
message, this, next_route_id_callback_.get(), &msg_is_ok);
@@ -310,6 +314,7 @@ void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) {
void WorkerProcessHost::OnProcessLaunched() {
db_dispatcher_host_->Init(handle());
+ appcache_dispatcher_host_->Initialize(this, id(), handle());
}
CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback(
@@ -480,7 +485,7 @@ void WorkerProcessHost::OnCreateWorker(
params.url, params.is_shared, instances_.front().off_the_record(),
params.name, params.document_id, first_parent->renderer_id(),
first_parent->render_view_route_id(), this, *route_id,
- database_tracker(), host_content_settings_map_);
+ request_context_);
}
void WorkerProcessHost::OnCancelCreateDedicatedWorker(int route_id) {
@@ -511,23 +516,23 @@ void WorkerProcessHost::DocumentDetached(IPC::Message::Sender* parent,
}
}
-webkit_database::DatabaseTracker*
- WorkerProcessHost::database_tracker() const {
- return db_dispatcher_host_->database_tracker();
-}
-
-WorkerProcessHost::WorkerInstance::WorkerInstance(const GURL& url,
- bool shared,
- bool off_the_record,
- const string16& name,
- int worker_route_id)
+WorkerProcessHost::WorkerInstance::WorkerInstance(
+ const GURL& url,
+ bool shared,
+ bool off_the_record,
+ const string16& name,
+ int worker_route_id,
+ ChromeURLRequestContext* request_context)
: url_(url),
shared_(shared),
off_the_record_(off_the_record),
closed_(false),
name_(name),
worker_route_id_(worker_route_id),
+ request_context_(request_context),
worker_document_set_(new WorkerDocumentSet()) {
+ DCHECK(!request_context ||
+ (off_the_record == request_context->is_off_the_record()));
}
// Compares an instance based on the algorithm in the WebWorkers spec - an
diff --git a/chrome/browser/worker_host/worker_process_host.h b/chrome/browser/worker_host/worker_process_host.h
index 36d4312..a18897d 100644
--- a/chrome/browser/worker_host/worker_process_host.h
+++ b/chrome/browser/worker_host/worker_process_host.h
@@ -11,11 +11,14 @@
#include "base/callback.h"
#include "base/ref_counted.h"
#include "chrome/browser/child_process_host.h"
-#include "chrome/browser/host_content_settings_map.h"
+#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/worker_host/worker_document_set.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_channel.h"
+class AppCacheDispatcherHost;
+class ChromeURLRequestContext;
+class ChromeURLRequestContextGetter;
class DatabaseDispatcherHost;
namespace webkit_database {
class DatabaseTracker;
@@ -27,7 +30,7 @@ struct ViewHostMsg_CreateWorker_Params;
// the browser <-> worker communication channel. There will be one
// WorkerProcessHost per worker process. Currently each worker runs in its own
// process, but that may change. However, we do assume [by storing a
-// HostContentSettingsMap] that a WorkerProcessHost serves a single Profile.
+// ChromeURLRequestContext] that a WorkerProcessHost serves a single Profile.
class WorkerProcessHost : public ChildProcessHost {
public:
@@ -39,7 +42,8 @@ class WorkerProcessHost : public ChildProcessHost {
bool shared,
bool off_the_record,
const string16& name,
- int worker_route_id);
+ int worker_route_id,
+ ChromeURLRequestContext* request_context);
// Unique identifier for a worker client.
typedef std::pair<IPC::Message::Sender*, int> SenderInfo;
@@ -81,6 +85,9 @@ class WorkerProcessHost : public ChildProcessHost {
WorkerDocumentSet* worker_document_set() const {
return worker_document_set_;
}
+ ChromeURLRequestContext* request_context() const {
+ return request_context_;
+ }
private:
// Set of all senders (clients) associated with this worker.
@@ -90,13 +97,14 @@ class WorkerProcessHost : public ChildProcessHost {
bool closed_;
string16 name_;
int worker_route_id_;
+ scoped_refptr<ChromeURLRequestContext> request_context_;
SenderList senders_;
scoped_refptr<WorkerDocumentSet> worker_document_set_;
};
- WorkerProcessHost(ResourceDispatcherHost* resource_dispatcher_host,
- webkit_database::DatabaseTracker *db_tracker,
- HostContentSettingsMap *host_content_settings_map);
+ WorkerProcessHost(
+ ResourceDispatcherHost* resource_dispatcher_host,
+ ChromeURLRequestContext* request_context);
~WorkerProcessHost();
// Starts the process. Returns true iff it succeeded.
@@ -116,10 +124,8 @@ class WorkerProcessHost : public ChildProcessHost {
void DocumentDetached(IPC::Message::Sender* sender,
unsigned long long document_id);
- webkit_database::DatabaseTracker* database_tracker() const;
-
- HostContentSettingsMap *GetHostContentSettingsMap() const {
- return host_content_settings_map_;
+ ChromeURLRequestContext* request_context() const {
+ return request_context_;
}
protected:
@@ -173,10 +179,10 @@ class WorkerProcessHost : public ChildProcessHost {
Instances instances_;
+ scoped_refptr<ChromeURLRequestContext> request_context_;
+ scoped_ptr<AppCacheDispatcherHost> appcache_dispatcher_host_;
scoped_refptr<DatabaseDispatcherHost> db_dispatcher_host_;
- scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
-
// A callback to create a routing id for the associated worker process.
scoped_ptr<CallbackWithReturnValue<int>::Type> next_route_id_callback_;
diff --git a/chrome/browser/worker_host/worker_service.cc b/chrome/browser/worker_host/worker_service.cc
index 6946427..2f50e33 100644
--- a/chrome/browser/worker_host/worker_service.cc
+++ b/chrome/browser/worker_host/worker_service.cc
@@ -56,8 +56,7 @@ bool WorkerService::CreateWorker(
int render_view_route_id,
IPC::Message::Sender* sender,
int sender_route_id,
- webkit_database::DatabaseTracker* db_tracker,
- HostContentSettingsMap* host_content_settings_map) {
+ ChromeURLRequestContext* request_context) {
// Generate a unique route id for the browser-worker communication that's
// unique among all worker processes. That way when the worker process sends
// a wrapped IPC message through us, we know which WorkerProcessHost to give
@@ -66,20 +65,22 @@ bool WorkerService::CreateWorker(
is_shared,
off_the_record,
name,
- next_worker_route_id());
+ next_worker_route_id(),
+ request_context);
instance.AddSender(sender, sender_route_id);
instance.worker_document_set()->Add(
sender, document_id, renderer_id, render_view_route_id);
- return CreateWorkerFromInstance(instance, db_tracker,
- host_content_settings_map);
+ return CreateWorkerFromInstance(instance);
}
bool WorkerService::CreateWorkerFromInstance(
- WorkerProcessHost::WorkerInstance instance,
- webkit_database::DatabaseTracker* db_tracker,
- HostContentSettingsMap* host_content_settings_map) {
+ WorkerProcessHost::WorkerInstance instance) {
+ // TODO(michaeln): We need to ensure that a process is working
+ // on behalf of a single profile. The process sharing logic below
+ // does not ensure that. Consider making WorkerService a per profile
+ // object to help with this.
WorkerProcessHost* worker = NULL;
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kWebWorkerProcessPerCore)) {
@@ -159,27 +160,32 @@ bool WorkerService::CreateWorkerFromInstance(
}
if (!worker) {
- worker = new WorkerProcessHost(resource_dispatcher_host_, db_tracker,
- host_content_settings_map);
+ worker = new WorkerProcessHost(resource_dispatcher_host_,
+ instance.request_context());
if (!worker->Init()) {
delete worker;
return false;
}
}
+ // TODO(michaeln): As written, test can fail per my earlier comment in
+ // this method, but that's a bug.
+ // DCHECK(worker->request_context() == instance.request_context());
+
worker->CreateWorker(instance);
return true;
}
-bool WorkerService::LookupSharedWorker(const GURL &url,
- const string16& name,
- bool off_the_record,
- unsigned long long document_id,
- int renderer_id,
- int render_view_route_id,
- IPC::Message::Sender* sender,
- int sender_route_id,
- bool* url_mismatch) {
+bool WorkerService::LookupSharedWorker(
+ const GURL &url,
+ const string16& name,
+ bool off_the_record,
+ unsigned long long document_id,
+ int renderer_id,
+ int render_view_route_id,
+ IPC::Message::Sender* sender,
+ int sender_route_id,
+ bool* url_mismatch) {
bool found_instance = true;
WorkerProcessHost::WorkerInstance* instance =
FindSharedWorkerInstance(url, name, off_the_record);
@@ -448,8 +454,7 @@ void WorkerService::WorkerProcessDestroyed(WorkerProcessHost* process) {
if (CanCreateWorkerProcess(*i)) {
WorkerProcessHost::WorkerInstance instance = *i;
queued_workers_.erase(i);
- CreateWorkerFromInstance(instance, process->database_tracker(),
- process->GetHostContentSettingsMap());
+ CreateWorkerFromInstance(instance);
// CreateWorkerFromInstance can modify the queued_workers_ list when it
// coalesces queued instances after starting a shared worker, so we
@@ -530,7 +535,7 @@ WorkerProcessHost::WorkerInstance*
WorkerService::CreatePendingInstance(const GURL& url,
const string16& name,
bool off_the_record) {
- // Look for an existing pending worker.
+ // Look for an existing pending shared worker.
WorkerProcessHost::WorkerInstance* instance =
FindPendingInstance(url, name, off_the_record);
if (instance)
@@ -538,7 +543,7 @@ WorkerService::CreatePendingInstance(const GURL& url,
// No existing pending worker - create a new one.
WorkerProcessHost::WorkerInstance pending(
- url, true, off_the_record, name, MSG_ROUTING_NONE);
+ url, true, off_the_record, name, MSG_ROUTING_NONE, NULL);
pending_shared_workers_.push_back(pending);
return &pending_shared_workers_.back();
}
diff --git a/chrome/browser/worker_host/worker_service.h b/chrome/browser/worker_host/worker_service.h
index c08d139..50c381a 100644
--- a/chrome/browser/worker_host/worker_service.h
+++ b/chrome/browser/worker_host/worker_service.h
@@ -14,10 +14,8 @@
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message.h"
-class DatabaseTracker;
-class HostContentSettingsMap;
+class ChromeURLRequestContext;
class ResourceDispatcherHost;
-class WorkerProcessHost;
class WorkerService : public NotificationObserver {
public:
@@ -37,8 +35,7 @@ class WorkerService : public NotificationObserver {
int render_view_route_id,
IPC::Message::Sender* sender,
int sender_route_id,
- webkit_database::DatabaseTracker* db_tracker,
- HostContentSettingsMap* host_content_settings_map);
+ ChromeURLRequestContext* request_context);
// Validates the passed URL and checks for the existence of matching shared
// worker. Returns true if the url was found, and sets the url_mismatch out
@@ -92,10 +89,7 @@ class WorkerService : public NotificationObserver {
~WorkerService();
// Given a WorkerInstance, create an associated worker process.
- bool CreateWorkerFromInstance(
- WorkerProcessHost::WorkerInstance instance,
- webkit_database::DatabaseTracker* db_tracker,
- HostContentSettingsMap* host_content_settings_map);
+ bool CreateWorkerFromInstance(WorkerProcessHost::WorkerInstance instance);
// Returns a WorkerProcessHost object if one exists for the given domain, or
// NULL if there are no such workers yet.