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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 SCRIPT_EVALUATED, | 64 SCRIPT_EVALUATED, |
65 THREAD_STARTED, // Happens after SCRIPT_LOADED and before SCRIPT_EVALUATED | 65 THREAD_STARTED, // Happens after SCRIPT_LOADED and before SCRIPT_EVALUATED |
66 // Script read happens after SENT_START_WORKER and before SCRIPT_LOADED | 66 // Script read happens after SENT_START_WORKER and before SCRIPT_LOADED |
67 // (installed scripts only) | 67 // (installed scripts only) |
68 SCRIPT_READ_STARTED, | 68 SCRIPT_READ_STARTED, |
69 SCRIPT_READ_FINISHED, | 69 SCRIPT_READ_FINISHED, |
70 // Add new values here. | 70 // Add new values here. |
71 STARTING_PHASE_MAX_VALUE, | 71 STARTING_PHASE_MAX_VALUE, |
72 }; | 72 }; |
73 | 73 |
74 using ProviderInfoGetter = | |
75 base::OnceCallback<mojom::ServiceWorkerProviderInfoForStartWorkerPtr( | |
76 int /* process_id */)>; | |
77 | |
78 class Listener { | 74 class Listener { |
79 public: | 75 public: |
80 virtual ~Listener() {} | 76 virtual ~Listener() {} |
81 | 77 |
82 virtual void OnStarting() {} | 78 virtual void OnStarting() {} |
83 virtual void OnProcessAllocated() {} | 79 virtual void OnProcessAllocated() {} |
84 virtual void OnRegisteredToDevToolsManager() {} | 80 virtual void OnRegisteredToDevToolsManager() {} |
85 virtual void OnStartWorkerMessageSent() {} | 81 virtual void OnStartWorkerMessageSent() {} |
86 virtual void OnThreadStarted() {} | 82 virtual void OnThreadStarted() {} |
87 virtual void OnStarted() {} | 83 virtual void OnStarted() {} |
(...skipping 17 matching lines...) Expand all Loading... |
105 // Returns false if the message is not handled by this listener. | 101 // Returns false if the message is not handled by this listener. |
106 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); | 102 CONTENT_EXPORT virtual bool OnMessageReceived(const IPC::Message& message); |
107 }; | 103 }; |
108 | 104 |
109 ~EmbeddedWorkerInstance() override; | 105 ~EmbeddedWorkerInstance() override; |
110 | 106 |
111 // Starts the worker. It is invalid to call this when the worker is not in | 107 // Starts the worker. It is invalid to call this when the worker is not in |
112 // STOPPED status. |callback| is invoked after the worker script has been | 108 // STOPPED status. |callback| is invoked after the worker script has been |
113 // started and evaluated, or when an error occurs. | 109 // started and evaluated, or when an error occurs. |
114 // |params| should be populated with service worker version info needed | 110 // |params| should be populated with service worker version info needed |
115 // to start the worker. |provider_info_getter| is called when this instance | 111 // to start the worker. |
116 // allocates a process and is ready to send a StartWorker message. | |
117 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, | 112 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, |
118 ProviderInfoGetter provider_info_getter, | |
119 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, | 113 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, |
120 const StatusCallback& callback); | 114 const StatusCallback& callback); |
121 | 115 |
122 // Stops the worker. It is invalid to call this when the worker is | 116 // Stops the worker. It is invalid to call this when the worker is |
123 // not in STARTING or RUNNING status. | 117 // not in STARTING or RUNNING status. |
124 // This returns false when StopWorker IPC couldn't be sent to the worker. | 118 // This returns false when StopWorker IPC couldn't be sent to the worker. |
125 bool Stop(); | 119 bool Stop(); |
126 | 120 |
127 // Stops the worker if the worker is not being debugged (i.e. devtools is | 121 // Stops the worker if the worker is not being debugged (i.e. devtools is |
128 // not attached). This method is called by a stop-worker timer to kill | 122 // 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... |
227 | 221 |
228 // Called back from StartTask after a start worker message is sent. | 222 // Called back from StartTask after a start worker message is sent. |
229 void OnStartWorkerMessageSent(); | 223 void OnStartWorkerMessageSent(); |
230 | 224 |
231 // Implements mojom::EmbeddedWorkerInstanceHost. | 225 // Implements mojom::EmbeddedWorkerInstanceHost. |
232 // These functions all run on the IO thread. | 226 // These functions all run on the IO thread. |
233 void OnReadyForInspection() override; | 227 void OnReadyForInspection() override; |
234 void OnScriptLoaded() override; | 228 void OnScriptLoaded() override; |
235 // Notifies the corresponding provider host that the thread has started and is | 229 // Notifies the corresponding provider host that the thread has started and is |
236 // ready to receive messages. | 230 // ready to receive messages. |
237 void OnThreadStarted(int thread_id) override; | 231 void OnThreadStarted(int thread_id, int provider_id) override; |
238 void OnScriptLoadFailed() override; | 232 void OnScriptLoadFailed() override; |
239 // Fires the callback passed to Start(). | 233 // Fires the callback passed to Start(). |
240 void OnScriptEvaluated(bool success) override; | 234 void OnScriptEvaluated(bool success) override; |
241 // Changes the internal worker status from STARTING to RUNNING. | 235 // Changes the internal worker status from STARTING to RUNNING. |
242 void OnStarted() override; | 236 void OnStarted() override; |
243 // Resets the embedded worker instance to the initial state. This will change | 237 // Resets the embedded worker instance to the initial state. This will change |
244 // the internal status from STARTING or RUNNING to STOPPED. | 238 // the internal status from STARTING or RUNNING to STOPPED. |
245 void OnStopped() override; | 239 void OnStopped() override; |
246 void OnReportException(const base::string16& error_message, | 240 void OnReportException(const base::string16& error_message, |
247 int line_number, | 241 int line_number, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 const int embedded_worker_id_; | 276 const int embedded_worker_id_; |
283 | 277 |
284 EmbeddedWorkerStatus status_; | 278 EmbeddedWorkerStatus status_; |
285 StartingPhase starting_phase_; | 279 StartingPhase starting_phase_; |
286 int restart_count_; | 280 int restart_count_; |
287 | 281 |
288 // Current running information. | 282 // Current running information. |
289 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; | 283 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; |
290 int thread_id_; | 284 int thread_id_; |
291 | 285 |
292 // |client_| is used to send messages to the renderer process. The browser | 286 // |client_| is used to send messages to the renderer process. |
293 // process should not disconnect the pipe because other associated interfaces | |
294 // may be using it. The renderer process will disconnect the pipe when | |
295 // appropriate. | |
296 mojom::EmbeddedWorkerInstanceClientPtr client_; | 287 mojom::EmbeddedWorkerInstanceClientPtr client_; |
297 | 288 |
298 // Binding for EmbeddedWorkerInstanceHost, runs on IO thread. | 289 // Binding for EmbeddedWorkerInstanceHost, runs on IO thread. |
299 mojo::AssociatedBinding<EmbeddedWorkerInstanceHost> instance_host_binding_; | 290 mojo::AssociatedBinding<EmbeddedWorkerInstanceHost> instance_host_binding_; |
300 | 291 |
301 // TODO(shimazu): Remove this after EmbeddedWorkerStartParams is changed to | 292 // TODO(shimazu): Remove this after EmbeddedWorkerStartParams is changed to |
302 // a mojo struct. | 293 // a mojo struct. |
303 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; | 294 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; |
304 | 295 |
305 // This is set at Start and used on SendStartWorker. | |
306 ProviderInfoGetter provider_info_getter_; | |
307 | |
308 // Whether devtools is attached or not. | 296 // Whether devtools is attached or not. |
309 bool devtools_attached_; | 297 bool devtools_attached_; |
310 | 298 |
311 // True if the script load request accessed the network. If the script was | 299 // True if the script load request accessed the network. If the script was |
312 // served from HTTPCache or ServiceWorkerDatabase this value is false. | 300 // served from HTTPCache or ServiceWorkerDatabase this value is false. |
313 bool network_accessed_for_script_; | 301 bool network_accessed_for_script_; |
314 | 302 |
315 ListenerList listener_list_; | 303 ListenerList listener_list_; |
316 std::unique_ptr<DevToolsProxy> devtools_proxy_; | 304 std::unique_ptr<DevToolsProxy> devtools_proxy_; |
317 | 305 |
318 std::unique_ptr<StartTask> inflight_start_task_; | 306 std::unique_ptr<StartTask> inflight_start_task_; |
319 | 307 |
320 // This is valid only after a process is allocated for the worker. | 308 // This is valid only after a process is allocated for the worker. |
321 ServiceWorkerMetrics::StartSituation start_situation_ = | 309 ServiceWorkerMetrics::StartSituation start_situation_ = |
322 ServiceWorkerMetrics::StartSituation::UNKNOWN; | 310 ServiceWorkerMetrics::StartSituation::UNKNOWN; |
323 | 311 |
324 // Used for UMA. The start time of the current start sequence step. | 312 // Used for UMA. The start time of the current start sequence step. |
325 base::TimeTicks step_time_; | 313 base::TimeTicks step_time_; |
326 | 314 |
327 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; | 315 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; |
328 | 316 |
329 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); | 317 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); |
330 }; | 318 }; |
331 | 319 |
332 } // namespace content | 320 } // namespace content |
333 | 321 |
334 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ | 322 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ |
OLD | NEW |