summaryrefslogtreecommitdiffstats
path: root/content/browser/worker_host/worker_process_host.h
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-28 21:30:40 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-28 21:30:40 +0000
commit1b8af731dccaaf3b040e32481aedf9e113f32854 (patch)
tree24e10ac7e200637d362171c9b3b51f158fb3c660 /content/browser/worker_host/worker_process_host.h
parentd45271ca30365429b189bc71217349cb2ea5f852 (diff)
downloadchromium_src-1b8af731dccaaf3b040e32481aedf9e113f32854.zip
chromium_src-1b8af731dccaaf3b040e32481aedf9e113f32854.tar.gz
chromium_src-1b8af731dccaaf3b040e32481aedf9e113f32854.tar.bz2
Move worker_host code to content.
TBR=avi Review URL: http://codereview.chromium.org/6592041 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76263 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/worker_host/worker_process_host.h')
-rw-r--r--content/browser/worker_host/worker_process_host.h187
1 files changed, 187 insertions, 0 deletions
diff --git a/content/browser/worker_host/worker_process_host.h b/content/browser/worker_host/worker_process_host.h
new file mode 100644
index 0000000..af446f0
--- /dev/null
+++ b/content/browser/worker_host/worker_process_host.h
@@ -0,0 +1,187 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_
+#define CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_
+#pragma once
+
+#include <list>
+
+#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "chrome/browser/net/chrome_url_request_context.h"
+#include "content/browser/browser_child_process_host.h"
+#include "content/browser/worker_host/worker_document_set.h"
+#include "googleurl/src/gurl.h"
+
+class URLRequestContextGetter;
+
+// 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
+// net::URLRequestContext) that a WorkerProcessHost serves a single Profile.
+class WorkerProcessHost : public BrowserChildProcessHost {
+ public:
+
+ // Contains information about each worker instance, needed to forward messages
+ // between the renderer and worker processes.
+ class WorkerInstance {
+ public:
+ WorkerInstance(const GURL& url,
+ bool shared,
+ bool off_the_record,
+ const string16& name,
+ int worker_route_id,
+ int parent_process_id,
+ int parent_appcache_host_id,
+ int64 main_resource_appcache_id,
+ URLRequestContextGetter* request_context);
+ ~WorkerInstance();
+
+ // Unique identifier for a worker client.
+ typedef std::pair<WorkerMessageFilter*, int> FilterInfo;
+
+ // APIs to manage the filter list for a given instance.
+ void AddFilter(WorkerMessageFilter* filter, int route_id);
+ void RemoveFilter(WorkerMessageFilter* filter, int route_id);
+ void RemoveFilters(WorkerMessageFilter* filter);
+ bool HasFilter(WorkerMessageFilter* filter, int route_id) const;
+ bool RendererIsParent(int render_process_id, int render_view_id) const;
+ int NumFilters() const { return filters_.size(); }
+ // Returns the single filter (must only be one).
+ FilterInfo GetFilter() const;
+
+ typedef std::list<FilterInfo> FilterList;
+ const FilterList& filters() const { return filters_; }
+
+ // Checks if this WorkerInstance matches the passed url/name params
+ // (per the comparison algorithm in the WebWorkers spec). This API only
+ // applies to shared workers.
+ bool Matches(
+ const GURL& url, const string16& name, bool off_the_record) const;
+
+ // Shares the passed instance's WorkerDocumentSet with this instance. This
+ // instance's current WorkerDocumentSet is dereferenced (and freed if this
+ // is the only reference) as a result.
+ void ShareDocumentSet(const WorkerInstance& instance) {
+ worker_document_set_ = instance.worker_document_set_;
+ };
+
+ // Accessors
+ bool shared() const { return shared_; }
+ bool off_the_record() const { return off_the_record_; }
+ bool closed() const { return closed_; }
+ void set_closed(bool closed) { closed_ = closed; }
+ const GURL& url() const { return url_; }
+ const string16 name() const { return name_; }
+ int worker_route_id() const { return worker_route_id_; }
+ int parent_process_id() const { return parent_process_id_; }
+ int parent_appcache_host_id() const { return parent_appcache_host_id_; }
+ int64 main_resource_appcache_id() const {
+ return main_resource_appcache_id_;
+ }
+ WorkerDocumentSet* worker_document_set() const {
+ return worker_document_set_;
+ }
+ URLRequestContextGetter* request_context() const {
+ return request_context_;
+ }
+
+ private:
+ // Set of all filters (clients) associated with this worker.
+ GURL url_;
+ bool shared_;
+ bool off_the_record_;
+ bool closed_;
+ string16 name_;
+ int worker_route_id_;
+ int parent_process_id_;
+ int parent_appcache_host_id_;
+ int64 main_resource_appcache_id_;
+ scoped_refptr<URLRequestContextGetter> request_context_;
+ FilterList filters_;
+ scoped_refptr<WorkerDocumentSet> worker_document_set_;
+ };
+
+ WorkerProcessHost(
+ ResourceDispatcherHost* resource_dispatcher_host,
+ URLRequestContextGetter* request_context);
+ ~WorkerProcessHost();
+
+ // Starts the process. Returns true iff it succeeded.
+ // |render_process_id| is the renderer process responsible for starting this
+ // worker.
+ bool Init(int render_process_id);
+
+ // Creates a worker object in the process.
+ void CreateWorker(const WorkerInstance& instance);
+
+ // Returns true iff the given message from a renderer process was forwarded to
+ // the worker.
+ bool FilterMessage(const IPC::Message& message, WorkerMessageFilter* filter);
+
+ void FilterShutdown(WorkerMessageFilter* filter);
+
+ // Shuts down any shared workers that are no longer referenced by active
+ // documents.
+ void DocumentDetached(WorkerMessageFilter* filter,
+ unsigned long long document_id);
+
+ URLRequestContextGetter* request_context() const {
+ return request_context_;
+ }
+
+ protected:
+ friend class WorkerService;
+
+ typedef std::list<WorkerInstance> Instances;
+ const Instances& instances() const { return instances_; }
+ Instances& mutable_instances() { return instances_; }
+
+ private:
+ // Called when the process has been launched successfully.
+ virtual void OnProcessLaunched();
+
+ // Creates and adds the message filters.
+ void CreateMessageFilters(int render_process_id);
+
+ // IPC::Channel::Listener implementation:
+ // Called when a message arrives from the worker process.
+ virtual bool OnMessageReceived(const IPC::Message& message);
+
+ void OnWorkerContextClosed(int worker_route_id);
+ void OnAllowDatabase(int worker_route_id,
+ const GURL& url,
+ const string16& name,
+ const string16& display_name,
+ unsigned long estimated_size,
+ bool* result);
+
+ // Relays a message to the given endpoint. Takes care of parsing the message
+ // if it contains a message port and sending it a valid route id.
+ static void RelayMessage(const IPC::Message& message,
+ WorkerMessageFilter* filter,
+ int route_id);
+
+ virtual bool CanShutdown();
+
+ // Updates the title shown in the task manager.
+ void UpdateTitle();
+
+ ChromeURLRequestContext* GetChromeURLRequestContext();
+
+ Instances instances_;
+
+ scoped_refptr<URLRequestContextGetter> request_context_;
+
+ // A reference to the filter associated with this worker process. We need to
+ // keep this around since we'll use it when forward messages to the worker
+ // process.
+ scoped_refptr<WorkerMessageFilter> worker_message_filter_;
+
+ DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost);
+};
+
+#endif // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_