Update broken references to image assets
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_version.h
bloba11e1dc6f8dec2a861fc941b940d65712373caf9
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
8 #include <map>
9 #include <queue>
10 #include <set>
11 #include <string>
12 #include <vector>
14 #include "base/basictypes.h"
15 #include "base/callback.h"
16 #include "base/gtest_prod_util.h"
17 #include "base/id_map.h"
18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/observer_list.h"
21 #include "base/timer/timer.h"
22 #include "content/browser/service_worker/embedded_worker_instance.h"
23 #include "content/browser/service_worker/service_worker_script_cache_map.h"
24 #include "content/common/background_sync_service.mojom.h"
25 #include "content/common/content_export.h"
26 #include "content/common/service_port_service.mojom.h"
27 #include "content/common/service_worker/service_worker_status_code.h"
28 #include "content/common/service_worker/service_worker_types.h"
29 #include "content/public/common/service_registry.h"
30 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h"
31 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerEventResult.h"
33 // Windows headers will redefine SendMessage.
34 #ifdef SendMessage
35 #undef SendMessage
36 #endif
38 class GURL;
40 namespace blink {
41 struct WebCircularGeofencingRegion;
44 namespace net {
45 class HttpResponseInfo;
48 namespace content {
50 class EmbeddedWorkerRegistry;
51 class ServiceWorkerContextCore;
52 class ServiceWorkerProviderHost;
53 class ServiceWorkerRegistration;
54 class ServiceWorkerURLRequestJob;
55 struct NavigatorConnectClient;
56 struct PlatformNotificationData;
57 struct ServiceWorkerClientInfo;
58 struct ServiceWorkerVersionInfo;
59 struct TransferredMessagePort;
61 // This class corresponds to a specific version of a ServiceWorker
62 // script for a given pattern. When a script is upgraded, there may be
63 // more than one ServiceWorkerVersion "running" at a time, but only
64 // one of them is activated. This class connects the actual script with a
65 // running worker.
66 class CONTENT_EXPORT ServiceWorkerVersion
67 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>),
68 public EmbeddedWorkerInstance::Listener {
69 public:
70 typedef base::Callback<void(ServiceWorkerStatusCode)> StatusCallback;
71 typedef base::Callback<void(ServiceWorkerStatusCode,
72 ServiceWorkerFetchEventResult,
73 const ServiceWorkerResponse&)> FetchCallback;
74 typedef base::Callback<void(ServiceWorkerStatusCode,
75 bool /* accept_connction */,
76 const base::string16& /* name */,
77 const base::string16& /* data */)>
78 ServicePortConnectCallback;
80 enum RunningStatus {
81 STOPPED = EmbeddedWorkerInstance::STOPPED,
82 STARTING = EmbeddedWorkerInstance::STARTING,
83 RUNNING = EmbeddedWorkerInstance::RUNNING,
84 STOPPING = EmbeddedWorkerInstance::STOPPING,
87 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED)
88 // should be persisted unlike running status.
89 enum Status {
90 NEW, // The version is just created.
91 INSTALLING, // Install event is dispatched and being handled.
92 INSTALLED, // Install event is finished and is ready to be activated.
93 ACTIVATING, // Activate event is dispatched and being handled.
94 ACTIVATED, // Activation is finished and can run as activated.
95 REDUNDANT, // The version is no longer running as activated, due to
96 // unregistration or replace.
99 class Listener {
100 public:
101 virtual void OnRunningStateChanged(ServiceWorkerVersion* version) {}
102 virtual void OnVersionStateChanged(ServiceWorkerVersion* version) {}
103 virtual void OnMainScriptHttpResponseInfoSet(
104 ServiceWorkerVersion* version) {}
105 virtual void OnErrorReported(ServiceWorkerVersion* version,
106 const base::string16& error_message,
107 int line_number,
108 int column_number,
109 const GURL& source_url) {}
110 virtual void OnReportConsoleMessage(ServiceWorkerVersion* version,
111 int source_identifier,
112 int message_level,
113 const base::string16& message,
114 int line_number,
115 const GURL& source_url) {}
116 virtual void OnControlleeAdded(ServiceWorkerVersion* version,
117 ServiceWorkerProviderHost* provider_host) {}
118 virtual void OnControlleeRemoved(ServiceWorkerVersion* version,
119 ServiceWorkerProviderHost* provider_host) {
121 // Fires when a version transitions from having a controllee to not.
122 virtual void OnNoControllees(ServiceWorkerVersion* version) {}
123 virtual void OnCachedMetadataUpdated(ServiceWorkerVersion* version) {}
125 protected:
126 virtual ~Listener() {}
129 ServiceWorkerVersion(
130 ServiceWorkerRegistration* registration,
131 const GURL& script_url,
132 int64 version_id,
133 base::WeakPtr<ServiceWorkerContextCore> context);
135 int64 version_id() const { return version_id_; }
136 int64 registration_id() const { return registration_id_; }
137 const GURL& script_url() const { return script_url_; }
138 const GURL& scope() const { return scope_; }
139 RunningStatus running_status() const {
140 return static_cast<RunningStatus>(embedded_worker_->status());
142 ServiceWorkerVersionInfo GetInfo();
143 Status status() const { return status_; }
145 // This sets the new status and also run status change callbacks
146 // if there're any (see RegisterStatusChangeCallback).
147 void SetStatus(Status status);
149 // Registers status change callback. (This is for one-off observation,
150 // the consumer needs to re-register if it wants to continue observing
151 // status changes)
152 void RegisterStatusChangeCallback(const base::Closure& callback);
154 // Starts an embedded worker for this version.
155 // This returns OK (success) if the worker is already running.
156 void StartWorker(const StatusCallback& callback);
158 // Stops an embedded worker for this version.
159 // This returns OK (success) if the worker is already stopped.
160 void StopWorker(const StatusCallback& callback);
162 // Schedules an update to be run 'soon'.
163 void ScheduleUpdate();
165 // If an update is scheduled but not yet started, this resets the timer
166 // delaying the start time by a 'small' amount.
167 void DeferScheduledUpdate();
169 // Starts an update now.
170 void StartUpdate();
172 // Sends a message event to the associated embedded worker.
173 void DispatchMessageEvent(
174 const base::string16& message,
175 const std::vector<TransferredMessagePort>& sent_message_ports,
176 const StatusCallback& callback);
178 // Sends install event to the associated embedded worker and asynchronously
179 // calls |callback| when it errors out or it gets a response from the worker
180 // to notify install completion.
182 // This must be called when the status() is NEW. Calling this changes
183 // the version's status to INSTALLING.
184 // Upon completion, the version's status will be changed to INSTALLED
185 // on success, or back to NEW on failure.
186 void DispatchInstallEvent(const StatusCallback& callback);
188 // Sends activate event to the associated embedded worker and asynchronously
189 // calls |callback| when it errors out or it gets a response from the worker
190 // to notify activation completion.
192 // This must be called when the status() is INSTALLED. Calling this changes
193 // the version's status to ACTIVATING.
194 // Upon completion, the version's status will be changed to ACTIVATED
195 // on success, or back to INSTALLED on failure.
196 void DispatchActivateEvent(const StatusCallback& callback);
198 // Sends fetch event to the associated embedded worker and calls
199 // |callback| with the response from the worker.
201 // This must be called when the status() is ACTIVATED. Calling this in other
202 // statuses will result in an error SERVICE_WORKER_ERROR_FAILED.
203 void DispatchFetchEvent(const ServiceWorkerFetchRequest& request,
204 const base::Closure& prepare_callback,
205 const FetchCallback& fetch_callback);
207 // Sends sync event to the associated embedded worker and asynchronously calls
208 // |callback| when it errors out or it gets a response from the worker to
209 // notify completion.
211 // This must be called when the status() is ACTIVATED.
212 void DispatchSyncEvent(SyncRegistrationPtr registration,
213 const StatusCallback& callback);
215 // Sends notificationclick event to the associated embedded worker and
216 // asynchronously calls |callback| when it errors out or it gets a response
217 // from the worker to notify completion.
219 // This must be called when the status() is ACTIVATED.
220 void DispatchNotificationClickEvent(
221 const StatusCallback& callback,
222 int64_t persistent_notification_id,
223 const PlatformNotificationData& notification_data,
224 int action_index);
226 // Sends push event to the associated embedded worker and asynchronously calls
227 // |callback| when it errors out or it gets a response from the worker to
228 // notify completion.
230 // This must be called when the status() is ACTIVATED.
231 void DispatchPushEvent(const StatusCallback& callback,
232 const std::string& data);
234 // Sends geofencing event to the associated embedded worker and asynchronously
235 // calls |callback| when it errors out or it gets a response from the worker
236 // to notify completion.
238 // This must be called when the status() is ACTIVATED.
239 void DispatchGeofencingEvent(
240 const StatusCallback& callback,
241 blink::WebGeofencingEventType event_type,
242 const std::string& region_id,
243 const blink::WebCircularGeofencingRegion& region);
245 // Sends a ServicePort connect event to the associated embedded worker and
246 // asynchronously calls |callback| with the response from the worker.
248 // This must be called when the status() is ACTIVATED.
249 void DispatchServicePortConnectEvent(
250 const ServicePortConnectCallback& callback,
251 const GURL& target_url,
252 const GURL& origin,
253 int port_id);
255 // Sends a cross origin message event to the associated embedded worker and
256 // asynchronously calls |callback| when the message was sent (or failed to
257 // sent).
258 // It is the responsibility of the code calling this method to make sure that
259 // any transferred message ports are put on hold while potentially a process
260 // for the service worker is spun up.
262 // This must be called when the status() is ACTIVATED.
263 void DispatchCrossOriginMessageEvent(
264 const NavigatorConnectClient& client,
265 const base::string16& message,
266 const std::vector<TransferredMessagePort>& sent_message_ports,
267 const StatusCallback& callback);
269 // Adds and removes |provider_host| as a controllee of this ServiceWorker.
270 // A potential controllee is a host having the version as its .installing
271 // or .waiting version.
272 void AddControllee(ServiceWorkerProviderHost* provider_host);
273 void RemoveControllee(ServiceWorkerProviderHost* provider_host);
275 // Returns if it has controllee.
276 bool HasControllee() const { return !controllee_map_.empty(); }
278 // Returns whether the service worker has active window clients under its
279 // control.
280 bool HasWindowClients();
282 // Adds and removes |request_job| as a dependent job not to stop the
283 // ServiceWorker while |request_job| is reading the stream of the fetch event
284 // response from the ServiceWorker.
285 void AddStreamingURLRequestJob(const ServiceWorkerURLRequestJob* request_job);
286 void RemoveStreamingURLRequestJob(
287 const ServiceWorkerURLRequestJob* request_job);
289 // Adds and removes Listeners.
290 void AddListener(Listener* listener);
291 void RemoveListener(Listener* listener);
293 ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; }
294 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); }
296 // Reports the error message to |listeners_|.
297 void ReportError(ServiceWorkerStatusCode status,
298 const std::string& status_message);
300 // Sets the status code to pass to StartWorker callbacks if start fails.
301 void SetStartWorkerStatusCode(ServiceWorkerStatusCode status);
303 // Sets this version's status to REDUNDANT and deletes its resources.
304 // The version must not have controllees.
305 void Doom();
306 bool is_redundant() const { return status_ == REDUNDANT; }
308 bool skip_waiting() const { return skip_waiting_; }
309 void set_skip_waiting(bool skip_waiting) { skip_waiting_ = skip_waiting; }
311 bool force_bypass_cache_for_scripts() {
312 return force_bypass_cache_for_scripts_;
314 void set_force_bypass_cache_for_scripts(bool force_bypass_cache_for_scripts) {
315 force_bypass_cache_for_scripts_ = force_bypass_cache_for_scripts;
318 void SetDevToolsAttached(bool attached);
320 // Sets the HttpResponseInfo used to load the main script.
321 // This HttpResponseInfo will be used for all responses sent back from the
322 // service worker, as the effective security of these responses is equivalent
323 // to that of the ServiceWorker.
324 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info);
325 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo();
327 // Simulate ping timeout. Should be used for tests-only.
328 void SimulatePingTimeoutForTesting();
330 private:
331 friend class base::RefCounted<ServiceWorkerVersion>;
332 friend class ServiceWorkerMetrics;
333 friend class ServiceWorkerURLRequestJobTest;
334 friend class ServiceWorkerVersionBrowserTest;
336 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
337 ActivateWaitingVersion);
338 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, IdleTimeout);
339 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, SetDevToolsAttached);
340 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_FreshWorker);
341 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest,
342 StaleUpdate_NonActiveWorker);
343 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_StartWorker);
344 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_RunningWorker);
345 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest,
346 StaleUpdate_DoNotDeferTimer);
347 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, RequestTimeout);
348 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout);
349 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
350 TimeoutStartingWorker);
351 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest,
352 TimeoutWorkerInEvent);
353 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StayAliveAfterPush);
355 class Metrics;
356 class PingController;
358 typedef ServiceWorkerVersion self;
359 using ServiceWorkerClients = std::vector<ServiceWorkerClientInfo>;
361 enum RequestType {
362 REQUEST_ACTIVATE,
363 REQUEST_INSTALL,
364 REQUEST_FETCH,
365 REQUEST_SYNC,
366 REQUEST_NOTIFICATION_CLICK,
367 REQUEST_PUSH,
368 REQUEST_GEOFENCING,
369 REQUEST_SERVICE_PORT_CONNECT
372 struct RequestInfo {
373 RequestInfo(int id, RequestType type, const base::TimeTicks& time);
374 ~RequestInfo();
375 int id;
376 RequestType type;
377 base::TimeTicks time;
380 template <typename CallbackType>
381 struct PendingRequest {
382 PendingRequest(const CallbackType& callback, const base::TimeTicks& time);
383 ~PendingRequest();
385 CallbackType callback;
386 base::TimeTicks start_time;
389 // Timeout for the worker to start.
390 static const int kStartWorkerTimeoutMinutes;
391 // Timeout for a request to be handled.
392 static const int kRequestTimeoutMinutes;
394 ~ServiceWorkerVersion() override;
396 // EmbeddedWorkerInstance::Listener overrides:
397 void OnScriptLoaded() override;
398 void OnStarting() override;
399 void OnStarted() override;
400 void OnStopping() override;
401 void OnStopped(EmbeddedWorkerInstance::Status old_status) override;
402 void OnDetached(EmbeddedWorkerInstance::Status old_status) override;
403 void OnReportException(const base::string16& error_message,
404 int line_number,
405 int column_number,
406 const GURL& source_url) override;
407 void OnReportConsoleMessage(int source_identifier,
408 int message_level,
409 const base::string16& message,
410 int line_number,
411 const GURL& source_url) override;
412 bool OnMessageReceived(const IPC::Message& message) override;
414 void OnStartSentAndScriptEvaluated(ServiceWorkerStatusCode status);
416 void DispatchInstallEventAfterStartWorker(const StatusCallback& callback);
417 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback);
419 void DispatchMessageEventInternal(
420 const base::string16& message,
421 const std::vector<TransferredMessagePort>& sent_message_ports,
422 const StatusCallback& callback);
424 // Message handlers.
426 // This corresponds to the spec's matchAll(options) steps.
427 void OnGetClients(int request_id,
428 const ServiceWorkerClientQueryOptions& options);
430 void OnActivateEventFinished(int request_id,
431 blink::WebServiceWorkerEventResult result);
432 void OnInstallEventFinished(int request_id,
433 blink::WebServiceWorkerEventResult result);
434 void OnFetchEventFinished(int request_id,
435 ServiceWorkerFetchEventResult result,
436 const ServiceWorkerResponse& response);
437 void OnSyncEventFinished(int request_id, ServiceWorkerEventStatus status);
438 void OnNotificationClickEventFinished(int request_id);
439 void OnPushEventFinished(int request_id,
440 blink::WebServiceWorkerEventResult result);
441 void OnGeofencingEventFinished(int request_id);
442 void OnServicePortConnectEventFinished(int request_id,
443 ServicePortConnectResult result,
444 const mojo::String& name,
445 const mojo::String& data);
446 void OnOpenWindow(int request_id, GURL url);
447 void DidOpenWindow(int request_id,
448 int render_process_id,
449 int render_frame_id);
450 void OnOpenWindowFinished(int request_id,
451 const std::string& client_uuid,
452 const ServiceWorkerClientInfo& client_info);
454 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data);
455 void OnSetCachedMetadataFinished(int64 callback_id, int result);
456 void OnClearCachedMetadata(const GURL& url);
457 void OnClearCachedMetadataFinished(int64 callback_id, int result);
459 void OnPostMessageToClient(
460 const std::string& client_uuid,
461 const base::string16& message,
462 const std::vector<TransferredMessagePort>& sent_message_ports);
463 void OnFocusClient(int request_id, const std::string& client_uuid);
464 void OnNavigateClient(int request_id,
465 const std::string& client_uuid,
466 const GURL& url);
467 void DidNavigateClient(int request_id,
468 int render_process_id,
469 int render_frame_id);
470 void OnNavigateClientFinished(int request_id,
471 const std::string& client_uuid,
472 const ServiceWorkerClientInfo& client);
473 void OnSkipWaiting(int request_id);
474 void OnClaimClients(int request_id);
475 void OnPongFromWorker();
477 void OnFocusClientFinished(int request_id,
478 const std::string& client_uuid,
479 const ServiceWorkerClientInfo& client);
481 void DidEnsureLiveRegistrationForStartWorker(
482 const StatusCallback& callback,
483 ServiceWorkerStatusCode status,
484 const scoped_refptr<ServiceWorkerRegistration>& protect);
485 void StartWorkerInternal();
487 void DidSkipWaiting(int request_id);
489 void GetWindowClients(int request_id,
490 const ServiceWorkerClientQueryOptions& options);
491 const std::vector<base::Tuple<int, int, std::string>>
492 GetWindowClientsInternal(bool include_uncontolled);
493 void DidGetWindowClients(int request_id,
494 const ServiceWorkerClientQueryOptions& options,
495 scoped_ptr<ServiceWorkerClients> clients);
496 void GetNonWindowClients(int request_id,
497 const ServiceWorkerClientQueryOptions& options,
498 ServiceWorkerClients* clients);
499 void OnGetClientsFinished(int request_id, ServiceWorkerClients* clients);
501 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker
502 // if it is excessively idle or unresponsive to ping.
503 void StartTimeoutTimer();
504 void StopTimeoutTimer();
505 void OnTimeoutTimer();
507 // Called by PingController for ping protocol.
508 ServiceWorkerStatusCode PingWorker();
509 void OnPingTimeout();
511 // Stops the worker if it is idle (has no in-flight requests) or timed out
512 // ping.
513 void StopWorkerIfIdle();
514 bool HasInflightRequests() const;
516 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer
517 // and records metrics about startup.
518 void RecordStartWorkerResult(ServiceWorkerStatusCode status);
520 template <typename IDMAP>
521 void RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, int request_id);
523 template <typename CallbackType>
524 int AddRequest(
525 const CallbackType& callback,
526 IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map,
527 RequestType request_type);
529 bool OnRequestTimeout(const RequestInfo& info);
530 void SetAllRequestTimes(const base::TimeTicks& ticks);
532 // Returns the reason the embedded worker failed to start, using information
533 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't
534 // deduce a reason.
535 ServiceWorkerStatusCode DeduceStartWorkerFailureReason(
536 ServiceWorkerStatusCode default_code);
538 // Sets |stale_time_| if this worker is stale, causing an update to eventually
539 // occur once the worker stops or is running too long.
540 void MarkIfStale();
542 void FoundRegistrationForUpdate(
543 ServiceWorkerStatusCode status,
544 const scoped_refptr<ServiceWorkerRegistration>& registration);
546 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status);
548 // Called when a connection to a mojo event Dispatcher drops or fails.
549 // Calls callbacks for any outstanding requests to the dispatcher as well
550 // as cleans up the dispatcher.
551 void OnServicePortDispatcherConnectionError();
552 void OnBackgroundSyncDispatcherConnectionError();
554 // Called at the beginning of each Dispatch*Event function: records
555 // the time elapsed since idle (generally the time since the previous
556 // event ended).
557 void OnBeginEvent();
559 const int64 version_id_;
560 const int64 registration_id_;
561 const GURL script_url_;
562 const GURL scope_;
564 Status status_ = NEW;
565 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_;
566 std::vector<StatusCallback> start_callbacks_;
567 std::vector<StatusCallback> stop_callbacks_;
568 std::vector<base::Closure> status_change_callbacks_;
570 // Message callbacks. (Update HasInflightRequests() too when you update this
571 // list.)
572 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_;
573 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_;
574 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_;
575 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> sync_requests_;
576 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer>
577 notification_click_requests_;
578 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_;
579 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> geofencing_requests_;
580 IDMap<PendingRequest<ServicePortConnectCallback>, IDMapOwnPointer>
581 service_port_connect_requests_;
583 ServicePortDispatcherPtr service_port_dispatcher_;
584 BackgroundSyncServiceClientPtr background_sync_dispatcher_;
586 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
588 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_;
589 // Will be null while shutting down.
590 base::WeakPtr<ServiceWorkerContextCore> context_;
591 base::ObserverList<Listener> listeners_;
592 ServiceWorkerScriptCacheMap script_cache_map_;
593 base::OneShotTimer<ServiceWorkerVersion> update_timer_;
595 // Starts running in StartWorker and continues until the worker is stopped.
596 base::RepeatingTimer<ServiceWorkerVersion> timeout_timer_;
597 // Holds the time the worker last started being considered idle.
598 base::TimeTicks idle_time_;
599 // Holds the time that the outstanding StartWorker() request started.
600 base::TimeTicks start_time_;
601 // Holds the time the worker entered STOPPING status.
602 base::TimeTicks stop_time_;
603 // Holds the time the worker was detected as stale and needs updating. We try
604 // to update once the worker stops, but will also update if it stays alive too
605 // long.
606 base::TimeTicks stale_time_;
608 // New requests are added to |requests_| along with their entry in a callback
609 // map. The timeout timer periodically checks |requests_| for entries that
610 // should time out or have already been fulfilled (i.e., removed from the
611 // callback map).
612 std::queue<RequestInfo> requests_;
614 bool skip_waiting_ = false;
615 bool skip_recording_startup_time_ = false;
616 bool force_bypass_cache_for_scripts_ = false;
617 bool is_update_scheduled_ = false;
618 bool in_dtor_ = false;
620 std::vector<int> pending_skip_waiting_requests_;
621 scoped_ptr<net::HttpResponseInfo> main_script_http_info_;
623 // The status when StartWorker was invoked. Used for UMA.
624 Status prestart_status_ = NEW;
625 // If not OK, the reason that StartWorker failed. Used for
626 // running |start_callbacks_|.
627 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK;
629 scoped_ptr<PingController> ping_controller_;
630 scoped_ptr<Metrics> metrics_;
631 const bool should_exclude_from_uma_ = false;
633 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
635 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
638 } // namespace content
640 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_