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

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

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

Powered by Google App Engine
This is Rietveld 408576698