summaryrefslogtreecommitdiffstats
path: root/chrome/browser/worker_host
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/worker_host')
-rw-r--r--chrome/browser/worker_host/worker_process_host.cc36
-rw-r--r--chrome/browser/worker_host/worker_process_host.h29
-rw-r--r--chrome/browser/worker_host/worker_service.cc35
-rw-r--r--chrome/browser/worker_host/worker_service.h15
4 files changed, 92 insertions, 23 deletions
diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc
index ba01a2d..38dd8e3 100644
--- a/chrome/browser/worker_host/worker_process_host.cc
+++ b/chrome/browser/worker_host/worker_process_host.cc
@@ -14,6 +14,7 @@
#include "base/string_util.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/child_process_security_policy.h"
+#include "chrome/browser/renderer_host/database_dispatcher_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
@@ -53,13 +54,21 @@ class WorkerCrashTask : public Task {
WorkerProcessHost::WorkerProcessHost(
- ResourceDispatcherHost* resource_dispatcher_host)
- : ChildProcessHost(WORKER_PROCESS, resource_dispatcher_host) {
+ ResourceDispatcherHost* resource_dispatcher_host,
+ webkit_database::DatabaseTracker *db_tracker,
+ HostContentSettingsMap *host_content_settings_map)
+ : ChildProcessHost(WORKER_PROCESS, resource_dispatcher_host),
+ host_content_settings_map_(host_content_settings_map) {
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);
}
WorkerProcessHost::~WorkerProcessHost() {
+ // Shut down the database dispatcher host.
+ db_dispatcher_host_->Shutdown();
+
// Let interested observers know we are being deleted.
NotificationService::current()->Notify(
NotificationType::WORKER_PROCESS_HOST_SHUTDOWN,
@@ -108,6 +117,11 @@ bool WorkerProcessHost::Init() {
}
if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableDatabases)) {
+ cmd_line->AppendSwitch(switches::kDisableDatabases);
+ }
+
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableLogging)) {
cmd_line->AppendSwitch(switches::kEnableLogging);
}
@@ -124,6 +138,7 @@ bool WorkerProcessHost::Init() {
switches::kDisableWebSockets)) {
cmd_line->AppendSwitch(switches::kDisableWebSockets);
}
+
#if defined(OS_WIN)
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableDesktopNotifications)) {
@@ -233,8 +248,9 @@ void WorkerProcessHost::OnWorkerContextClosed(int worker_route_id) {
void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) {
bool msg_is_ok = true;
- bool handled = MessagePortDispatcher::GetInstance()->OnMessageReceived(
- message, this, next_route_id_callback_.get(), &msg_is_ok);
+ bool handled = db_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
+ MessagePortDispatcher::GetInstance()->OnMessageReceived(
+ message, this, next_route_id_callback_.get(), &msg_is_ok);
if (!handled) {
handled = true;
@@ -279,6 +295,10 @@ void WorkerProcessHost::OnMessageReceived(const IPC::Message& message) {
}
}
+void WorkerProcessHost::OnProcessLaunched() {
+ db_dispatcher_host_->Init(handle());
+}
+
CallbackWithReturnValue<int>::Type* WorkerProcessHost::GetNextRouteIdCallback(
IPC::Message::Sender* sender) {
// We don't keep callbacks for senders associated with workers, so figure out
@@ -435,7 +455,8 @@ void WorkerProcessHost::OnCreateWorker(
WorkerService::GetInstance()->CreateWorker(
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);
+ first_parent->render_view_route_id(), this, *route_id,
+ database_tracker(), host_content_settings_map_);
}
void WorkerProcessHost::OnCancelCreateDedicatedWorker(int route_id) {
@@ -466,6 +487,11 @@ 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,
diff --git a/chrome/browser/worker_host/worker_process_host.h b/chrome/browser/worker_host/worker_process_host.h
index ea585dd..36d4312 100644
--- a/chrome/browser/worker_host/worker_process_host.h
+++ b/chrome/browser/worker_host/worker_process_host.h
@@ -9,13 +9,25 @@
#include "base/basictypes.h"
#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/worker_host/worker_document_set.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_channel.h"
+class DatabaseDispatcherHost;
+namespace webkit_database {
+class DatabaseTracker;
+} // namespace webkit_database
+
struct ViewHostMsg_CreateWorker_Params;
+// The WorkerProcessHost is the interface that represents the browser side of
+// 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.
class WorkerProcessHost : public ChildProcessHost {
public:
@@ -82,7 +94,9 @@ class WorkerProcessHost : public ChildProcessHost {
scoped_refptr<WorkerDocumentSet> worker_document_set_;
};
- explicit WorkerProcessHost(ResourceDispatcherHost* resource_dispatcher_host);
+ WorkerProcessHost(ResourceDispatcherHost* resource_dispatcher_host,
+ webkit_database::DatabaseTracker *db_tracker,
+ HostContentSettingsMap *host_content_settings_map);
~WorkerProcessHost();
// Starts the process. Returns true iff it succeeded.
@@ -102,6 +116,12 @@ 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_;
+ }
+
protected:
friend class WorkerService;
@@ -118,6 +138,9 @@ class WorkerProcessHost : public ChildProcessHost {
// Called when a message arrives from the worker process.
void OnMessageReceived(const IPC::Message& message);
+ // Called when the process has been launched successfully.
+ virtual void OnProcessLaunched();
+
// Called when the app invokes close() from within worker context.
void OnWorkerContextClosed(int worker_route_id);
@@ -150,6 +173,10 @@ class WorkerProcessHost : public ChildProcessHost {
Instances instances_;
+ 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 f021e24..6946427 100644
--- a/chrome/browser/worker_host/worker_service.cc
+++ b/chrome/browser/worker_host/worker_service.cc
@@ -9,6 +9,7 @@
#include "base/sys_info.h"
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
@@ -45,15 +46,18 @@ void WorkerService::Initialize(ResourceDispatcherHost* rdh) {
WorkerService::~WorkerService() {
}
-bool WorkerService::CreateWorker(const GURL &url,
- bool is_shared,
- bool off_the_record,
- const string16& name,
- unsigned long long document_id,
- int renderer_id,
- int render_view_route_id,
- IPC::Message::Sender* sender,
- int sender_route_id) {
+bool WorkerService::CreateWorker(
+ const GURL &url,
+ bool is_shared,
+ bool off_the_record,
+ const string16& name,
+ unsigned long long document_id,
+ int renderer_id,
+ int render_view_route_id,
+ IPC::Message::Sender* sender,
+ int sender_route_id,
+ webkit_database::DatabaseTracker* db_tracker,
+ HostContentSettingsMap* host_content_settings_map) {
// 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
@@ -67,11 +71,14 @@ bool WorkerService::CreateWorker(const GURL &url,
instance.worker_document_set()->Add(
sender, document_id, renderer_id, render_view_route_id);
- return CreateWorkerFromInstance(instance);
+ return CreateWorkerFromInstance(instance, db_tracker,
+ host_content_settings_map);
}
bool WorkerService::CreateWorkerFromInstance(
- WorkerProcessHost::WorkerInstance instance) {
+ WorkerProcessHost::WorkerInstance instance,
+ webkit_database::DatabaseTracker* db_tracker,
+ HostContentSettingsMap* host_content_settings_map) {
WorkerProcessHost* worker = NULL;
if (CommandLine::ForCurrentProcess()->HasSwitch(
@@ -152,7 +159,8 @@ bool WorkerService::CreateWorkerFromInstance(
}
if (!worker) {
- worker = new WorkerProcessHost(resource_dispatcher_host_);
+ worker = new WorkerProcessHost(resource_dispatcher_host_, db_tracker,
+ host_content_settings_map);
if (!worker->Init()) {
delete worker;
return false;
@@ -440,7 +448,8 @@ void WorkerService::WorkerProcessDestroyed(WorkerProcessHost* process) {
if (CanCreateWorkerProcess(*i)) {
WorkerProcessHost::WorkerInstance instance = *i;
queued_workers_.erase(i);
- CreateWorkerFromInstance(instance);
+ CreateWorkerFromInstance(instance, process->database_tracker(),
+ process->GetHostContentSettingsMap());
// CreateWorkerFromInstance can modify the queued_workers_ list when it
// coalesces queued instances after starting a shared worker, so we
diff --git a/chrome/browser/worker_host/worker_service.h b/chrome/browser/worker_host/worker_service.h
index 97891b5..c08d139 100644
--- a/chrome/browser/worker_host/worker_service.h
+++ b/chrome/browser/worker_host/worker_service.h
@@ -14,8 +14,10 @@
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message.h"
-class WorkerProcessHost;
+class DatabaseTracker;
+class HostContentSettingsMap;
class ResourceDispatcherHost;
+class WorkerProcessHost;
class WorkerService : public NotificationObserver {
public:
@@ -25,7 +27,7 @@ class WorkerService : public NotificationObserver {
// Initialize the WorkerService. OK to be called multiple times.
void Initialize(ResourceDispatcherHost* rdh);
- // Creates a dedicated worker. Returns true on success.
+ // Creates a worker. Returns true on success.
bool CreateWorker(const GURL &url,
bool is_shared,
bool is_off_the_record,
@@ -34,7 +36,9 @@ class WorkerService : public NotificationObserver {
int renderer_pid,
int render_view_route_id,
IPC::Message::Sender* sender,
- int sender_route_id);
+ int sender_route_id,
+ webkit_database::DatabaseTracker* db_tracker,
+ HostContentSettingsMap* host_content_settings_map);
// 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
@@ -88,7 +92,10 @@ class WorkerService : public NotificationObserver {
~WorkerService();
// Given a WorkerInstance, create an associated worker process.
- bool CreateWorkerFromInstance(WorkerProcessHost::WorkerInstance instance);
+ bool CreateWorkerFromInstance(
+ WorkerProcessHost::WorkerInstance instance,
+ webkit_database::DatabaseTracker* db_tracker,
+ HostContentSettingsMap* host_content_settings_map);
// Returns a WorkerProcessHost object if one exists for the given domain, or
// NULL if there are no such workers yet.