| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" |
| 14 #include "content/common/content_export.h" |
| 15 |
| 16 class GURL; |
| 17 |
| 18 namespace IPC { |
| 19 class Message; |
| 20 class Sender; |
| 21 } |
| 22 |
| 23 namespace content { |
| 24 |
| 25 class EmbeddedWorkerInstance; |
| 26 class ServiceWorkerContextCore; |
| 27 |
| 28 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, |
| 29 // which sends/receives messages to/from each EmbeddedWorker in child process. |
| 30 // |
| 31 // Hangs off ServiceWorkerContextCore (its reference is also held by each |
| 32 // EmbeddedWorkerInstance). Operated only on IO thread. |
| 33 class CONTENT_EXPORT EmbeddedWorkerRegistry |
| 34 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { |
| 35 public: |
| 36 explicit EmbeddedWorkerRegistry( |
| 37 base::WeakPtr<ServiceWorkerContextCore> context); |
| 38 |
| 39 // Creates and removes a new worker instance entry for bookkeeping. |
| 40 // This doesn't actually start or stop the worker. |
| 41 scoped_ptr<EmbeddedWorkerInstance> CreateWorker(); |
| 42 void RemoveWorker(int embedded_worker_id); |
| 43 |
| 44 // Called from EmbeddedWorkerInstance, relayed to the child process. |
| 45 bool StartWorker(int process_id, |
| 46 int embedded_worker_id, |
| 47 int64 service_worker_version_id, |
| 48 const GURL& script_url); |
| 49 bool StopWorker(int process_id, |
| 50 int embedded_worker_id); |
| 51 |
| 52 // Keeps a map from process_id to sender information. |
| 53 void AddChildProcessSender(int process_id, IPC::Sender* sender); |
| 54 void RemoveChildProcessSender(int process_id); |
| 55 |
| 56 private: |
| 57 friend class base::RefCounted<EmbeddedWorkerRegistry>; |
| 58 |
| 59 ~EmbeddedWorkerRegistry(); |
| 60 bool Send(int process_id, IPC::Message* message); |
| 61 |
| 62 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; |
| 63 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; |
| 64 |
| 65 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 66 |
| 67 WorkerInstanceMap worker_map_; |
| 68 ProcessToSenderMap process_sender_map_; |
| 69 |
| 70 int next_embedded_worker_id_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); |
| 73 }; |
| 74 |
| 75 } // namespace content |
| 76 |
| 77 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| OLD | NEW |