Permission messages: Add a bunch of missing combinations/suppressions.
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_version.h
blob24534a126bf228435dabd455dc27a6aae98631de
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 // Used for UMA; add new entries to the end, before NUM_REQUEST_TYPES.
362 enum RequestType {
363 REQUEST_ACTIVATE,
364 REQUEST_INSTALL,
365 REQUEST_FETCH,
366 REQUEST_SYNC,
367 REQUEST_NOTIFICATION_CLICK,
368 REQUEST_PUSH,
369 REQUEST_GEOFENCING,
370 REQUEST_SERVICE_PORT_CONNECT,
371 NUM_REQUEST_TYPES
374 struct RequestInfo {
375 RequestInfo(int id, RequestType type, const base::TimeTicks& time);
376 ~RequestInfo();
377 int id;
378 RequestType type;
379 base::TimeTicks time;
382 template <typename CallbackType>
383 struct PendingRequest {
384 PendingRequest(const CallbackType& callback, const base::TimeTicks& time);
385 ~PendingRequest();
387 CallbackType callback;
388 base::TimeTicks start_time;
391 // Timeout for the worker to start.
392 static const int kStartWorkerTimeoutMinutes;
393 // Timeout for a request to be handled.
394 static const int kRequestTimeoutMinutes;
396 ~ServiceWorkerVersion() override;
398 // EmbeddedWorkerInstance::Listener overrides:
399 void OnScriptLoaded() override;
400 void OnStarting() override;
401 void OnStarted() override;
402 void OnStopping() override;
403 void OnStopped(EmbeddedWorkerInstance::Status old_status) override;
404 void OnDetached(EmbeddedWorkerInstance::Status old_status) override;
405 void OnReportException(const base::string16& error_message,
406 int line_number,
407 int column_number,
408 const GURL& source_url) override;
409 void OnReportConsoleMessage(int source_identifier,
410 int message_level,
411 const base::string16& message,
412 int line_number,
413 const GURL& source_url) override;
414 bool OnMessageReceived(const IPC::Message& message) override;
416 void OnStartSentAndScriptEvaluated(ServiceWorkerStatusCode status);
418 void DispatchInstallEventAfterStartWorker(const StatusCallback& callback);
419 void DispatchActivateEventAfterStartWorker(const StatusCallback& callback);
421 void DispatchMessageEventInternal(
422 const base::string16& message,
423 const std::vector<TransferredMessagePort>& sent_message_ports,
424 const StatusCallback& callback);
426 // Message handlers.
428 // This corresponds to the spec's matchAll(options) steps.
429 void OnGetClients(int request_id,
430 const ServiceWorkerClientQueryOptions& options);
432 void OnActivateEventFinished(int request_id,
433 blink::WebServiceWorkerEventResult result);
434 void OnInstallEventFinished(int request_id,
435 blink::WebServiceWorkerEventResult result);
436 void OnFetchEventFinished(int request_id,
437 ServiceWorkerFetchEventResult result,
438 const ServiceWorkerResponse& response);
439 void OnSyncEventFinished(int request_id, ServiceWorkerEventStatus status);
440 void OnNotificationClickEventFinished(int request_id);
441 void OnPushEventFinished(int request_id,
442 blink::WebServiceWorkerEventResult result);
443 void OnGeofencingEventFinished(int request_id);
444 void OnServicePortConnectEventFinished(int request_id,
445 ServicePortConnectResult result,
446 const mojo::String& name,
447 const mojo::String& data);
448 void OnOpenWindow(int request_id, GURL url);
449 void DidOpenWindow(int request_id,
450 int render_process_id,
451 int render_frame_id);
452 void OnOpenWindowFinished(int request_id,
453 const std::string& client_uuid,
454 const ServiceWorkerClientInfo& client_info);
456 void OnSetCachedMetadata(const GURL& url, const std::vector<char>& data);
457 void OnSetCachedMetadataFinished(int64 callback_id, int result);
458 void OnClearCachedMetadata(const GURL& url);
459 void OnClearCachedMetadataFinished(int64 callback_id, int result);
461 void OnPostMessageToClient(
462 const std::string& client_uuid,
463 const base::string16& message,
464 const std::vector<TransferredMessagePort>& sent_message_ports);
465 void OnFocusClient(int request_id, const std::string& client_uuid);
466 void OnNavigateClient(int request_id,
467 const std::string& client_uuid,
468 const GURL& url);
469 void DidNavigateClient(int request_id,
470 int render_process_id,
471 int render_frame_id);
472 void OnNavigateClientFinished(int request_id,
473 const std::string& client_uuid,
474 const ServiceWorkerClientInfo& client);
475 void OnSkipWaiting(int request_id);
476 void OnClaimClients(int request_id);
477 void OnPongFromWorker();
479 void OnFocusClientFinished(int request_id,
480 const std::string& client_uuid,
481 const ServiceWorkerClientInfo& client);
483 void DidEnsureLiveRegistrationForStartWorker(
484 const StatusCallback& callback,
485 ServiceWorkerStatusCode status,
486 const scoped_refptr<ServiceWorkerRegistration>& protect);
487 void StartWorkerInternal();
489 void DidSkipWaiting(int request_id);
491 void GetWindowClients(int request_id,
492 const ServiceWorkerClientQueryOptions& options);
493 const std::vector<base::Tuple<int, int, std::string>>
494 GetWindowClientsInternal(bool include_uncontolled);
495 void DidGetWindowClients(int request_id,
496 const ServiceWorkerClientQueryOptions& options,
497 scoped_ptr<ServiceWorkerClients> clients);
498 void GetNonWindowClients(int request_id,
499 const ServiceWorkerClientQueryOptions& options,
500 ServiceWorkerClients* clients);
501 void OnGetClientsFinished(int request_id, ServiceWorkerClients* clients);
503 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker
504 // if it is excessively idle or unresponsive to ping.
505 void StartTimeoutTimer();
506 void StopTimeoutTimer();
507 void OnTimeoutTimer();
509 // Called by PingController for ping protocol.
510 ServiceWorkerStatusCode PingWorker();
511 void OnPingTimeout();
513 // Stops the worker if it is idle (has no in-flight requests) or timed out
514 // ping.
515 void StopWorkerIfIdle();
516 bool HasInflightRequests() const;
518 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer
519 // and records metrics about startup.
520 void RecordStartWorkerResult(ServiceWorkerStatusCode status);
522 template <typename IDMAP>
523 void RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, int request_id);
525 template <typename CallbackType>
526 int AddRequest(
527 const CallbackType& callback,
528 IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map,
529 RequestType request_type);
531 bool MaybeTimeOutRequest(const RequestInfo& info);
532 void SetAllRequestTimes(const base::TimeTicks& ticks);
534 // Returns the reason the embedded worker failed to start, using information
535 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't
536 // deduce a reason.
537 ServiceWorkerStatusCode DeduceStartWorkerFailureReason(
538 ServiceWorkerStatusCode default_code);
540 // Sets |stale_time_| if this worker is stale, causing an update to eventually
541 // occur once the worker stops or is running too long.
542 void MarkIfStale();
544 void FoundRegistrationForUpdate(
545 ServiceWorkerStatusCode status,
546 const scoped_refptr<ServiceWorkerRegistration>& registration);
548 void OnStoppedInternal(EmbeddedWorkerInstance::Status old_status);
550 // Called when a connection to a mojo event Dispatcher drops or fails.
551 // Calls callbacks for any outstanding requests to the dispatcher as well
552 // as cleans up the dispatcher.
553 void OnServicePortDispatcherConnectionError();
554 void OnBackgroundSyncDispatcherConnectionError();
556 // Called at the beginning of each Dispatch*Event function: records
557 // the time elapsed since idle (generally the time since the previous
558 // event ended).
559 void OnBeginEvent();
561 const int64 version_id_;
562 const int64 registration_id_;
563 const GURL script_url_;
564 const GURL scope_;
566 Status status_ = NEW;
567 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_;
568 std::vector<StatusCallback> start_callbacks_;
569 std::vector<StatusCallback> stop_callbacks_;
570 std::vector<base::Closure> status_change_callbacks_;
572 // Message callbacks. (Update HasInflightRequests() too when you update this
573 // list.)
574 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> activate_requests_;
575 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> install_requests_;
576 IDMap<PendingRequest<FetchCallback>, IDMapOwnPointer> fetch_requests_;
577 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> sync_requests_;
578 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer>
579 notification_click_requests_;
580 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> push_requests_;
581 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer> geofencing_requests_;
582 IDMap<PendingRequest<ServicePortConnectCallback>, IDMapOwnPointer>
583 service_port_connect_requests_;
585 ServicePortDispatcherPtr service_port_dispatcher_;
586 BackgroundSyncServiceClientPtr background_sync_dispatcher_;
588 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
590 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_;
591 // Will be null while shutting down.
592 base::WeakPtr<ServiceWorkerContextCore> context_;
593 base::ObserverList<Listener> listeners_;
594 ServiceWorkerScriptCacheMap script_cache_map_;
595 base::OneShotTimer<ServiceWorkerVersion> update_timer_;
597 // Starts running in StartWorker and continues until the worker is stopped.
598 base::RepeatingTimer<ServiceWorkerVersion> timeout_timer_;
599 // Holds the time the worker last started being considered idle.
600 base::TimeTicks idle_time_;
601 // Holds the time that the outstanding StartWorker() request started.
602 base::TimeTicks start_time_;
603 // Holds the time the worker entered STOPPING status.
604 base::TimeTicks stop_time_;
605 // Holds the time the worker was detected as stale and needs updating. We try
606 // to update once the worker stops, but will also update if it stays alive too
607 // long.
608 base::TimeTicks stale_time_;
610 // New requests are added to |requests_| along with their entry in a callback
611 // map. The timeout timer periodically checks |requests_| for entries that
612 // should time out or have already been fulfilled (i.e., removed from the
613 // callback map).
614 std::queue<RequestInfo> requests_;
616 bool skip_waiting_ = false;
617 bool skip_recording_startup_time_ = false;
618 bool force_bypass_cache_for_scripts_ = false;
619 bool is_update_scheduled_ = false;
620 bool in_dtor_ = false;
622 std::vector<int> pending_skip_waiting_requests_;
623 scoped_ptr<net::HttpResponseInfo> main_script_http_info_;
625 // The status when StartWorker was invoked. Used for UMA.
626 Status prestart_status_ = NEW;
627 // If not OK, the reason that StartWorker failed. Used for
628 // running |start_callbacks_|.
629 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK;
631 scoped_ptr<PingController> ping_controller_;
632 scoped_ptr<Metrics> metrics_;
633 const bool should_exclude_from_uma_ = false;
635 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
637 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
640 } // namespace content
642 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_