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 #include <vector> | 10 #include <vector> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 explicit EmbeddedWorkerRegistry( | 43 explicit EmbeddedWorkerRegistry( |
44 base::WeakPtr<ServiceWorkerContextCore> context); | 44 base::WeakPtr<ServiceWorkerContextCore> context); |
45 | 45 |
46 bool OnMessageReceived(const IPC::Message& message); | 46 bool OnMessageReceived(const IPC::Message& message); |
47 | 47 |
48 // Creates and removes a new worker instance entry for bookkeeping. | 48 // Creates and removes a new worker instance entry for bookkeeping. |
49 // This doesn't actually start or stop the worker. | 49 // This doesn't actually start or stop the worker. |
50 scoped_ptr<EmbeddedWorkerInstance> CreateWorker(); | 50 scoped_ptr<EmbeddedWorkerInstance> CreateWorker(); |
51 | 51 |
52 // Called from EmbeddedWorkerInstance, relayed to the child process. | 52 // Called from EmbeddedWorkerInstance, relayed to the child process. |
53 void StartWorker(const std::vector<int>& process_ids, | 53 void SendStartWorker(scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, |
54 int embedded_worker_id, | 54 const StatusCallback& callback, |
55 int64 service_worker_version_id, | 55 int process_id); |
56 const GURL& scope, | |
57 const GURL& script_url, | |
58 const StatusCallback& callback); | |
59 ServiceWorkerStatusCode StopWorker(int process_id, | 56 ServiceWorkerStatusCode StopWorker(int process_id, |
60 int embedded_worker_id); | 57 int embedded_worker_id); |
61 | 58 |
62 // Stop all active workers, even if they're handling events. | 59 // Stop all active workers, even if they're handling events. |
63 void Shutdown(); | 60 void Shutdown(); |
64 | 61 |
65 // Called back from EmbeddedWorker in the child process, relayed via | 62 // Called back from EmbeddedWorker in the child process, relayed via |
66 // ServiceWorkerDispatcherHost. | 63 // ServiceWorkerDispatcherHost. |
67 void OnWorkerScriptLoaded(int process_id, int embedded_worker_id); | 64 void OnWorkerScriptLoaded(int process_id, int embedded_worker_id); |
68 void OnWorkerScriptLoadFailed(int process_id, int embedded_worker_id); | 65 void OnWorkerScriptLoadFailed(int process_id, int embedded_worker_id); |
(...skipping 20 matching lines...) Expand all Loading... |
89 | 86 |
90 private: | 87 private: |
91 friend class base::RefCounted<EmbeddedWorkerRegistry>; | 88 friend class base::RefCounted<EmbeddedWorkerRegistry>; |
92 friend class EmbeddedWorkerInstance; | 89 friend class EmbeddedWorkerInstance; |
93 | 90 |
94 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; | 91 typedef std::map<int, EmbeddedWorkerInstance*> WorkerInstanceMap; |
95 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; | 92 typedef std::map<int, IPC::Sender*> ProcessToSenderMap; |
96 | 93 |
97 ~EmbeddedWorkerRegistry(); | 94 ~EmbeddedWorkerRegistry(); |
98 | 95 |
99 void StartWorkerWithProcessId( | |
100 int embedded_worker_id, | |
101 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | |
102 const StatusCallback& callback, | |
103 ServiceWorkerStatusCode status, | |
104 int process_id); | |
105 | |
106 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); | 96 ServiceWorkerStatusCode Send(int process_id, IPC::Message* message); |
107 | 97 |
108 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. | 98 // RemoveWorker is called when EmbeddedWorkerInstance is destructed. |
109 // |process_id| could be invalid (i.e. -1) if it's not running. | 99 // |process_id| could be invalid (i.e. -1) if it's not running. |
110 void RemoveWorker(int process_id, int embedded_worker_id); | 100 void RemoveWorker(int process_id, int embedded_worker_id); |
111 | 101 |
112 base::WeakPtr<ServiceWorkerContextCore> context_; | 102 base::WeakPtr<ServiceWorkerContextCore> context_; |
113 | 103 |
114 WorkerInstanceMap worker_map_; | 104 WorkerInstanceMap worker_map_; |
115 ProcessToSenderMap process_sender_map_; | 105 ProcessToSenderMap process_sender_map_; |
116 | 106 |
117 // Map from process_id to embedded_worker_id. | 107 // Map from process_id to embedded_worker_id. |
118 // This map only contains running workers. | 108 // This map only contains running workers. |
119 std::map<int, std::set<int> > worker_process_map_; | 109 std::map<int, std::set<int> > worker_process_map_; |
120 | 110 |
121 int next_embedded_worker_id_; | 111 int next_embedded_worker_id_; |
122 | 112 |
123 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); | 113 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerRegistry); |
124 }; | 114 }; |
125 | 115 |
126 } // namespace content | 116 } // namespace content |
127 | 117 |
128 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ | 118 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_REGISTRY_H_ |
OLD | NEW |