| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/common/service_worker/service_worker_status_code.h" | 17 #include "content/common/service_worker/service_worker_status_code.h" |
| 18 | 18 |
| 19 class EmbeddedWorkerMsg_StartWorker; |
| 19 class GURL; | 20 class GURL; |
| 20 | 21 |
| 21 namespace IPC { | 22 namespace IPC { |
| 22 class Message; | 23 class Message; |
| 23 class Sender; | 24 class Sender; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 | 28 |
| 28 class EmbeddedWorkerInstance; | 29 class EmbeddedWorkerInstance; |
| 29 class ServiceWorkerContextCore; | 30 class ServiceWorkerContextCore; |
| 30 | 31 |
| 31 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, | 32 // Acts as a thin stub between MessageFilter and each EmbeddedWorkerInstance, |
| 32 // which sends/receives messages to/from each EmbeddedWorker in child process. | 33 // which sends/receives messages to/from each EmbeddedWorker in child process. |
| 33 // | 34 // |
| 34 // Hangs off ServiceWorkerContextCore (its reference is also held by each | 35 // Hangs off ServiceWorkerContextCore (its reference is also held by each |
| 35 // EmbeddedWorkerInstance). Operated only on IO thread. | 36 // EmbeddedWorkerInstance). Operated only on IO thread. |
| 36 class CONTENT_EXPORT EmbeddedWorkerRegistry | 37 class CONTENT_EXPORT EmbeddedWorkerRegistry |
| 37 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { | 38 : public NON_EXPORTED_BASE(base::RefCounted<EmbeddedWorkerRegistry>) { |
| 38 public: | 39 public: |
| 40 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
| 41 |
| 39 explicit EmbeddedWorkerRegistry( | 42 explicit EmbeddedWorkerRegistry( |
| 40 base::WeakPtr<ServiceWorkerContextCore> context); | 43 base::WeakPtr<ServiceWorkerContextCore> context); |
| 41 | 44 |
| 42 bool OnMessageReceived(const IPC::Message& message); | 45 bool OnMessageReceived(const IPC::Message& message); |
| 43 | 46 |
| 44 // Creates and removes a new worker instance entry for bookkeeping. | 47 // Creates and removes a new worker instance entry for bookkeeping. |
| 45 // This doesn't actually start or stop the worker. | 48 // This doesn't actually start or stop the worker. |
| 46 scoped_ptr<EmbeddedWorkerInstance> CreateWorker(); | 49 scoped_ptr<EmbeddedWorkerInstance> CreateWorker(); |
| 47 | 50 |
| 48 // Called from EmbeddedWorkerInstance, relayed to the child process. | 51 // Called from EmbeddedWorkerInstance, relayed to the child process. |
| 49 ServiceWorkerStatusCode StartWorker(int process_id, | 52 void StartWorker(const std::vector<int>& process_ids, |
| 50 int embedded_worker_id, | 53 int embedded_worker_id, |
| 51 int64 service_worker_version_id, | 54 int64 service_worker_version_id, |
| 52 const GURL& scope, | 55 const GURL& scope, |
| 53 const GURL& script_url); | 56 const GURL& script_url, |
| 57 const StatusCallback& callback); |
| 54 ServiceWorkerStatusCode StopWorker(int process_id, | 58 ServiceWorkerStatusCode StopWorker(int process_id, |
| 55 int embedded_worker_id); | 59 int embedded_worker_id); |
| 56 | 60 |
| 61 // Stop all active workers, even if they're handling events. |
| 62 void Shutdown(); |
| 63 |
| 57 // Called back from EmbeddedWorker in the child process, relayed via | 64 // Called back from EmbeddedWorker in the child process, relayed via |
| 58 // ServiceWorkerDispatcherHost. | 65 // ServiceWorkerDispatcherHost. |
| 59 void OnWorkerStarted(int process_id, int thread_id, int embedded_worker_id); | 66 void OnWorkerStarted(int process_id, int thread_id, int embedded_worker_id); |
| 60 void OnWorkerStopped(int process_id, int embedded_worker_id); | 67 void OnWorkerStopped(int process_id, int embedded_worker_id); |
| 61 void OnReportException(int embedded_worker_id, | 68 void OnReportException(int embedded_worker_id, |
| 62 const base::string16& error_message, | 69 const base::string16& error_message, |
| 63 int line_number, | 70 int line_number, |
| 64 int column_number, | 71 int column_number, |
| 65 const GURL& source_url); | 72 const GURL& source_url); |
| 66 void OnReportConsoleMessage(int embedded_worker_id, | 73 void OnReportConsoleMessage(int embedded_worker_id, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 78 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); | 85 EmbeddedWorkerInstance* GetWorker(int embedded_worker_id); |
| 79 | 86 |
| 80 private: | 87 private: |
| 81 friend class base::RefCounted<EmbeddedWorkerRegistry>; | 88 friend class base::RefCounted<EmbeddedWorkerRegistry>; |
| 82 friend class EmbeddedWorkerInstance; | 89 friend class EmbeddedWorkerInstance; |
| 83 | 90 |
| 84 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; | 91 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; |
| 85 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; | 92 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; |
| 86 | 93 |
| 87 ~EmbeddedWorkerRegistry(); | 94 ~EmbeddedWorkerRegistry(); |
| 95 |
| 96 void StartWorkerWithProcessId( |
| 97 int embedded_worker_id, |
| 98 scoped_ptr<EmbeddedWorkerMsg_StartWorker> message, |
| 99 const StatusCallback& callback, |
| 100 ServiceWorkerStatusCode status, |
| 101 int process_id); |
| 102 |
| 88 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); | 103 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); |
| 89 | 104 |
| 90 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. | 105 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. |
| 91 // |process_id| could be invalid (i.e. -1) if it's not running. | 106 // |process_id| could be invalid (i.e. -1) if it's not running. |
| 92 void RemoveWorker(int process_id, int embedded_worker_id); | 107 void RemoveWorker(int process_id, int embedded_worker_id); |
| 93 | 108 |
| 94 base::WeakPtr<ServiceWorkerContextCore> context_; | 109 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 95 | 110 |
| 96 WorkerInstanceMap worker_map_; | 111 WorkerInstanceMap worker_map_; |
| 97 ProcessToSenderMap process_sender_map_; | 112 ProcessToSenderMap process_sender_map_; |
| 98 | 113 |
| 99 // Map from process_id to embedded_worker_id. | 114 // Map from process_id to embedded_worker_id. |
| 100 // This map only contains running workers. | 115 // This map only contains running workers. |
| 101 std::map<int, std::set<int> > worker_process_map_; | 116 std::map<int, std::set<int> > worker_process_map_; |
| 102 | 117 |
| 103 int next_embedded_worker_id_; | 118 int next_embedded_worker_id_; |
| 104 | 119 |
| 105 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); | 120 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); |
| 106 }; | 121 }; |
| 107 | 122 |
| 108 } // namespace content | 123 } // namespace content |
| 109 | 124 |
| 110 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 125 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
| OLD | NEW |