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_INSTANCE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 25 matching lines...) Expand all Loading... | |
36 | 36 |
37 namespace IPC { | 37 namespace IPC { |
38 class Message; | 38 class Message; |
39 } | 39 } |
40 | 40 |
41 namespace content { | 41 namespace content { |
42 | 42 |
43 class EmbeddedWorkerRegistry; | 43 class EmbeddedWorkerRegistry; |
44 struct EmbeddedWorkerStartParams; | 44 struct EmbeddedWorkerStartParams; |
45 class ServiceWorkerContextCore; | 45 class ServiceWorkerContextCore; |
46 class ServiceWorkerProviderHost; | |
46 | 47 |
47 // This gives an interface to control one EmbeddedWorker instance, which | 48 // This gives an interface to control one EmbeddedWorker instance, which |
48 // may be 'in-waiting' or running in one of the child processes added by | 49 // may be 'in-waiting' or running in one of the child processes added by |
49 // AddProcessReference(). | 50 // AddProcessReference(). |
50 class CONTENT_EXPORT EmbeddedWorkerInstance | 51 class CONTENT_EXPORT EmbeddedWorkerInstance |
51 : NON_EXPORTED_BASE(public mojom::EmbeddedWorkerInstanceHost) { | 52 : NON_EXPORTED_BASE(public mojom::EmbeddedWorkerInstanceHost) { |
52 public: | 53 public: |
53 class DevToolsProxy; | 54 class DevToolsProxy; |
54 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 55 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
55 | 56 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 // Returns false if the message is not handled by this listener. | 102 // Returns false if the message is not handled by this listener. |
102 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); | 103 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); |
103 }; | 104 }; |
104 | 105 |
105 ~EmbeddedWorkerInstance() override; | 106 ~EmbeddedWorkerInstance() override; |
106 | 107 |
107 // Starts the worker. It is invalid to call this when the worker is not in | 108 // Starts the worker. It is invalid to call this when the worker is not in |
108 // STOPPED status. |callback| is invoked after the worker script has been | 109 // STOPPED status. |callback| is invoked after the worker script has been |
109 // started and evaluated, or when an error occurs. | 110 // started and evaluated, or when an error occurs. |
110 // |params| should be populated with service worker version info needed | 111 // |params| should be populated with service worker version info needed |
111 // to start the worker. | 112 // to start the worker. |
kinuko
2017/06/14 08:37:40
Please document |provider_host|.
shimazu
2017/06/16 04:18:43
Done.
| |
112 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, | 113 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, |
114 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | |
113 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, | 115 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, |
114 const StatusCallback& callback); | 116 const StatusCallback& callback); |
115 | 117 |
116 // Stops the worker. It is invalid to call this when the worker is | 118 // Stops the worker. It is invalid to call this when the worker is |
117 // not in STARTING or RUNNING status. | 119 // not in STARTING or RUNNING status. |
118 // This returns false when StopWorker IPC couldn't be sent to the worker. | 120 // This returns false when StopWorker IPC couldn't be sent to the worker. |
119 bool Stop(); | 121 bool Stop(); |
120 | 122 |
121 // Stops the worker if the worker is not being debugged (i.e. devtools is | 123 // Stops the worker if the worker is not being debugged (i.e. devtools is |
122 // not attached). This method is called by a stop-worker timer to kill | 124 // not attached). This method is called by a stop-worker timer to kill |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 | 223 |
222 // Called back from StartTask after a start worker message is sent. | 224 // Called back from StartTask after a start worker message is sent. |
223 void OnStartWorkerMessageSent(); | 225 void OnStartWorkerMessageSent(); |
224 | 226 |
225 // Implements mojom::EmbeddedWorkerInstanceHost. | 227 // Implements mojom::EmbeddedWorkerInstanceHost. |
226 // These functions all run on the IO thread. | 228 // These functions all run on the IO thread. |
227 void OnReadyForInspection() override; | 229 void OnReadyForInspection() override; |
228 void OnScriptLoaded() override; | 230 void OnScriptLoaded() override; |
229 // Notifies the corresponding provider host that the thread has started and is | 231 // Notifies the corresponding provider host that the thread has started and is |
230 // ready to receive messages. | 232 // ready to receive messages. |
231 void OnThreadStarted(int thread_id, int provider_id) override; | 233 void OnThreadStarted(int thread_id) override; |
232 void OnScriptLoadFailed() override; | 234 void OnScriptLoadFailed() override; |
233 // Fires the callback passed to Start(). | 235 // Fires the callback passed to Start(). |
234 void OnScriptEvaluated(bool success) override; | 236 void OnScriptEvaluated(bool success) override; |
235 // Changes the internal worker status from STARTING to RUNNING. | 237 // Changes the internal worker status from STARTING to RUNNING. |
236 void OnStarted() override; | 238 void OnStarted() override; |
237 // Resets the embedded worker instance to the initial state. This will change | 239 // Resets the embedded worker instance to the initial state. This will change |
238 // the internal status from STARTING or RUNNING to STOPPED. | 240 // the internal status from STARTING or RUNNING to STOPPED. |
239 void OnStopped() override; | 241 void OnStopped() override; |
240 void OnReportException(const base::string16& error_message, | 242 void OnReportException(const base::string16& error_message, |
241 int line_number, | 243 int line_number, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 const int embedded_worker_id_; | 278 const int embedded_worker_id_; |
277 | 279 |
278 EmbeddedWorkerStatus status_; | 280 EmbeddedWorkerStatus status_; |
279 StartingPhase starting_phase_; | 281 StartingPhase starting_phase_; |
280 int restart_count_; | 282 int restart_count_; |
281 | 283 |
282 // Current running information. | 284 // Current running information. |
283 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; | 285 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; |
284 int thread_id_; | 286 int thread_id_; |
285 | 287 |
286 // |client_| is used to send messages to the renderer process. | 288 // |client_| is used to send messages to the renderer process. The browser |
289 // process should not disconnect the pipe because other associated interfaces | |
290 // may be using it. The renderer process will disconnect the pipe when | |
291 // appropriate. | |
287 mojom::EmbeddedWorkerInstanceClientPtr client_; | 292 mojom::EmbeddedWorkerInstanceClientPtr client_; |
288 | 293 |
289 // Binding for EmbeddedWorkerInstanceHost, runs on IO thread. | 294 // Binding for EmbeddedWorkerInstanceHost, runs on IO thread. |
290 mojo::AssociatedBinding<EmbeddedWorkerInstanceHost> instance_host_binding_; | 295 mojo::AssociatedBinding<EmbeddedWorkerInstanceHost> instance_host_binding_; |
291 | 296 |
292 // TODO(shimazu): Remove this after EmbeddedWorkerStartParams is changed to | 297 // TODO(shimazu): Remove this after EmbeddedWorkerStartParams is changed to |
293 // a mojo struct. | 298 // a mojo struct. |
294 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; | 299 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; |
295 | 300 |
falken
2017/06/14 08:10:34
// The provider host that is hosting this running
shimazu
2017/06/16 04:18:43
Done.
| |
301 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | |
302 | |
296 // Whether devtools is attached or not. | 303 // Whether devtools is attached or not. |
297 bool devtools_attached_; | 304 bool devtools_attached_; |
298 | 305 |
299 // True if the script load request accessed the network. If the script was | 306 // True if the script load request accessed the network. If the script was |
300 // served from HTTPCache or ServiceWorkerDatabase this value is false. | 307 // served from HTTPCache or ServiceWorkerDatabase this value is false. |
301 bool network_accessed_for_script_; | 308 bool network_accessed_for_script_; |
302 | 309 |
303 ListenerList listener_list_; | 310 ListenerList listener_list_; |
304 std::unique_ptr<DevToolsProxy> devtools_proxy_; | 311 std::unique_ptr<DevToolsProxy> devtools_proxy_; |
305 | 312 |
306 std::unique_ptr<StartTask> inflight_start_task_; | 313 std::unique_ptr<StartTask> inflight_start_task_; |
307 | 314 |
308 // This is valid only after a process is allocated for the worker. | 315 // This is valid only after a process is allocated for the worker. |
309 ServiceWorkerMetrics::StartSituation start_situation_ = | 316 ServiceWorkerMetrics::StartSituation start_situation_ = |
310 ServiceWorkerMetrics::StartSituation::UNKNOWN; | 317 ServiceWorkerMetrics::StartSituation::UNKNOWN; |
311 | 318 |
312 // Used for UMA. The start time of the current start sequence step. | 319 // Used for UMA. The start time of the current start sequence step. |
313 base::TimeTicks step_time_; | 320 base::TimeTicks step_time_; |
314 | 321 |
315 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 322 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
316 | 323 |
317 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 324 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
318 }; | 325 }; |
319 | 326 |
320 } // namespace content | 327 } // namespace content |
321 | 328 |
322 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 329 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
OLD | NEW |