| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 366 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 367 RegisterForeignFetchScopes); | 367 RegisterForeignFetchScopes); |
| 368 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); | 368 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); |
| 369 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 369 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 370 RequestCustomizedTimeoutKill); | 370 RequestCustomizedTimeoutKill); |
| 371 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts); | 371 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts); |
| 372 | 372 |
| 373 class Metrics; | 373 class Metrics; |
| 374 class PingController; | 374 class PingController; |
| 375 | 375 |
| 376 enum RequestType { | |
| 377 REQUEST_CUSTOM, | |
| 378 NUM_REQUEST_TYPES | |
| 379 }; | |
| 380 | |
| 381 struct RequestInfo { | 376 struct RequestInfo { |
| 382 RequestInfo(int id, | 377 RequestInfo(int id, |
| 383 RequestType type, | |
| 384 ServiceWorkerMetrics::EventType event_type, | 378 ServiceWorkerMetrics::EventType event_type, |
| 385 const base::TimeTicks& expiration, | 379 const base::TimeTicks& expiration, |
| 386 TimeoutBehavior timeout_behavior); | 380 TimeoutBehavior timeout_behavior); |
| 387 ~RequestInfo(); | 381 ~RequestInfo(); |
| 388 bool operator>(const RequestInfo& other) const; | 382 bool operator>(const RequestInfo& other) const; |
| 389 int id; | 383 int id; |
| 390 RequestType type; | |
| 391 ServiceWorkerMetrics::EventType event_type; | 384 ServiceWorkerMetrics::EventType event_type; |
| 392 base::TimeTicks expiration; | 385 base::TimeTicks expiration; |
| 393 TimeoutBehavior timeout_behavior; | 386 TimeoutBehavior timeout_behavior; |
| 394 }; | 387 }; |
| 395 | 388 |
| 396 template <typename CallbackType> | 389 template <typename CallbackType> |
| 397 struct PendingRequest { | 390 struct PendingRequest { |
| 398 PendingRequest(const CallbackType& callback, | 391 PendingRequest(const CallbackType& callback, |
| 399 const base::TimeTicks& time, | 392 const base::TimeTicks& time, |
| 400 ServiceWorkerMetrics::EventType event_type); | 393 ServiceWorkerMetrics::EventType event_type); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 580 |
| 588 // Stops the worker if it is idle (has no in-flight requests) or timed out | 581 // Stops the worker if it is idle (has no in-flight requests) or timed out |
| 589 // ping. | 582 // ping. |
| 590 void StopWorkerIfIdle(); | 583 void StopWorkerIfIdle(); |
| 591 bool HasInflightRequests() const; | 584 bool HasInflightRequests() const; |
| 592 | 585 |
| 593 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer | 586 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer |
| 594 // and records metrics about startup. | 587 // and records metrics about startup. |
| 595 void RecordStartWorkerResult(ServiceWorkerStatusCode status); | 588 void RecordStartWorkerResult(ServiceWorkerStatusCode status); |
| 596 | 589 |
| 597 template <typename IDMAP> | |
| 598 void RemoveCallbackAndStopIfRedundant(IDMAP* callbacks, int request_id); | |
| 599 | |
| 600 template <typename CallbackType> | |
| 601 int AddRequest( | |
| 602 const CallbackType& callback, | |
| 603 IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map, | |
| 604 RequestType request_type, | |
| 605 ServiceWorkerMetrics::EventType event_type); | |
| 606 | |
| 607 template <typename CallbackType> | |
| 608 int AddRequestWithExpiration( | |
| 609 const CallbackType& callback, | |
| 610 IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map, | |
| 611 RequestType request_type, | |
| 612 ServiceWorkerMetrics::EventType event_type, | |
| 613 base::TimeTicks expiration, | |
| 614 TimeoutBehavior timeout_behavior); | |
| 615 | |
| 616 bool MaybeTimeOutRequest(const RequestInfo& info); | 590 bool MaybeTimeOutRequest(const RequestInfo& info); |
| 617 void SetAllRequestExpirations(const base::TimeTicks& expiration); | 591 void SetAllRequestExpirations(const base::TimeTicks& expiration); |
| 618 | 592 |
| 619 // Returns the reason the embedded worker failed to start, using information | 593 // Returns the reason the embedded worker failed to start, using information |
| 620 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't | 594 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't |
| 621 // deduce a reason. | 595 // deduce a reason. |
| 622 ServiceWorkerStatusCode DeduceStartWorkerFailureReason( | 596 ServiceWorkerStatusCode DeduceStartWorkerFailureReason( |
| 623 ServiceWorkerStatusCode default_code); | 597 ServiceWorkerStatusCode default_code); |
| 624 | 598 |
| 625 // Sets |stale_time_| if this worker is stale, causing an update to eventually | 599 // Sets |stale_time_| if this worker is stale, causing an update to eventually |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 766 |
| 793 // At this point |this| can have been deleted, so don't do anything other | 767 // At this point |this| can have been deleted, so don't do anything other |
| 794 // than returning. | 768 // than returning. |
| 795 | 769 |
| 796 return true; | 770 return true; |
| 797 } | 771 } |
| 798 | 772 |
| 799 } // namespace content | 773 } // namespace content |
| 800 | 774 |
| 801 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 775 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |