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> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "content/browser/service_worker/embedded_worker_status.h" | 23 #include "content/browser/service_worker/embedded_worker_status.h" |
24 #include "content/browser/service_worker/service_worker_metrics.h" | 24 #include "content/browser/service_worker/service_worker_metrics.h" |
25 #include "content/common/content_export.h" | 25 #include "content/common/content_export.h" |
26 #include "content/common/service_worker/embedded_worker.mojom.h" | |
27 #include "content/common/service_worker/service_worker_status_code.h" | 26 #include "content/common/service_worker/service_worker_status_code.h" |
28 #include "content/public/common/console_message_level.h" | 27 #include "content/public/common/console_message_level.h" |
29 #include "url/gurl.h" | 28 #include "url/gurl.h" |
30 | 29 |
31 // Windows headers will redefine SendMessage. | 30 // Windows headers will redefine SendMessage. |
32 #ifdef SendMessage | 31 #ifdef SendMessage |
33 #undef SendMessage | 32 #undef SendMessage |
34 #endif | 33 #endif |
35 | 34 |
| 35 struct EmbeddedWorkerMsg_StartWorker_Params; |
| 36 |
36 namespace IPC { | 37 namespace IPC { |
37 class Message; | 38 class Message; |
38 } | 39 } |
39 | 40 |
40 namespace shell { | 41 namespace shell { |
41 class InterfaceProvider; | 42 class InterfaceProvider; |
42 class InterfaceRegistry; | 43 class InterfaceRegistry; |
43 } | 44 } |
44 | 45 |
45 namespace content { | 46 namespace content { |
46 | 47 |
47 class EmbeddedWorkerRegistry; | 48 class EmbeddedWorkerRegistry; |
48 struct EmbeddedWorkerStartParams; | |
49 class MessagePortMessageFilter; | 49 class MessagePortMessageFilter; |
50 class ServiceWorkerContextCore; | 50 class ServiceWorkerContextCore; |
51 | 51 |
52 // This gives an interface to control one EmbeddedWorker instance, which | 52 // This gives an interface to control one EmbeddedWorker instance, which |
53 // may be 'in-waiting' or running in one of the child processes added by | 53 // may be 'in-waiting' or running in one of the child processes added by |
54 // AddProcessReference(). | 54 // AddProcessReference(). |
55 class CONTENT_EXPORT EmbeddedWorkerInstance { | 55 class CONTENT_EXPORT EmbeddedWorkerInstance { |
56 public: | 56 public: |
57 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; | 57 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback; |
58 | 58 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); | 104 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); |
105 }; | 105 }; |
106 | 106 |
107 ~EmbeddedWorkerInstance(); | 107 ~EmbeddedWorkerInstance(); |
108 | 108 |
109 // Starts the worker. It is invalid to call this when the worker is not in | 109 // Starts the worker. It is invalid to call this when the worker is not in |
110 // STOPPED status. |callback| is invoked after the worker script has been | 110 // STOPPED status. |callback| is invoked after the worker script has been |
111 // started and evaluated, or when an error occurs. | 111 // started and evaluated, or when an error occurs. |
112 // |params| should be populated with service worker version info needed | 112 // |params| should be populated with service worker version info needed |
113 // to start the worker. | 113 // to start the worker. |
114 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, | 114 void Start(std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, |
115 const StatusCallback& callback); | 115 const StatusCallback& callback); |
116 | 116 |
117 // Stops the worker. It is invalid to call this when the worker is | 117 // Stops the worker. It is invalid to call this when the worker is |
118 // not in STARTING or RUNNING status. | 118 // not in STARTING or RUNNING status. |
119 // This returns false if stopping a worker fails immediately, e.g. when | 119 // This returns false if stopping a worker fails immediately, e.g. when |
120 // IPC couldn't be sent to the worker. | 120 // IPC couldn't be sent to the worker. |
121 ServiceWorkerStatusCode Stop(); | 121 ServiceWorkerStatusCode Stop(); |
122 | 122 |
123 // 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 |
124 // 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // Called back from StartTask after a process is allocated on the UI thread. | 216 // Called back from StartTask after a process is allocated on the UI thread. |
217 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, | 217 void OnProcessAllocated(std::unique_ptr<WorkerProcessHandle> handle, |
218 ServiceWorkerMetrics::StartSituation start_situation); | 218 ServiceWorkerMetrics::StartSituation start_situation); |
219 | 219 |
220 // Called back from StartTask after the worker is registered to | 220 // Called back from StartTask after the worker is registered to |
221 // WorkerDevToolsManager. | 221 // WorkerDevToolsManager. |
222 void OnRegisteredToDevToolsManager(bool is_new_process, | 222 void OnRegisteredToDevToolsManager(bool is_new_process, |
223 int worker_devtools_agent_route_id, | 223 int worker_devtools_agent_route_id, |
224 bool wait_for_debugger); | 224 bool wait_for_debugger); |
225 | 225 |
226 // Sends StartWorker message via Mojo. | |
227 void SendMojoStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params); | |
228 | |
229 // Called back from StartTask after a start worker message is sent. | 226 // Called back from StartTask after a start worker message is sent. |
230 void OnStartWorkerMessageSent(); | 227 void OnStartWorkerMessageSent(); |
231 | 228 |
232 // Called back from Registry when the worker instance has ack'ed that | 229 // Called back from Registry when the worker instance has ack'ed that |
233 // it is ready for inspection. | 230 // it is ready for inspection. |
234 void OnReadyForInspection(); | 231 void OnReadyForInspection(); |
235 | 232 |
236 // Called back from Registry when the worker instance has ack'ed that | 233 // Called back from Registry when the worker instance has ack'ed that |
237 // it finished loading the script. | 234 // it finished loading the script. |
238 void OnScriptLoaded(); | 235 void OnScriptLoaded(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 298 |
302 // Unique within an EmbeddedWorkerRegistry. | 299 // Unique within an EmbeddedWorkerRegistry. |
303 const int embedded_worker_id_; | 300 const int embedded_worker_id_; |
304 | 301 |
305 EmbeddedWorkerStatus status_; | 302 EmbeddedWorkerStatus status_; |
306 StartingPhase starting_phase_; | 303 StartingPhase starting_phase_; |
307 | 304 |
308 // Current running information. | 305 // Current running information. |
309 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; | 306 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; |
310 int thread_id_; | 307 int thread_id_; |
311 | |
312 // These are connected to the renderer process after OnThreadStarted. | |
313 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; | 308 std::unique_ptr<shell::InterfaceRegistry> interface_registry_; |
314 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; | 309 std::unique_ptr<shell::InterfaceProvider> remote_interfaces_; |
315 // |client_| is used to send messages to the renderer process. | |
316 mojom::EmbeddedWorkerInstanceClientPtr client_; | |
317 | 310 |
318 // Whether devtools is attached or not. | 311 // Whether devtools is attached or not. |
319 bool devtools_attached_; | 312 bool devtools_attached_; |
320 | 313 |
321 // True if the script load request accessed the network. If the script was | 314 // True if the script load request accessed the network. If the script was |
322 // served from HTTPCache or ServiceWorkerDatabase this value is false. | 315 // served from HTTPCache or ServiceWorkerDatabase this value is false. |
323 bool network_accessed_for_script_; | 316 bool network_accessed_for_script_; |
324 | 317 |
325 ListenerList listener_list_; | 318 ListenerList listener_list_; |
326 std::unique_ptr<DevToolsProxy> devtools_proxy_; | 319 std::unique_ptr<DevToolsProxy> devtools_proxy_; |
327 | 320 |
328 std::unique_ptr<StartTask> inflight_start_task_; | 321 std::unique_ptr<StartTask> inflight_start_task_; |
329 | 322 |
330 // This is valid only after a process is allocated for the worker. | 323 // This is valid only after a process is allocated for the worker. |
331 ServiceWorkerMetrics::StartSituation start_situation_ = | 324 ServiceWorkerMetrics::StartSituation start_situation_ = |
332 ServiceWorkerMetrics::StartSituation::UNKNOWN; | 325 ServiceWorkerMetrics::StartSituation::UNKNOWN; |
333 | 326 |
334 // Used for UMA. The start time of the current start sequence step. | 327 // Used for UMA. The start time of the current start sequence step. |
335 base::TimeTicks step_time_; | 328 base::TimeTicks step_time_; |
336 | 329 |
337 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 330 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
338 | 331 |
339 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 332 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
340 }; | 333 }; |
341 | 334 |
342 } // namespace content | 335 } // namespace content |
343 | 336 |
344 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 337 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
OLD | NEW |