| 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 OnNoInflightRequests(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 bool HasInflightRequests() const; |
| 346 |
| 347 private: | 347 private: |
| 348 friend class base::RefCounted<ServiceWorkerVersion>; | 348 friend class base::RefCounted<ServiceWorkerVersion>; |
| 349 friend class ServiceWorkerMetrics; | 349 friend class ServiceWorkerMetrics; |
| 350 friend class ServiceWorkerReadFromCacheJobTest; | 350 friend class ServiceWorkerReadFromCacheJobTest; |
| 351 friend class ServiceWorkerStallInStoppingTest; | 351 friend class ServiceWorkerStallInStoppingTest; |
| 352 friend class ServiceWorkerURLRequestJobTest; | 352 friend class ServiceWorkerURLRequestJobTest; |
| 353 friend class ServiceWorkerVersionBrowserTest; | 353 friend class ServiceWorkerVersionBrowserTest; |
| 354 friend class ServiceWorkerVersionTest; | 354 friend class ServiceWorkerVersionTest; |
| 355 | 355 |
| 356 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, | 356 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 373 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); | 373 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); |
| 374 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); | 374 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); |
| 375 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 375 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 376 RegisterForeignFetchScopes); | 376 RegisterForeignFetchScopes); |
| 377 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); | 377 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); |
| 378 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 378 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 379 RequestCustomizedTimeoutKill); | 379 RequestCustomizedTimeoutKill); |
| 380 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts); | 380 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts); |
| 381 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse); | 381 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse); |
| 382 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest); | 382 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest); |
| 383 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, SkipWaiting); |
| 384 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, |
| 385 SkipWaitingWithInflightRequest); |
| 383 | 386 |
| 384 class Metrics; | 387 class Metrics; |
| 385 class PingController; | 388 class PingController; |
| 386 | 389 |
| 387 struct RequestInfo { | 390 struct RequestInfo { |
| 388 RequestInfo(int id, | 391 RequestInfo(int id, |
| 389 ServiceWorkerMetrics::EventType event_type, | 392 ServiceWorkerMetrics::EventType event_type, |
| 390 const base::TimeTicks& expiration, | 393 const base::TimeTicks& expiration, |
| 391 TimeoutBehavior timeout_behavior); | 394 TimeoutBehavior timeout_behavior); |
| 392 ~RequestInfo(); | 395 ~RequestInfo(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 void OnTimeoutTimer(); | 595 void OnTimeoutTimer(); |
| 593 void SetTimeoutTimerInterval(base::TimeDelta interval); | 596 void SetTimeoutTimerInterval(base::TimeDelta interval); |
| 594 | 597 |
| 595 // Called by PingController for ping protocol. | 598 // Called by PingController for ping protocol. |
| 596 ServiceWorkerStatusCode PingWorker(); | 599 ServiceWorkerStatusCode PingWorker(); |
| 597 void OnPingTimeout(); | 600 void OnPingTimeout(); |
| 598 | 601 |
| 599 // Stops the worker if it is idle (has no in-flight requests) or timed out | 602 // Stops the worker if it is idle (has no in-flight requests) or timed out |
| 600 // ping. | 603 // ping. |
| 601 void StopWorkerIfIdle(); | 604 void StopWorkerIfIdle(); |
| 602 bool HasInflightRequests() const; | |
| 603 | 605 |
| 604 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer | 606 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer |
| 605 // and records metrics about startup. | 607 // and records metrics about startup. |
| 606 void RecordStartWorkerResult(ServiceWorkerMetrics::EventType purpose, | 608 void RecordStartWorkerResult(ServiceWorkerMetrics::EventType purpose, |
| 607 Status prestart_status, | 609 Status prestart_status, |
| 608 int trace_id, | 610 int trace_id, |
| 609 bool is_browser_startup_complete, | 611 bool is_browser_startup_complete, |
| 610 ServiceWorkerStatusCode status); | 612 ServiceWorkerStatusCode status); |
| 611 | 613 |
| 612 bool MaybeTimeOutRequest(const RequestInfo& info); | 614 bool MaybeTimeOutRequest(const RequestInfo& info); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 | 790 |
| 789 // At this point |this| can have been deleted, so don't do anything other | 791 // At this point |this| can have been deleted, so don't do anything other |
| 790 // than returning. | 792 // than returning. |
| 791 | 793 |
| 792 return true; | 794 return true; |
| 793 } | 795 } |
| 794 | 796 |
| 795 } // namespace content | 797 } // namespace content |
| 796 | 798 |
| 797 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 799 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |