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

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

Issue 2936623002: Implement dumb URLLoader{Factory} for ServiceWorker script loading (for try)
Patch Set: . 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 25 matching lines...) Expand all
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
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. |provider_host| is a pre-created host for the
113 // controller.
112 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params, 114 void Start(std::unique_ptr<EmbeddedWorkerStartParams> params,
115 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
113 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, 116 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request,
114 const StatusCallback& callback); 117 const StatusCallback& callback);
115 118
116 // Stops the worker. It is invalid to call this when the worker is 119 // Stops the worker. It is invalid to call this when the worker is
117 // not in STARTING or RUNNING status. 120 // not in STARTING or RUNNING status.
118 // This returns false when StopWorker IPC couldn't be sent to the worker. 121 // This returns false when StopWorker IPC couldn't be sent to the worker.
119 bool Stop(); 122 bool Stop();
120 123
121 // Stops the worker if the worker is not being debugged (i.e. devtools is 124 // 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 125 // 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 224
222 // Called back from StartTask after a start worker message is sent. 225 // Called back from StartTask after a start worker message is sent.
223 void OnStartWorkerMessageSent(); 226 void OnStartWorkerMessageSent();
224 227
225 // Implements mojom::EmbeddedWorkerInstanceHost. 228 // Implements mojom::EmbeddedWorkerInstanceHost.
226 // These functions all run on the IO thread. 229 // These functions all run on the IO thread.
227 void OnReadyForInspection() override; 230 void OnReadyForInspection() override;
228 void OnScriptLoaded() override; 231 void OnScriptLoaded() override;
229 // Notifies the corresponding provider host that the thread has started and is 232 // Notifies the corresponding provider host that the thread has started and is
230 // ready to receive messages. 233 // ready to receive messages.
231 void OnThreadStarted(int thread_id, int provider_id) override; 234 void OnThreadStarted(int thread_id) override;
232 void OnScriptLoadFailed() override; 235 void OnScriptLoadFailed() override;
233 // Fires the callback passed to Start(). 236 // Fires the callback passed to Start().
234 void OnScriptEvaluated(bool success) override; 237 void OnScriptEvaluated(bool success) override;
235 // Changes the internal worker status from STARTING to RUNNING. 238 // Changes the internal worker status from STARTING to RUNNING.
236 void OnStarted() override; 239 void OnStarted() override;
237 // Resets the embedded worker instance to the initial state. This will change 240 // Resets the embedded worker instance to the initial state. This will change
238 // the internal status from STARTING or RUNNING to STOPPED. 241 // the internal status from STARTING or RUNNING to STOPPED.
239 void OnStopped() override; 242 void OnStopped() override;
240 void OnReportException(const base::string16& error_message, 243 void OnReportException(const base::string16& error_message,
241 int line_number, 244 int line_number,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 const int embedded_worker_id_; 279 const int embedded_worker_id_;
277 280
278 EmbeddedWorkerStatus status_; 281 EmbeddedWorkerStatus status_;
279 StartingPhase starting_phase_; 282 StartingPhase starting_phase_;
280 int restart_count_; 283 int restart_count_;
281 284
282 // Current running information. 285 // Current running information.
283 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_; 286 std::unique_ptr<EmbeddedWorkerInstance::WorkerProcessHandle> process_handle_;
284 int thread_id_; 287 int thread_id_;
285 288
286 // |client_| is used to send messages to the renderer process. 289 // |client_| is used to send messages to the renderer process. The browser
290 // process should not disconnect the pipe because other associated interfaces
291 // may be using it. The renderer process will disconnect the pipe when
292 // appropriate.
287 mojom::EmbeddedWorkerInstanceClientPtr client_; 293 mojom::EmbeddedWorkerInstanceClientPtr client_;
288 294
289 // Binding for EmbeddedWorkerInstanceHost, runs on IO thread. 295 // Binding for EmbeddedWorkerInstanceHost, runs on IO thread.
290 mojo::AssociatedBinding<EmbeddedWorkerInstanceHost> instance_host_binding_; 296 mojo::AssociatedBinding<EmbeddedWorkerInstanceHost> instance_host_binding_;
291 297
292 // TODO(shimazu): Remove this after EmbeddedWorkerStartParams is changed to 298 // TODO(shimazu): Remove this after EmbeddedWorkerStartParams is changed to
293 // a mojo struct. 299 // a mojo struct.
294 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; 300 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_;
295 301
302 // The provider host that is hosting this running worker.
303 base::WeakPtr<ServiceWorkerProviderHost> provider_host_;
304
296 // Whether devtools is attached or not. 305 // Whether devtools is attached or not.
297 bool devtools_attached_; 306 bool devtools_attached_;
298 307
299 // True if the script load request accessed the network. If the script was 308 // True if the script load request accessed the network. If the script was
300 // served from HTTPCache or ServiceWorkerDatabase this value is false. 309 // served from HTTPCache or ServiceWorkerDatabase this value is false.
301 bool network_accessed_for_script_; 310 bool network_accessed_for_script_;
302 311
303 ListenerList listener_list_; 312 ListenerList listener_list_;
304 std::unique_ptr<DevToolsProxy> devtools_proxy_; 313 std::unique_ptr<DevToolsProxy> devtools_proxy_;
305 314
306 std::unique_ptr<StartTask> inflight_start_task_; 315 std::unique_ptr<StartTask> inflight_start_task_;
307 316
308 // This is valid only after a process is allocated for the worker. 317 // This is valid only after a process is allocated for the worker.
309 ServiceWorkerMetrics::StartSituation start_situation_ = 318 ServiceWorkerMetrics::StartSituation start_situation_ =
310 ServiceWorkerMetrics::StartSituation::UNKNOWN; 319 ServiceWorkerMetrics::StartSituation::UNKNOWN;
311 320
312 // Used for UMA. The start time of the current start sequence step. 321 // Used for UMA. The start time of the current start sequence step.
313 base::TimeTicks step_time_; 322 base::TimeTicks step_time_;
314 323
315 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_; 324 base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_;
316 325
317 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); 326 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
318 }; 327 };
319 328
320 } // namespace content 329 } // namespace content
321 330
322 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_ 331 #endif // CONTENT_BROWSER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698