| 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/weak_ptr.h" |
| 13 |
| 14 class GURL; |
| 15 |
| 16 namespace IPC { |
| 17 class Message; |
| 18 class Sender; |
| 19 } |
| 20 |
| 21 namespace content { |
| 22 |
| 23 class EmbeddedWorkerInstance; |
| 24 class ServiceWorkerContextCore; |
| 25 |
| 26 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, |
| 27 // which sends/receives messages to/from each EmbeddedWorker in child process. |
| 28 // |
| 29 // Hangs off ServiceWorkerContextCore (its reference is also held by each |
| 30 // EmbeddedWorkerInstance). Operated only on IO thread. |
| 31 class EmbeddedWorkerRegistry |
| 32 : public base::RefCounted<EmbeddedWorkerRegistry> { |
| 33 public: |
| 34 explicit EmbeddedWorkerRegistry( |
| 35 base::WeakPtr<ServiceWorkerContextCore> context); |
| 36 |
| 37 // Creates and removes a new worker instance entry for bookkeeping. |
| 38 // This doesn't actually start or stop the worker. |
| 39 scoped_ptr<EmbeddedWorkerInstance> CreateWorker(); |
| 40 void RemoveWorker(int embedded_worker_id); |
| 41 |
| 42 // Called from EmbeddedWorkerInstance, relayed to the child process. |
| 43 bool StartWorker(int process_id, |
| 44 int embedded_worker_id, |
| 45 int64 service_worker_version_id, |
| 46 const GURL& script_url); |
| 47 bool StopWorker(int process_id, |
| 48 int embedded_worker_id); |
| 49 |
| 50 // Keeps a map from process_id to sender information. |
| 51 void AddChildProcessSender(int process_id, IPC::Sender* sender); |
| 52 void RemoveChildProcessSender(int process_id); |
| 53 |
| 54 private: |
| 55 friend class RefCounted<EmbeddedWorkerRegistry>; |
| 56 |
| 57 ~EmbeddedWorkerRegistry(); |
| 58 bool Send(int process_id, IPC::Message* message); |
| 59 |
| 60 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; |
| 61 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; |
| 62 |
| 63 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 64 |
| 65 WorkerInstanceMap worker_map_; |
| 66 ProcessToSenderMap process_sender_map_; |
| 67 |
| 68 int next_embedded_worker_id_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); |
| 71 }; |
| 72 |
| 73 } // namespace content |
| 74 |
| 75 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| OLD | NEW |