Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.h

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

Powered by Google App Engine
This is Rietveld 408576698