| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 // if there're any (see RegisterStatusChangeCallback). | 157 // if there're any (see RegisterStatusChangeCallback). |
| 158 void SetStatus(Status status); | 158 void SetStatus(Status status); |
| 159 | 159 |
| 160 // Registers status change callback. (This is for one-off observation, | 160 // Registers status change callback. (This is for one-off observation, |
| 161 // the consumer needs to re-register if it wants to continue observing | 161 // the consumer needs to re-register if it wants to continue observing |
| 162 // status changes) | 162 // status changes) |
| 163 void RegisterStatusChangeCallback(const base::Closure& callback); | 163 void RegisterStatusChangeCallback(const base::Closure& callback); |
| 164 | 164 |
| 165 // Starts an embedded worker for this version. | 165 // Starts an embedded worker for this version. |
| 166 // This returns OK (success) if the worker is already running. | 166 // This returns OK (success) if the worker is already running. |
| 167 void StartWorker(const StatusCallback& callback); | 167 // |purpose| is recorded in UMA. |
| 168 void StartWorker(ServiceWorkerMetrics::EventType purpose, |
| 169 const StatusCallback& callback); |
| 168 | 170 |
| 169 // Stops an embedded worker for this version. | 171 // Stops an embedded worker for this version. |
| 170 // This returns OK (success) if the worker is already stopped. | 172 // This returns OK (success) if the worker is already stopped. |
| 171 void StopWorker(const StatusCallback& callback); | 173 void StopWorker(const StatusCallback& callback); |
| 172 | 174 |
| 173 // Schedules an update to be run 'soon'. | 175 // Schedules an update to be run 'soon'. |
| 174 void ScheduleUpdate(); | 176 void ScheduleUpdate(); |
| 175 | 177 |
| 176 // If an update is scheduled but not yet started, this resets the timer | 178 // If an update is scheduled but not yet started, this resets the timer |
| 177 // delaying the start time by a 'small' amount. | 179 // delaying the start time by a 'small' amount. |
| 178 void DeferScheduledUpdate(); | 180 void DeferScheduledUpdate(); |
| 179 | 181 |
| 180 // Starts an update now. | 182 // Starts an update now. |
| 181 void StartUpdate(); | 183 void StartUpdate(); |
| 182 | 184 |
| 183 // Starts the worker if it isn't already running, and calls |task| when the | 185 // Starts the worker if it isn't already running, and calls |task| when the |
| 184 // worker is running, or |error_callback| if starting the worker failed. | 186 // worker is running, or |error_callback| if starting the worker failed. |
| 185 // If the worker is already running, |task| is executed synchronously (before | 187 // If the worker is already running, |task| is executed synchronously (before |
| 186 // this method returns). | 188 // this method returns). |
| 187 void RunAfterStartWorker(const base::Closure& task, | 189 // |purpose| is used for UMA. |
| 190 void RunAfterStartWorker(ServiceWorkerMetrics::EventType purpose, |
| 191 const base::Closure& task, |
| 188 const StatusCallback& error_callback); | 192 const StatusCallback& error_callback); |
| 189 | 193 |
| 190 // Call this while the worker is running before dispatching an event to the | 194 // Call this while the worker is running before dispatching an event to the |
| 191 // worker. This informs ServiceWorkerVersion about the event in progress. | 195 // worker. This informs ServiceWorkerVersion about the event in progress. |
| 192 // Returns a request id, which should later be passed to FinishRequest when | 196 // Returns a request id, which should later be passed to FinishRequest when |
| 193 // the event finished. | 197 // the event finished. |
| 194 // The |error_callback| is called if either ServiceWorkerVersion decides the | 198 // The |error_callback| is called if either ServiceWorkerVersion decides the |
| 195 // event is taking too long, or if for some reason the worker stops or is | 199 // event is taking too long, or if for some reason the worker stops or is |
| 196 // killed before the request finishes. | 200 // killed before the request finishes. |
| 197 int StartRequest(ServiceWorkerMetrics::EventType event_type, | 201 int StartRequest(ServiceWorkerMetrics::EventType event_type, |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 void OnClaimClients(int request_id); | 552 void OnClaimClients(int request_id); |
| 549 void OnPongFromWorker(); | 553 void OnPongFromWorker(); |
| 550 | 554 |
| 551 void OnFocusClientFinished(int request_id, | 555 void OnFocusClientFinished(int request_id, |
| 552 const ServiceWorkerClientInfo& client_info); | 556 const ServiceWorkerClientInfo& client_info); |
| 553 | 557 |
| 554 void OnRegisterForeignFetchScopes(const std::vector<GURL>& sub_scopes, | 558 void OnRegisterForeignFetchScopes(const std::vector<GURL>& sub_scopes, |
| 555 const std::vector<url::Origin>& origins); | 559 const std::vector<url::Origin>& origins); |
| 556 | 560 |
| 557 void DidEnsureLiveRegistrationForStartWorker( | 561 void DidEnsureLiveRegistrationForStartWorker( |
| 562 ServiceWorkerMetrics::EventType purpose, |
| 558 const StatusCallback& callback, | 563 const StatusCallback& callback, |
| 559 ServiceWorkerStatusCode status, | 564 ServiceWorkerStatusCode status, |
| 560 const scoped_refptr<ServiceWorkerRegistration>& registration); | 565 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 561 void StartWorkerInternal(); | 566 void StartWorkerInternal(); |
| 562 | 567 |
| 563 void DidSkipWaiting(int request_id); | 568 void DidSkipWaiting(int request_id); |
| 564 | 569 |
| 565 void OnGetClientFinished(int request_id, | 570 void OnGetClientFinished(int request_id, |
| 566 const ServiceWorkerClientInfo& client_info); | 571 const ServiceWorkerClientInfo& client_info); |
| 567 | 572 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 578 ServiceWorkerStatusCode PingWorker(); | 583 ServiceWorkerStatusCode PingWorker(); |
| 579 void OnPingTimeout(); | 584 void OnPingTimeout(); |
| 580 | 585 |
| 581 // Stops the worker if it is idle (has no in-flight requests) or timed out | 586 // Stops the worker if it is idle (has no in-flight requests) or timed out |
| 582 // ping. | 587 // ping. |
| 583 void StopWorkerIfIdle(); | 588 void StopWorkerIfIdle(); |
| 584 bool HasInflightRequests() const; | 589 bool HasInflightRequests() const; |
| 585 | 590 |
| 586 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer | 591 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer |
| 587 // and records metrics about startup. | 592 // and records metrics about startup. |
| 588 void RecordStartWorkerResult(ServiceWorkerStatusCode status); | 593 void RecordStartWorkerResult(ServiceWorkerMetrics::EventType purpose, |
| 594 ServiceWorkerStatusCode status); |
| 589 | 595 |
| 590 bool MaybeTimeOutRequest(const RequestInfo& info); | 596 bool MaybeTimeOutRequest(const RequestInfo& info); |
| 591 void SetAllRequestExpirations(const base::TimeTicks& expiration); | 597 void SetAllRequestExpirations(const base::TimeTicks& expiration); |
| 592 | 598 |
| 593 // Returns the reason the embedded worker failed to start, using information | 599 // Returns the reason the embedded worker failed to start, using information |
| 594 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't | 600 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't |
| 595 // deduce a reason. | 601 // deduce a reason. |
| 596 ServiceWorkerStatusCode DeduceStartWorkerFailureReason( | 602 ServiceWorkerStatusCode DeduceStartWorkerFailureReason( |
| 597 ServiceWorkerStatusCode default_code); | 603 ServiceWorkerStatusCode default_code); |
| 598 | 604 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 | 773 |
| 768 // At this point |this| can have been deleted, so don't do anything other | 774 // At this point |this| can have been deleted, so don't do anything other |
| 769 // than returning. | 775 // than returning. |
| 770 | 776 |
| 771 return true; | 777 return true; |
| 772 } | 778 } |
| 773 | 779 |
| 774 } // namespace content | 780 } // namespace content |
| 775 | 781 |
| 776 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 782 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |