OLD | NEW |
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_SERVICE_WORKER_VERSION_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <functional> | 10 #include <functional> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 int source_identifier, | 102 int source_identifier, |
103 int message_level, | 103 int message_level, |
104 const base::string16& message, | 104 const base::string16& message, |
105 int line_number, | 105 int line_number, |
106 const GURL& source_url) {} | 106 const GURL& source_url) {} |
107 virtual void OnControlleeAdded(ServiceWorkerVersion* version, | 107 virtual void OnControlleeAdded(ServiceWorkerVersion* version, |
108 ServiceWorkerProviderHost* provider_host) {} | 108 ServiceWorkerProviderHost* provider_host) {} |
109 virtual void OnControlleeRemoved(ServiceWorkerVersion* version, | 109 virtual void OnControlleeRemoved(ServiceWorkerVersion* version, |
110 ServiceWorkerProviderHost* provider_host) { | 110 ServiceWorkerProviderHost* provider_host) { |
111 } | 111 } |
112 // Fires when a version transitions from having a controllee to not. | |
113 virtual void OnNoControllees(ServiceWorkerVersion* version) {} | 112 virtual void OnNoControllees(ServiceWorkerVersion* version) {} |
| 113 virtual void OnNoWork(ServiceWorkerVersion* version) {} |
114 virtual void OnCachedMetadataUpdated(ServiceWorkerVersion* version) {} | 114 virtual void OnCachedMetadataUpdated(ServiceWorkerVersion* version) {} |
115 | 115 |
116 protected: | 116 protected: |
117 virtual ~Listener() {} | 117 virtual ~Listener() {} |
118 }; | 118 }; |
119 | 119 |
120 ServiceWorkerVersion(ServiceWorkerRegistration* registration, | 120 ServiceWorkerVersion(ServiceWorkerRegistration* registration, |
121 const GURL& script_url, | 121 const GURL& script_url, |
122 int64_t version_id, | 122 int64_t version_id, |
123 base::WeakPtr<ServiceWorkerContextCore> context); | 123 base::WeakPtr<ServiceWorkerContextCore> context); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // RegisterRequestCallback/DispatchEvent is not needed, this method can be | 267 // RegisterRequestCallback/DispatchEvent is not needed, this method can be |
268 // used instead. The ResponseMessage must consist | 268 // used instead. The ResponseMessage must consist |
269 // of just a request_id and a blink::WebServiceWorkerEventResult field. The | 269 // of just a request_id and a blink::WebServiceWorkerEventResult field. The |
270 // result is converted to a ServiceWorkerStatusCode and passed to the error | 270 // result is converted to a ServiceWorkerStatusCode and passed to the error |
271 // handler associated with the request. Additionally this methods calls | 271 // handler associated with the request. Additionally this methods calls |
272 // FinishRequest before passing the reply to the callback. | 272 // FinishRequest before passing the reply to the callback. |
273 template <typename ResponseMessage> | 273 template <typename ResponseMessage> |
274 void DispatchSimpleEvent(int request_id, const IPC::Message& message); | 274 void DispatchSimpleEvent(int request_id, const IPC::Message& message); |
275 | 275 |
276 // Adds and removes |provider_host| as a controllee of this ServiceWorker. | 276 // Adds and removes |provider_host| as a controllee of this ServiceWorker. |
277 // A potential controllee is a host having the version as its .installing | |
278 // or .waiting version. | |
279 void AddControllee(ServiceWorkerProviderHost* provider_host); | 277 void AddControllee(ServiceWorkerProviderHost* provider_host); |
280 void RemoveControllee(ServiceWorkerProviderHost* provider_host); | 278 void RemoveControllee(ServiceWorkerProviderHost* provider_host); |
281 | 279 |
282 // Returns if it has controllee. | 280 // Returns if it has controllee. |
283 bool HasControllee() const { return !controllee_map_.empty(); } | 281 bool HasControllee() const { return !controllee_map_.empty(); } |
284 std::map<std::string, ServiceWorkerProviderHost*> controllee_map() { | 282 std::map<std::string, ServiceWorkerProviderHost*> controllee_map() { |
285 return controllee_map_; | 283 return controllee_map_; |
286 } | 284 } |
287 | 285 |
288 base::WeakPtr<ServiceWorkerContextCore> context() const { return context_; } | 286 base::WeakPtr<ServiceWorkerContextCore> context() const { return context_; } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // Sets the HttpResponseInfo used to load the main script. | 335 // Sets the HttpResponseInfo used to load the main script. |
338 // This HttpResponseInfo will be used for all responses sent back from the | 336 // This HttpResponseInfo will be used for all responses sent back from the |
339 // service worker, as the effective security of these responses is equivalent | 337 // service worker, as the effective security of these responses is equivalent |
340 // to that of the ServiceWorker. | 338 // to that of the ServiceWorker. |
341 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info); | 339 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info); |
342 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo(); | 340 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo(); |
343 | 341 |
344 // Simulate ping timeout. Should be used for tests-only. | 342 // Simulate ping timeout. Should be used for tests-only. |
345 void SimulatePingTimeoutForTesting(); | 343 void SimulatePingTimeoutForTesting(); |
346 | 344 |
| 345 // Returns true if the service worker has work to do: it has pending |
| 346 // requests, in-progress streaming URLRequestJobs, or pending start callbacks. |
| 347 bool HasWork() const; |
| 348 |
347 private: | 349 private: |
348 friend class base::RefCounted<ServiceWorkerVersion>; | 350 friend class base::RefCounted<ServiceWorkerVersion>; |
349 friend class ServiceWorkerMetrics; | 351 friend class ServiceWorkerMetrics; |
350 friend class ServiceWorkerReadFromCacheJobTest; | 352 friend class ServiceWorkerReadFromCacheJobTest; |
351 friend class ServiceWorkerStallInStoppingTest; | 353 friend class ServiceWorkerStallInStoppingTest; |
352 friend class ServiceWorkerURLRequestJobTest; | 354 friend class ServiceWorkerURLRequestJobTest; |
353 friend class ServiceWorkerVersionBrowserTest; | 355 friend class ServiceWorkerVersionBrowserTest; |
354 friend class ServiceWorkerVersionTest; | 356 friend class ServiceWorkerVersionTest; |
355 | 357 |
356 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, | 358 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, |
(...skipping 18 matching lines...) Expand all Loading... |
375 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); | 377 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); |
376 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); | 378 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); |
377 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 379 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
378 RegisterForeignFetchScopes); | 380 RegisterForeignFetchScopes); |
379 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); | 381 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); |
380 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 382 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
381 RequestCustomizedTimeoutKill); | 383 RequestCustomizedTimeoutKill); |
382 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts); | 384 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts); |
383 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse); | 385 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse); |
384 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest); | 386 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest); |
| 387 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, SkipWaiting); |
| 388 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, |
| 389 SkipWaitingWithInflightRequest); |
385 | 390 |
386 class Metrics; | 391 class Metrics; |
387 class PingController; | 392 class PingController; |
388 | 393 |
389 struct RequestInfo { | 394 struct RequestInfo { |
390 RequestInfo(int id, | 395 RequestInfo(int id, |
391 ServiceWorkerMetrics::EventType event_type, | 396 ServiceWorkerMetrics::EventType event_type, |
392 const base::TimeTicks& expiration, | 397 const base::TimeTicks& expiration, |
393 TimeoutBehavior timeout_behavior); | 398 TimeoutBehavior timeout_behavior); |
394 ~RequestInfo(); | 399 ~RequestInfo(); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 void OnTimeoutTimer(); | 599 void OnTimeoutTimer(); |
595 void SetTimeoutTimerInterval(base::TimeDelta interval); | 600 void SetTimeoutTimerInterval(base::TimeDelta interval); |
596 | 601 |
597 // Called by PingController for ping protocol. | 602 // Called by PingController for ping protocol. |
598 ServiceWorkerStatusCode PingWorker(); | 603 ServiceWorkerStatusCode PingWorker(); |
599 void OnPingTimeout(); | 604 void OnPingTimeout(); |
600 | 605 |
601 // Stops the worker if it is idle (has no in-flight requests) or timed out | 606 // Stops the worker if it is idle (has no in-flight requests) or timed out |
602 // ping. | 607 // ping. |
603 void StopWorkerIfIdle(); | 608 void StopWorkerIfIdle(); |
604 bool HasInflightRequests() const; | |
605 | 609 |
606 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer | 610 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer |
607 // and records metrics about startup. | 611 // and records metrics about startup. |
608 void RecordStartWorkerResult(ServiceWorkerMetrics::EventType purpose, | 612 void RecordStartWorkerResult(ServiceWorkerMetrics::EventType purpose, |
609 Status prestart_status, | 613 Status prestart_status, |
610 int trace_id, | 614 int trace_id, |
611 bool is_browser_startup_complete, | 615 bool is_browser_startup_complete, |
612 ServiceWorkerStatusCode status); | 616 ServiceWorkerStatusCode status); |
613 | 617 |
614 bool MaybeTimeOutRequest(const RequestInfo& info); | 618 bool MaybeTimeOutRequest(const RequestInfo& info); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 | 794 |
791 // At this point |this| can have been deleted, so don't do anything other | 795 // At this point |this| can have been deleted, so don't do anything other |
792 // than returning. | 796 // than returning. |
793 | 797 |
794 return true; | 798 return true; |
795 } | 799 } |
796 | 800 |
797 } // namespace content | 801 } // namespace content |
798 | 802 |
799 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 803 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |