| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 // Informs ServiceWorkerVersion that an event has finished being dispatched. | 257 // Informs ServiceWorkerVersion that an event has finished being dispatched. |
| 258 // Returns false if no pending requests with the provided id exist, for | 258 // Returns false if no pending requests with the provided id exist, for |
| 259 // example if the request has already timed out. | 259 // example if the request has already timed out. |
| 260 // Pass the result of the event to |was_handled|, which is used to record | 260 // Pass the result of the event to |was_handled|, which is used to record |
| 261 // statistics based on the event status. | 261 // statistics based on the event status. |
| 262 // TODO(mek): Use something other than a bool for event status. | 262 // TODO(mek): Use something other than a bool for event status. |
| 263 bool FinishRequest(int request_id, | 263 bool FinishRequest(int request_id, |
| 264 bool was_handled, | 264 bool was_handled, |
| 265 base::Time dispatch_event_time); | 265 base::Time dispatch_event_time); |
| 266 | 266 |
| 267 void RegisterForeignFetchScopes(const std::vector<GURL>& sub_scopes, |
| 268 const std::vector<url::Origin>& origins); |
| 269 |
| 267 // Finishes an external request that was started by StartExternalRequest(). | 270 // Finishes an external request that was started by StartExternalRequest(). |
| 268 // Returns false if there was an error finishing the request: e.g. the request | 271 // Returns false if there was an error finishing the request: e.g. the request |
| 269 // was not found or the worker already terminated. | 272 // was not found or the worker already terminated. |
| 270 bool FinishExternalRequest(const std::string& request_uuid); | 273 bool FinishExternalRequest(const std::string& request_uuid); |
| 271 | 274 |
| 272 // Creates a callback that is to be used for marking simple events dispatched | 275 // Creates a callback that is to be used for marking simple events dispatched |
| 273 // through the ServiceWorkerEventDispatcher as finished for the |request_id|. | 276 // through the ServiceWorkerEventDispatcher as finished for the |request_id|. |
| 274 // Simple event means those events expecting a response with only a status | 277 // Simple event means those events expecting a response with only a status |
| 275 // code and the dispatch time. See service_worker_event_dispatcher.mojom. | 278 // code and the dispatch time. See service_worker_event_dispatcher.mojom. |
| 276 SimpleEventCallback CreateSimpleEventCallback(int request_id); | 279 SimpleEventCallback CreateSimpleEventCallback(int request_id); |
| 277 | 280 |
| 278 // This must be called when the worker is running. | 281 // This must be called when the worker is running. |
| 279 mojom::ServiceWorkerEventDispatcher* event_dispatcher() { | 282 mojom::ServiceWorkerEventDispatcher* event_dispatcher() { |
| 280 DCHECK(event_dispatcher_.is_bound()); | 283 DCHECK(event_dispatcher_.is_bound()); |
| 281 return event_dispatcher_.get(); | 284 return event_dispatcher_.get(); |
| 282 } | 285 } |
| 283 | 286 |
| 284 // Dispatches an event. If dispatching the event fails, all of the error | |
| 285 // callbacks that were associated with |request_ids| via StartRequest are | |
| 286 // called. | |
| 287 // Use RegisterRequestCallback to register a callback to receive messages sent | |
| 288 // back in response to this event before calling this method. This must be | |
| 289 // called when the worker is running. | |
| 290 void DispatchEvent(const std::vector<int>& request_ids, | |
| 291 const IPC::Message& message); | |
| 292 | |
| 293 // This method registers a callback to receive messages sent back from the | 287 // This method registers a callback to receive messages sent back from the |
| 294 // service worker in response to |request_id|. | 288 // service worker in response to |request_id|. |
| 295 // ResponseMessage is the type of the IPC message that is used for the | 289 // ResponseMessage is the type of the IPC message that is used for the |
| 296 // response, and its first argument MUST be the request_id. | 290 // response, and its first argument MUST be the request_id. |
| 297 // Callback registration should be done once for one request_id. | 291 // Callback registration should be done once for one request_id. |
| 298 template <typename ResponseMessage, typename ResponseCallbackType> | 292 template <typename ResponseMessage, typename ResponseCallbackType> |
| 299 void RegisterRequestCallback(int request_id, | 293 void RegisterRequestCallback(int request_id, |
| 300 const ResponseCallbackType& callback); | 294 const ResponseCallbackType& callback); |
| 301 | 295 |
| 302 // Adds and removes |provider_host| as a controllee of this ServiceWorker. | 296 // Adds and removes |provider_host| as a controllee of this ServiceWorker. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 396 } |
| 403 | 397 |
| 404 void CountFeature(uint32_t feature); | 398 void CountFeature(uint32_t feature); |
| 405 void set_used_features(const std::set<uint32_t>& used_features) { | 399 void set_used_features(const std::set<uint32_t>& used_features) { |
| 406 used_features_ = used_features; | 400 used_features_ = used_features; |
| 407 } | 401 } |
| 408 const std::set<uint32_t>& used_features() const { return used_features_; } | 402 const std::set<uint32_t>& used_features() const { return used_features_; } |
| 409 | 403 |
| 410 private: | 404 private: |
| 411 friend class base::RefCounted<ServiceWorkerVersion>; | 405 friend class base::RefCounted<ServiceWorkerVersion>; |
| 406 friend class ServiceWorkerJobTest; |
| 412 friend class ServiceWorkerMetrics; | 407 friend class ServiceWorkerMetrics; |
| 413 friend class ServiceWorkerReadFromCacheJobTest; | 408 friend class ServiceWorkerReadFromCacheJobTest; |
| 414 friend class ServiceWorkerStallInStoppingTest; | 409 friend class ServiceWorkerStallInStoppingTest; |
| 415 friend class ServiceWorkerURLRequestJobTest; | 410 friend class ServiceWorkerURLRequestJobTest; |
| 416 friend class ServiceWorkerVersionBrowserTest; | 411 friend class ServiceWorkerVersionBrowserTest; |
| 417 friend class ServiceWorkerVersionTest; | 412 friend class ServiceWorkerVersionTest; |
| 418 | 413 |
| 419 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, | 414 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, |
| 420 ActivateWaitingVersion); | 415 ActivateWaitingVersion); |
| 421 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, | 416 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, |
| 422 FallbackWithNoFetchHandler); | 417 FallbackWithNoFetchHandler); |
| 418 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerJobTest, Register); |
| 423 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, IdleTimeout); | 419 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, IdleTimeout); |
| 424 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, SetDevToolsAttached); | 420 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, SetDevToolsAttached); |
| 425 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_FreshWorker); | 421 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_FreshWorker); |
| 426 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 422 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 427 StaleUpdate_NonActiveWorker); | 423 StaleUpdate_NonActiveWorker); |
| 428 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_StartWorker); | 424 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_StartWorker); |
| 429 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_RunningWorker); | 425 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_RunningWorker); |
| 430 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, | 426 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 431 StaleUpdate_DoNotDeferTimer); | 427 StaleUpdate_DoNotDeferTimer); |
| 432 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerRequestTimeoutTest, RequestTimeout); | 428 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerRequestTimeoutTest, RequestTimeout); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 void OnNavigateClientFinished(int request_id, | 605 void OnNavigateClientFinished(int request_id, |
| 610 ServiceWorkerStatusCode status, | 606 ServiceWorkerStatusCode status, |
| 611 const ServiceWorkerClientInfo& client_info); | 607 const ServiceWorkerClientInfo& client_info); |
| 612 void OnSkipWaiting(int request_id); | 608 void OnSkipWaiting(int request_id); |
| 613 void OnClaimClients(int request_id); | 609 void OnClaimClients(int request_id); |
| 614 void OnPongFromWorker(); | 610 void OnPongFromWorker(); |
| 615 | 611 |
| 616 void OnFocusClientFinished(int request_id, | 612 void OnFocusClientFinished(int request_id, |
| 617 const ServiceWorkerClientInfo& client_info); | 613 const ServiceWorkerClientInfo& client_info); |
| 618 | 614 |
| 619 void OnRegisterForeignFetchScopes(const std::vector<GURL>& sub_scopes, | |
| 620 const std::vector<url::Origin>& origins); | |
| 621 | |
| 622 void DidEnsureLiveRegistrationForStartWorker( | 615 void DidEnsureLiveRegistrationForStartWorker( |
| 623 ServiceWorkerMetrics::EventType purpose, | 616 ServiceWorkerMetrics::EventType purpose, |
| 624 Status prestart_status, | 617 Status prestart_status, |
| 625 bool is_browser_startup_complete, | 618 bool is_browser_startup_complete, |
| 626 const StatusCallback& callback, | 619 const StatusCallback& callback, |
| 627 ServiceWorkerStatusCode status, | 620 ServiceWorkerStatusCode status, |
| 628 scoped_refptr<ServiceWorkerRegistration> registration); | 621 scoped_refptr<ServiceWorkerRegistration> registration); |
| 629 void StartWorkerInternal(); | 622 void StartWorkerInternal(); |
| 630 | 623 |
| 631 void DidSkipWaiting(int request_id); | 624 void DidSkipWaiting(int request_id); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 | 828 |
| 836 // At this point |this| can have been deleted, so don't do anything other | 829 // At this point |this| can have been deleted, so don't do anything other |
| 837 // than returning. | 830 // than returning. |
| 838 | 831 |
| 839 return true; | 832 return true; |
| 840 } | 833 } |
| 841 | 834 |
| 842 } // namespace content | 835 } // namespace content |
| 843 | 836 |
| 844 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 837 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |