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