| OLD | NEW | 
|---|
| 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 #ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 5 #ifndef CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 
| 6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 6 #define CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 
| 7 #pragma once | 7 #pragma once | 
| 8 | 8 | 
| 9 #include <list> | 9 #include <list> | 
| 10 | 10 | 
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" | 
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" | 
| 13 #include "chrome/browser/net/chrome_url_request_context.h" | 13 #include "chrome/browser/net/chrome_url_request_context.h" | 
| 14 #include "content/browser/browser_child_process_host.h" | 14 #include "content/browser/browser_child_process_host.h" | 
| 15 #include "content/browser/worker_host/worker_document_set.h" | 15 #include "content/browser/worker_host/worker_document_set.h" | 
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" | 
| 17 | 17 | 
|  | 18 namespace content { | 
|  | 19 class ResourceContext; | 
|  | 20 }  // namespace content | 
| 18 namespace net { | 21 namespace net { | 
| 19 class URLRequestContextGetter; | 22 class URLRequestContextGetter; | 
| 20 } | 23 }  // namespace net | 
| 21 | 24 | 
| 22 // The WorkerProcessHost is the interface that represents the browser side of | 25 // The WorkerProcessHost is the interface that represents the browser side of | 
| 23 // the browser <-> worker communication channel. There will be one | 26 // the browser <-> worker communication channel. There will be one | 
| 24 // WorkerProcessHost per worker process.  Currently each worker runs in its own | 27 // WorkerProcessHost per worker process.  Currently each worker runs in its own | 
| 25 // process, but that may change.  However, we do assume (by storing a | 28 // process, but that may change.  However, we do assume (by storing a | 
| 26 // net::URLRequestContext) that a WorkerProcessHost serves a single Profile. | 29 // net::URLRequestContext) that a WorkerProcessHost serves a single Profile. | 
| 27 class WorkerProcessHost : public BrowserChildProcessHost { | 30 class WorkerProcessHost : public BrowserChildProcessHost { | 
| 28  public: | 31  public: | 
| 29 | 32 | 
| 30   // Contains information about each worker instance, needed to forward messages | 33   // Contains information about each worker instance, needed to forward messages | 
| 31   // between the renderer and worker processes. | 34   // between the renderer and worker processes. | 
| 32   class WorkerInstance { | 35   class WorkerInstance { | 
| 33    public: | 36    public: | 
| 34     WorkerInstance(const GURL& url, | 37     WorkerInstance(const GURL& url, | 
| 35                    bool shared, | 38                    bool shared, | 
| 36                    bool incognito, | 39                    bool incognito, | 
| 37                    const string16& name, | 40                    const string16& name, | 
| 38                    int worker_route_id, | 41                    int worker_route_id, | 
| 39                    int parent_process_id, | 42                    int parent_process_id, | 
| 40                    int parent_appcache_host_id, | 43                    int parent_appcache_host_id, | 
| 41                    int64 main_resource_appcache_id, | 44                    int64 main_resource_appcache_id, | 
| 42                    net::URLRequestContextGetter* request_context); | 45                    net::URLRequestContextGetter* request_context_getter, | 
|  | 46                    const content::ResourceContext& resource_context); | 
|  | 47     // Used for pending instances. Rest of the parameters are ignored. | 
|  | 48     WorkerInstance(const GURL& url, | 
|  | 49                    bool shared, | 
|  | 50                    bool incognito, | 
|  | 51                    const string16& name); | 
| 43     ~WorkerInstance(); | 52     ~WorkerInstance(); | 
| 44 | 53 | 
| 45     // Unique identifier for a worker client. | 54     // Unique identifier for a worker client. | 
| 46     typedef std::pair<WorkerMessageFilter*, int> FilterInfo; | 55     typedef std::pair<WorkerMessageFilter*, int> FilterInfo; | 
| 47 | 56 | 
| 48     // APIs to manage the filter list for a given instance. | 57     // APIs to manage the filter list for a given instance. | 
| 49     void AddFilter(WorkerMessageFilter* filter, int route_id); | 58     void AddFilter(WorkerMessageFilter* filter, int route_id); | 
| 50     void RemoveFilter(WorkerMessageFilter* filter, int route_id); | 59     void RemoveFilter(WorkerMessageFilter* filter, int route_id); | 
| 51     void RemoveFilters(WorkerMessageFilter* filter); | 60     void RemoveFilters(WorkerMessageFilter* filter); | 
| 52     bool HasFilter(WorkerMessageFilter* filter, int route_id) const; | 61     bool HasFilter(WorkerMessageFilter* filter, int route_id) const; | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 80     const string16 name() const { return name_; } | 89     const string16 name() const { return name_; } | 
| 81     int worker_route_id() const { return worker_route_id_; } | 90     int worker_route_id() const { return worker_route_id_; } | 
| 82     int parent_process_id() const { return parent_process_id_; } | 91     int parent_process_id() const { return parent_process_id_; } | 
| 83     int parent_appcache_host_id() const { return parent_appcache_host_id_; } | 92     int parent_appcache_host_id() const { return parent_appcache_host_id_; } | 
| 84     int64 main_resource_appcache_id() const { | 93     int64 main_resource_appcache_id() const { | 
| 85       return main_resource_appcache_id_; | 94       return main_resource_appcache_id_; | 
| 86     } | 95     } | 
| 87     WorkerDocumentSet* worker_document_set() const { | 96     WorkerDocumentSet* worker_document_set() const { | 
| 88       return worker_document_set_; | 97       return worker_document_set_; | 
| 89     } | 98     } | 
| 90     net::URLRequestContextGetter* request_context() const { | 99     net::URLRequestContextGetter* request_context_getter() const { | 
| 91       return request_context_; | 100       return request_context_getter_; | 
|  | 101     } | 
|  | 102     const content::ResourceContext& resource_context() const { | 
|  | 103       return *resource_context_; | 
| 92     } | 104     } | 
| 93 | 105 | 
| 94    private: | 106    private: | 
| 95     // Set of all filters (clients) associated with this worker. | 107     // Set of all filters (clients) associated with this worker. | 
| 96     GURL url_; | 108     GURL url_; | 
| 97     bool shared_; | 109     bool shared_; | 
| 98     bool incognito_; | 110     bool incognito_; | 
| 99     bool closed_; | 111     bool closed_; | 
| 100     string16 name_; | 112     string16 name_; | 
| 101     int worker_route_id_; | 113     int worker_route_id_; | 
| 102     int parent_process_id_; | 114     int parent_process_id_; | 
| 103     int parent_appcache_host_id_; | 115     int parent_appcache_host_id_; | 
| 104     int64 main_resource_appcache_id_; | 116     int64 main_resource_appcache_id_; | 
| 105     scoped_refptr<net::URLRequestContextGetter> request_context_; | 117     scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 
| 106     FilterList filters_; | 118     FilterList filters_; | 
| 107     scoped_refptr<WorkerDocumentSet> worker_document_set_; | 119     scoped_refptr<WorkerDocumentSet> worker_document_set_; | 
|  | 120     const content::ResourceContext* const resource_context_; | 
| 108   }; | 121   }; | 
| 109 | 122 | 
| 110   WorkerProcessHost( | 123   WorkerProcessHost( | 
| 111       ResourceDispatcherHost* resource_dispatcher_host, | 124       net::URLRequestContextGetter* request_context_getter, | 
| 112       net::URLRequestContextGetter* request_context); | 125       const content::ResourceContext& resource_context, | 
|  | 126       ResourceDispatcherHost* resource_dispatcher_host); | 
| 113   ~WorkerProcessHost(); | 127   ~WorkerProcessHost(); | 
| 114 | 128 | 
| 115   // Starts the process.  Returns true iff it succeeded. | 129   // Starts the process.  Returns true iff it succeeded. | 
| 116   // |render_process_id| is the renderer process responsible for starting this | 130   // |render_process_id| is the renderer process responsible for starting this | 
| 117   // worker. | 131   // worker. | 
| 118   bool Init(int render_process_id); | 132   bool Init(int render_process_id); | 
| 119 | 133 | 
| 120   // Creates a worker object in the process. | 134   // Creates a worker object in the process. | 
| 121   void CreateWorker(const WorkerInstance& instance); | 135   void CreateWorker(const WorkerInstance& instance); | 
| 122 | 136 | 
| 123   // Returns true iff the given message from a renderer process was forwarded to | 137   // Returns true iff the given message from a renderer process was forwarded to | 
| 124   // the worker. | 138   // the worker. | 
| 125   bool FilterMessage(const IPC::Message& message, WorkerMessageFilter* filter); | 139   bool FilterMessage(const IPC::Message& message, WorkerMessageFilter* filter); | 
| 126 | 140 | 
| 127   void FilterShutdown(WorkerMessageFilter* filter); | 141   void FilterShutdown(WorkerMessageFilter* filter); | 
| 128 | 142 | 
| 129   // Shuts down any shared workers that are no longer referenced by active | 143   // Shuts down any shared workers that are no longer referenced by active | 
| 130   // documents. | 144   // documents. | 
| 131   void DocumentDetached(WorkerMessageFilter* filter, | 145   void DocumentDetached(WorkerMessageFilter* filter, | 
| 132                         unsigned long long document_id); | 146                         unsigned long long document_id); | 
| 133 | 147 | 
| 134   net::URLRequestContextGetter* request_context() const { |  | 
| 135     return request_context_; |  | 
| 136   } |  | 
| 137 |  | 
| 138  protected: | 148  protected: | 
| 139   friend class WorkerService; | 149   friend class WorkerService; | 
| 140 | 150 | 
| 141   typedef std::list<WorkerInstance> Instances; | 151   typedef std::list<WorkerInstance> Instances; | 
| 142   const Instances& instances() const { return instances_; } | 152   const Instances& instances() const { return instances_; } | 
| 143   Instances& mutable_instances() { return instances_; } | 153   Instances& mutable_instances() { return instances_; } | 
| 144 | 154 | 
| 145  private: | 155  private: | 
| 146   // Called when the process has been launched successfully. | 156   // Called when the process has been launched successfully. | 
| 147   virtual void OnProcessLaunched(); | 157   virtual void OnProcessLaunched(); | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 169 | 179 | 
| 170   virtual bool CanShutdown(); | 180   virtual bool CanShutdown(); | 
| 171 | 181 | 
| 172   // Updates the title shown in the task manager. | 182   // Updates the title shown in the task manager. | 
| 173   void UpdateTitle(); | 183   void UpdateTitle(); | 
| 174 | 184 | 
| 175   ChromeURLRequestContext* GetChromeURLRequestContext(); | 185   ChromeURLRequestContext* GetChromeURLRequestContext(); | 
| 176 | 186 | 
| 177   Instances instances_; | 187   Instances instances_; | 
| 178 | 188 | 
| 179   scoped_refptr<net::URLRequestContextGetter> request_context_; | 189   scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 
|  | 190 | 
|  | 191   const content::ResourceContext* const resource_context_; | 
| 180 | 192 | 
| 181   // A reference to the filter associated with this worker process.  We need to | 193   // A reference to the filter associated with this worker process.  We need to | 
| 182   // keep this around since we'll use it when forward messages to the worker | 194   // keep this around since we'll use it when forward messages to the worker | 
| 183   // process. | 195   // process. | 
| 184   scoped_refptr<WorkerMessageFilter> worker_message_filter_; | 196   scoped_refptr<WorkerMessageFilter> worker_message_filter_; | 
| 185 | 197 | 
|  | 198   ResourceDispatcherHost* const resource_dispatcher_host_; | 
|  | 199 | 
| 186   DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); | 200   DISALLOW_COPY_AND_ASSIGN(WorkerProcessHost); | 
| 187 }; | 201 }; | 
| 188 | 202 | 
| 189 #endif  // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 203 #endif  // CONTENT_BROWSER_WORKER_HOST_WORKER_PROCESS_HOST_H_ | 
| OLD | NEW | 
|---|