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_
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/background_sync/background_sync_registration_handle.h"
23 #include "content/browser/service_worker/embedded_worker_instance.h"
24 #include "content/browser/service_worker/service_worker_script_cache_map.h"
25 #include "content/common/background_sync_service.mojom.h"
26 #include "content/common/content_export.h"
27 #include "content/common/service_port_service.mojom.h"
28 #include "content/common/service_worker/service_worker_status_code.h"
29 #include "content/common/service_worker/service_worker_types.h"
30 #include "content/public/common/service_registry.h"
31 #include "third_party/WebKit/public/platform/WebGeofencingEventType.h"
32 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerEventResult.h"
34 // Windows headers will redefine SendMessage.
42 struct WebCircularGeofencingRegion
;
46 class HttpResponseInfo
;
51 class EmbeddedWorkerRegistry
;
52 class ServiceWorkerContextCore
;
53 class ServiceWorkerProviderHost
;
54 class ServiceWorkerRegistration
;
55 class ServiceWorkerURLRequestJob
;
56 struct NavigatorConnectClient
;
57 struct PlatformNotificationData
;
58 struct ServiceWorkerClientInfo
;
59 struct ServiceWorkerVersionInfo
;
60 struct TransferredMessagePort
;
62 // This class corresponds to a specific version of a ServiceWorker
63 // script for a given pattern. When a script is upgraded, there may be
64 // more than one ServiceWorkerVersion "running" at a time, but only
65 // one of them is activated. This class connects the actual script with a
67 class CONTENT_EXPORT ServiceWorkerVersion
68 : NON_EXPORTED_BASE(public base::RefCounted
<ServiceWorkerVersion
>),
69 public EmbeddedWorkerInstance::Listener
{
71 typedef base::Callback
<void(ServiceWorkerStatusCode
)> StatusCallback
;
72 typedef base::Callback
<void(ServiceWorkerStatusCode
,
73 ServiceWorkerFetchEventResult
,
74 const ServiceWorkerResponse
&)> FetchCallback
;
75 typedef base::Callback
<void(ServiceWorkerStatusCode
,
76 bool /* accept_connction */,
77 const base::string16
& /* name */,
78 const base::string16
& /* data */)>
79 ServicePortConnectCallback
;
82 STOPPED
= EmbeddedWorkerInstance::STOPPED
,
83 STARTING
= EmbeddedWorkerInstance::STARTING
,
84 RUNNING
= EmbeddedWorkerInstance::RUNNING
,
85 STOPPING
= EmbeddedWorkerInstance::STOPPING
,
88 // Current version status; some of the status (e.g. INSTALLED and ACTIVATED)
89 // should be persisted unlike running status.
91 NEW
, // The version is just created.
92 INSTALLING
, // Install event is dispatched and being handled.
93 INSTALLED
, // Install event is finished and is ready to be activated.
94 ACTIVATING
, // Activate event is dispatched and being handled.
95 ACTIVATED
, // Activation is finished and can run as activated.
96 REDUNDANT
, // The version is no longer running as activated, due to
97 // unregistration or replace.
102 virtual void OnRunningStateChanged(ServiceWorkerVersion
* version
) {}
103 virtual void OnVersionStateChanged(ServiceWorkerVersion
* version
) {}
104 virtual void OnMainScriptHttpResponseInfoSet(
105 ServiceWorkerVersion
* version
) {}
106 virtual void OnErrorReported(ServiceWorkerVersion
* version
,
107 const base::string16
& error_message
,
110 const GURL
& source_url
) {}
111 virtual void OnReportConsoleMessage(ServiceWorkerVersion
* version
,
112 int source_identifier
,
114 const base::string16
& message
,
116 const GURL
& source_url
) {}
117 virtual void OnControlleeAdded(ServiceWorkerVersion
* version
,
118 ServiceWorkerProviderHost
* provider_host
) {}
119 virtual void OnControlleeRemoved(ServiceWorkerVersion
* version
,
120 ServiceWorkerProviderHost
* provider_host
) {
122 // Fires when a version transitions from having a controllee to not.
123 virtual void OnNoControllees(ServiceWorkerVersion
* version
) {}
124 virtual void OnCachedMetadataUpdated(ServiceWorkerVersion
* version
) {}
127 virtual ~Listener() {}
130 ServiceWorkerVersion(
131 ServiceWorkerRegistration
* registration
,
132 const GURL
& script_url
,
134 base::WeakPtr
<ServiceWorkerContextCore
> context
);
136 int64
version_id() const { return version_id_
; }
137 int64
registration_id() const { return registration_id_
; }
138 const GURL
& script_url() const { return script_url_
; }
139 const GURL
& scope() const { return scope_
; }
140 RunningStatus
running_status() const {
141 return static_cast<RunningStatus
>(embedded_worker_
->status());
143 ServiceWorkerVersionInfo
GetInfo();
144 Status
status() const { return status_
; }
146 // This sets the new status and also run status change callbacks
147 // if there're any (see RegisterStatusChangeCallback).
148 void SetStatus(Status status
);
150 // Registers status change callback. (This is for one-off observation,
151 // the consumer needs to re-register if it wants to continue observing
153 void RegisterStatusChangeCallback(const base::Closure
& callback
);
155 // Starts an embedded worker for this version.
156 // This returns OK (success) if the worker is already running.
157 void StartWorker(const StatusCallback
& callback
);
159 // Stops an embedded worker for this version.
160 // This returns OK (success) if the worker is already stopped.
161 void StopWorker(const StatusCallback
& callback
);
163 // Schedules an update to be run 'soon'.
164 void ScheduleUpdate();
166 // If an update is scheduled but not yet started, this resets the timer
167 // delaying the start time by a 'small' amount.
168 void DeferScheduledUpdate();
170 // Starts an update now.
173 // Sends a message event to the associated embedded worker.
174 void DispatchMessageEvent(
175 const base::string16
& message
,
176 const std::vector
<TransferredMessagePort
>& sent_message_ports
,
177 const StatusCallback
& callback
);
179 // Sends install event to the associated embedded worker and asynchronously
180 // calls |callback| when it errors out or it gets a response from the worker
181 // to notify install completion.
183 // This must be called when the status() is NEW. Calling this changes
184 // the version's status to INSTALLING.
185 // Upon completion, the version's status will be changed to INSTALLED
186 // on success, or back to NEW on failure.
187 void DispatchInstallEvent(const StatusCallback
& callback
);
189 // Sends activate event to the associated embedded worker and asynchronously
190 // calls |callback| when it errors out or it gets a response from the worker
191 // to notify activation completion.
193 // This must be called when the status() is INSTALLED. Calling this changes
194 // the version's status to ACTIVATING.
195 // Upon completion, the version's status will be changed to ACTIVATED
196 // on success, or back to INSTALLED on failure.
197 void DispatchActivateEvent(const StatusCallback
& callback
);
199 // Sends fetch event to the associated embedded worker and calls
200 // |callback| with the response from the worker.
202 // This must be called when the status() is ACTIVATED. Calling this in other
203 // statuses will result in an error SERVICE_WORKER_ERROR_FAILED.
204 void DispatchFetchEvent(const ServiceWorkerFetchRequest
& request
,
205 const base::Closure
& prepare_callback
,
206 const FetchCallback
& fetch_callback
);
208 // Sends sync event to the associated embedded worker and asynchronously calls
209 // |callback| when it errors out or it gets a response from the worker to
210 // notify completion.
212 // This must be called when the status() is ACTIVATED.
213 void DispatchSyncEvent(BackgroundSyncRegistrationHandle::HandleId handle_id
,
214 const StatusCallback
& callback
);
216 // Sends notificationclick event to the associated embedded worker and
217 // asynchronously calls |callback| when it errors out or it gets a response
218 // from the worker to notify completion.
220 // This must be called when the status() is ACTIVATED.
221 void DispatchNotificationClickEvent(
222 const StatusCallback
& callback
,
223 int64_t persistent_notification_id
,
224 const PlatformNotificationData
& notification_data
,
227 // Sends push event to the associated embedded worker and asynchronously calls
228 // |callback| when it errors out or it gets a response from the worker to
229 // notify completion.
231 // This must be called when the status() is ACTIVATED.
232 void DispatchPushEvent(const StatusCallback
& callback
,
233 const std::string
& data
);
235 // Sends geofencing event to the associated embedded worker and asynchronously
236 // calls |callback| when it errors out or it gets a response from the worker
237 // to notify completion.
239 // This must be called when the status() is ACTIVATED.
240 void DispatchGeofencingEvent(
241 const StatusCallback
& callback
,
242 blink::WebGeofencingEventType event_type
,
243 const std::string
& region_id
,
244 const blink::WebCircularGeofencingRegion
& region
);
246 // Sends a ServicePort connect event to the associated embedded worker and
247 // asynchronously calls |callback| with the response from the worker.
249 // This must be called when the status() is ACTIVATED.
250 void DispatchServicePortConnectEvent(
251 const ServicePortConnectCallback
& callback
,
252 const GURL
& target_url
,
256 // Sends a cross origin message event to the associated embedded worker and
257 // asynchronously calls |callback| when the message was sent (or failed to
259 // It is the responsibility of the code calling this method to make sure that
260 // any transferred message ports are put on hold while potentially a process
261 // for the service worker is spun up.
263 // This must be called when the status() is ACTIVATED.
264 void DispatchCrossOriginMessageEvent(
265 const NavigatorConnectClient
& client
,
266 const base::string16
& message
,
267 const std::vector
<TransferredMessagePort
>& sent_message_ports
,
268 const StatusCallback
& callback
);
270 // Adds and removes |provider_host| as a controllee of this ServiceWorker.
271 // A potential controllee is a host having the version as its .installing
272 // or .waiting version.
273 void AddControllee(ServiceWorkerProviderHost
* provider_host
);
274 void RemoveControllee(ServiceWorkerProviderHost
* provider_host
);
276 // Returns if it has controllee.
277 bool HasControllee() const { return !controllee_map_
.empty(); }
279 // Returns whether the service worker has active window clients under its
281 bool HasWindowClients();
283 // Adds and removes |request_job| as a dependent job not to stop the
284 // ServiceWorker while |request_job| is reading the stream of the fetch event
285 // response from the ServiceWorker.
286 void AddStreamingURLRequestJob(const ServiceWorkerURLRequestJob
* request_job
);
287 void RemoveStreamingURLRequestJob(
288 const ServiceWorkerURLRequestJob
* request_job
);
290 // Adds and removes Listeners.
291 void AddListener(Listener
* listener
);
292 void RemoveListener(Listener
* listener
);
294 ServiceWorkerScriptCacheMap
* script_cache_map() { return &script_cache_map_
; }
295 EmbeddedWorkerInstance
* embedded_worker() { return embedded_worker_
.get(); }
297 // Reports the error message to |listeners_|.
298 void ReportError(ServiceWorkerStatusCode status
,
299 const std::string
& status_message
);
301 // Sets the status code to pass to StartWorker callbacks if start fails.
302 void SetStartWorkerStatusCode(ServiceWorkerStatusCode status
);
304 // Sets this version's status to REDUNDANT and deletes its resources.
305 // The version must not have controllees.
307 bool is_redundant() const { return status_
== REDUNDANT
; }
309 bool skip_waiting() const { return skip_waiting_
; }
310 void set_skip_waiting(bool skip_waiting
) { skip_waiting_
= skip_waiting
; }
312 bool force_bypass_cache_for_scripts() {
313 return force_bypass_cache_for_scripts_
;
315 void set_force_bypass_cache_for_scripts(bool force_bypass_cache_for_scripts
) {
316 force_bypass_cache_for_scripts_
= force_bypass_cache_for_scripts
;
319 void SetDevToolsAttached(bool attached
);
321 // Sets the HttpResponseInfo used to load the main script.
322 // This HttpResponseInfo will be used for all responses sent back from the
323 // service worker, as the effective security of these responses is equivalent
324 // to that of the ServiceWorker.
325 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo
& http_info
);
326 const net::HttpResponseInfo
* GetMainScriptHttpResponseInfo();
328 // Simulate ping timeout. Should be used for tests-only.
329 void SimulatePingTimeoutForTesting();
332 friend class base::RefCounted
<ServiceWorkerVersion
>;
333 friend class ServiceWorkerMetrics
;
334 friend class ServiceWorkerURLRequestJobTest
;
335 friend class ServiceWorkerVersionBrowserTest
;
337 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest
,
338 ActivateWaitingVersion
);
339 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest
, IdleTimeout
);
340 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest
, SetDevToolsAttached
);
341 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest
, StaleUpdate_FreshWorker
);
342 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest
,
343 StaleUpdate_NonActiveWorker
);
344 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest
, StaleUpdate_StartWorker
);
345 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest
, StaleUpdate_RunningWorker
);
346 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest
,
347 StaleUpdate_DoNotDeferTimer
);
348 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest
, RequestTimeout
);
349 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest
, Timeout
);
350 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest
,
351 TimeoutStartingWorker
);
352 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest
,
353 TimeoutWorkerInEvent
);
354 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest
, StayAliveAfterPush
);
357 class PingController
;
359 typedef ServiceWorkerVersion self
;
360 using ServiceWorkerClients
= std::vector
<ServiceWorkerClientInfo
>;
362 // Used for UMA; add new entries to the end, before NUM_REQUEST_TYPES.
368 REQUEST_NOTIFICATION_CLICK
,
371 REQUEST_SERVICE_PORT_CONNECT
,
376 RequestInfo(int id
, RequestType type
, const base::TimeTicks
& time
);
380 base::TimeTicks time
;
383 template <typename CallbackType
>
384 struct PendingRequest
{
385 PendingRequest(const CallbackType
& callback
, const base::TimeTicks
& time
);
388 CallbackType callback
;
389 base::TimeTicks start_time
;
392 // Timeout for the worker to start.
393 static const int kStartWorkerTimeoutMinutes
;
394 // Timeout for a request to be handled.
395 static const int kRequestTimeoutMinutes
;
397 ~ServiceWorkerVersion() override
;
399 // EmbeddedWorkerInstance::Listener overrides:
400 void OnThreadStarted() override
;
401 void OnStarting() override
;
402 void OnStarted() override
;
403 void OnStopping() override
;
404 void OnStopped(EmbeddedWorkerInstance::Status old_status
) override
;
405 void OnDetached(EmbeddedWorkerInstance::Status old_status
) override
;
406 void OnReportException(const base::string16
& error_message
,
409 const GURL
& source_url
) override
;
410 void OnReportConsoleMessage(int source_identifier
,
412 const base::string16
& message
,
414 const GURL
& source_url
) override
;
415 bool OnMessageReceived(const IPC::Message
& message
) override
;
417 void OnStartSentAndScriptEvaluated(ServiceWorkerStatusCode status
);
419 void DispatchInstallEventAfterStartWorker(const StatusCallback
& callback
);
420 void DispatchActivateEventAfterStartWorker(const StatusCallback
& callback
);
422 void DispatchMessageEventInternal(
423 const base::string16
& message
,
424 const std::vector
<TransferredMessagePort
>& sent_message_ports
,
425 const StatusCallback
& callback
);
429 // This corresponds to the spec's matchAll(options) steps.
430 void OnGetClients(int request_id
,
431 const ServiceWorkerClientQueryOptions
& options
);
433 void OnActivateEventFinished(int request_id
,
434 blink::WebServiceWorkerEventResult result
);
435 void OnInstallEventFinished(int request_id
,
436 blink::WebServiceWorkerEventResult result
);
437 void OnFetchEventFinished(int request_id
,
438 ServiceWorkerFetchEventResult result
,
439 const ServiceWorkerResponse
& response
);
440 void OnSyncEventFinished(int request_id
, ServiceWorkerEventStatus status
);
441 void OnNotificationClickEventFinished(int request_id
);
442 void OnPushEventFinished(int request_id
,
443 blink::WebServiceWorkerEventResult result
);
444 void OnGeofencingEventFinished(int request_id
);
445 void OnServicePortConnectEventFinished(int request_id
,
446 ServicePortConnectResult result
,
447 const mojo::String
& name
,
448 const mojo::String
& data
);
449 void OnOpenWindow(int request_id
, GURL url
);
450 void DidOpenWindow(int request_id
,
451 int render_process_id
,
452 int render_frame_id
);
453 void OnOpenWindowFinished(int request_id
,
454 const std::string
& client_uuid
,
455 const ServiceWorkerClientInfo
& client_info
);
457 void OnSetCachedMetadata(const GURL
& url
, const std::vector
<char>& data
);
458 void OnSetCachedMetadataFinished(int64 callback_id
, int result
);
459 void OnClearCachedMetadata(const GURL
& url
);
460 void OnClearCachedMetadataFinished(int64 callback_id
, int result
);
462 void OnPostMessageToClient(
463 const std::string
& client_uuid
,
464 const base::string16
& message
,
465 const std::vector
<TransferredMessagePort
>& sent_message_ports
);
466 void OnFocusClient(int request_id
, const std::string
& client_uuid
);
467 void OnNavigateClient(int request_id
,
468 const std::string
& client_uuid
,
470 void DidNavigateClient(int request_id
,
471 int render_process_id
,
472 int render_frame_id
);
473 void OnNavigateClientFinished(int request_id
,
474 const std::string
& client_uuid
,
475 const ServiceWorkerClientInfo
& client
);
476 void OnSkipWaiting(int request_id
);
477 void OnClaimClients(int request_id
);
478 void OnPongFromWorker();
480 void OnFocusClientFinished(int request_id
,
481 const std::string
& client_uuid
,
482 const ServiceWorkerClientInfo
& client
);
484 void DidEnsureLiveRegistrationForStartWorker(
485 const StatusCallback
& callback
,
486 ServiceWorkerStatusCode status
,
487 const scoped_refptr
<ServiceWorkerRegistration
>& protect
);
488 void StartWorkerInternal();
490 void DidSkipWaiting(int request_id
);
492 void GetWindowClients(int request_id
,
493 const ServiceWorkerClientQueryOptions
& options
);
494 const std::vector
<base::Tuple
<int, int, std::string
>>
495 GetWindowClientsInternal(bool include_uncontolled
);
496 void DidGetWindowClients(int request_id
,
497 const ServiceWorkerClientQueryOptions
& options
,
498 scoped_ptr
<ServiceWorkerClients
> clients
);
499 void GetNonWindowClients(int request_id
,
500 const ServiceWorkerClientQueryOptions
& options
,
501 ServiceWorkerClients
* clients
);
502 void OnGetClientsFinished(int request_id
, ServiceWorkerClients
* clients
);
504 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker
505 // if it is excessively idle or unresponsive to ping.
506 void StartTimeoutTimer();
507 void StopTimeoutTimer();
508 void OnTimeoutTimer();
510 // Called by PingController for ping protocol.
511 ServiceWorkerStatusCode
PingWorker();
512 void OnPingTimeout();
514 // Stops the worker if it is idle (has no in-flight requests) or timed out
516 void StopWorkerIfIdle();
517 bool HasInflightRequests() const;
519 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer
520 // and records metrics about startup.
521 void RecordStartWorkerResult(ServiceWorkerStatusCode status
);
523 template <typename IDMAP
>
524 void RemoveCallbackAndStopIfRedundant(IDMAP
* callbacks
, int request_id
);
526 template <typename CallbackType
>
528 const CallbackType
& callback
,
529 IDMap
<PendingRequest
<CallbackType
>, IDMapOwnPointer
>* callback_map
,
530 RequestType request_type
);
532 bool MaybeTimeOutRequest(const RequestInfo
& info
);
533 void SetAllRequestTimes(const base::TimeTicks
& ticks
);
535 // Returns the reason the embedded worker failed to start, using information
536 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't
538 ServiceWorkerStatusCode
DeduceStartWorkerFailureReason(
539 ServiceWorkerStatusCode default_code
);
541 // Sets |stale_time_| if this worker is stale, causing an update to eventually
542 // occur once the worker stops or is running too long.
545 void FoundRegistrationForUpdate(
546 ServiceWorkerStatusCode status
,
547 const scoped_refptr
<ServiceWorkerRegistration
>& registration
);
549 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status
);
551 // Called when a connection to a mojo event Dispatcher drops or fails.
552 // Calls callbacks for any outstanding requests to the dispatcher as well
553 // as cleans up the dispatcher.
554 void OnServicePortDispatcherConnectionError();
555 void OnBackgroundSyncDispatcherConnectionError();
557 // Called at the beginning of each Dispatch*Event function: records
558 // the time elapsed since idle (generally the time since the previous
562 const int64 version_id_
;
563 const int64 registration_id_
;
564 const GURL script_url_
;
567 Status status_
= NEW
;
568 scoped_ptr
<EmbeddedWorkerInstance
> embedded_worker_
;
569 std::vector
<StatusCallback
> start_callbacks_
;
570 std::vector
<StatusCallback
> stop_callbacks_
;
571 std::vector
<base::Closure
> status_change_callbacks_
;
573 // Message callbacks. (Update HasInflightRequests() too when you update this
575 IDMap
<PendingRequest
<StatusCallback
>, IDMapOwnPointer
> activate_requests_
;
576 IDMap
<PendingRequest
<StatusCallback
>, IDMapOwnPointer
> install_requests_
;
577 IDMap
<PendingRequest
<FetchCallback
>, IDMapOwnPointer
> fetch_requests_
;
578 IDMap
<PendingRequest
<StatusCallback
>, IDMapOwnPointer
> sync_requests_
;
579 IDMap
<PendingRequest
<StatusCallback
>, IDMapOwnPointer
>
580 notification_click_requests_
;
581 IDMap
<PendingRequest
<StatusCallback
>, IDMapOwnPointer
> push_requests_
;
582 IDMap
<PendingRequest
<StatusCallback
>, IDMapOwnPointer
> geofencing_requests_
;
583 IDMap
<PendingRequest
<ServicePortConnectCallback
>, IDMapOwnPointer
>
584 service_port_connect_requests_
;
586 ServicePortDispatcherPtr service_port_dispatcher_
;
587 BackgroundSyncServiceClientPtr background_sync_dispatcher_
;
589 std::set
<const ServiceWorkerURLRequestJob
*> streaming_url_request_jobs_
;
591 std::map
<std::string
, ServiceWorkerProviderHost
*> controllee_map_
;
592 // Will be null while shutting down.
593 base::WeakPtr
<ServiceWorkerContextCore
> context_
;
594 base::ObserverList
<Listener
> listeners_
;
595 ServiceWorkerScriptCacheMap script_cache_map_
;
596 base::OneShotTimer
<ServiceWorkerVersion
> update_timer_
;
598 // Starts running in StartWorker and continues until the worker is stopped.
599 base::RepeatingTimer
<ServiceWorkerVersion
> timeout_timer_
;
600 // Holds the time the worker last started being considered idle.
601 base::TimeTicks idle_time_
;
602 // Holds the time that the outstanding StartWorker() request started.
603 base::TimeTicks start_time_
;
604 // Holds the time the worker entered STOPPING status.
605 base::TimeTicks stop_time_
;
606 // Holds the time the worker was detected as stale and needs updating. We try
607 // to update once the worker stops, but will also update if it stays alive too
609 base::TimeTicks stale_time_
;
611 // New requests are added to |requests_| along with their entry in a callback
612 // map. The timeout timer periodically checks |requests_| for entries that
613 // should time out or have already been fulfilled (i.e., removed from the
615 std::queue
<RequestInfo
> requests_
;
617 bool skip_waiting_
= false;
618 bool skip_recording_startup_time_
= false;
619 bool force_bypass_cache_for_scripts_
= false;
620 bool is_update_scheduled_
= false;
621 bool in_dtor_
= false;
623 std::vector
<int> pending_skip_waiting_requests_
;
624 scoped_ptr
<net::HttpResponseInfo
> main_script_http_info_
;
626 // The status when StartWorker was invoked. Used for UMA.
627 Status prestart_status_
= NEW
;
628 // If not OK, the reason that StartWorker failed. Used for
629 // running |start_callbacks_|.
630 ServiceWorkerStatusCode start_worker_status_
= SERVICE_WORKER_OK
;
632 scoped_ptr
<PingController
> ping_controller_
;
633 scoped_ptr
<Metrics
> metrics_
;
634 const bool should_exclude_from_uma_
= false;
636 base::WeakPtrFactory
<ServiceWorkerVersion
> weak_factory_
;
638 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion
);
641 } // namespace content
643 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_