| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 int StartRequest(ServiceWorkerMetrics::EventType event_type, | 228 int StartRequest(ServiceWorkerMetrics::EventType event_type, |
| 229 const StatusCallback& error_callback); | 229 const StatusCallback& error_callback); |
| 230 | 230 |
| 231 // Same as StartRequest, but allows the caller to specify a custom timeout for | 231 // Same as StartRequest, but allows the caller to specify a custom timeout for |
| 232 // the event, as well as the behavior for when the request times out. | 232 // the event, as well as the behavior for when the request times out. |
| 233 int StartRequestWithCustomTimeout(ServiceWorkerMetrics::EventType event_type, | 233 int StartRequestWithCustomTimeout(ServiceWorkerMetrics::EventType event_type, |
| 234 const StatusCallback& error_callback, | 234 const StatusCallback& error_callback, |
| 235 const base::TimeDelta& timeout, | 235 const base::TimeDelta& timeout, |
| 236 TimeoutBehavior timeout_behavior); | 236 TimeoutBehavior timeout_behavior); |
| 237 | 237 |
| 238 // Starts a request of type EventType::EXTERNAL_REQUEST. |
| 239 // Provides a mechanism to external clients to keep the worker running. |
| 240 // |request_uuid| is a GUID for clients to identify the request. |
| 241 bool StartExternalRequest(const std::string& request_uuid); |
| 242 |
| 238 // Informs ServiceWorkerVersion that an event has finished being dispatched. | 243 // Informs ServiceWorkerVersion that an event has finished being dispatched. |
| 239 // Returns false if no pending requests with the provided id exist, for | 244 // Returns false if no pending requests with the provided id exist, for |
| 240 // example if the request has already timed out. | 245 // example if the request has already timed out. |
| 241 // Pass the result of the event to |was_handled|, which is used to record | 246 // Pass the result of the event to |was_handled|, which is used to record |
| 242 // statistics based on the event status. | 247 // statistics based on the event status. |
| 243 // TODO(mek): Use something other than a bool for event status. | 248 // TODO(mek): Use something other than a bool for event status. |
| 244 bool FinishRequest(int request_id, | 249 bool FinishRequest(int request_id, |
| 245 bool was_handled, | 250 bool was_handled, |
| 246 base::Time dispatch_event_time); | 251 base::Time dispatch_event_time); |
| 247 | 252 |
| 253 // Finishes an external request that was started by StartExternalRequest(). |
| 254 bool FinishExternalRequest(const std::string& request_uuid); |
| 255 |
| 248 // Connects to a specific mojo service exposed by the (running) service | 256 // Connects to a specific mojo service exposed by the (running) service |
| 249 // worker. If a connection to a service for the same Interface already exists | 257 // worker. If a connection to a service for the same Interface already exists |
| 250 // this will return that existing connection. The |request_id| must be a value | 258 // this will return that existing connection. The |request_id| must be a value |
| 251 // previously returned by StartRequest. If the connection to the service | 259 // previously returned by StartRequest. If the connection to the service |
| 252 // fails or closes before the request finished, the error callback associated | 260 // fails or closes before the request finished, the error callback associated |
| 253 // with |request_id| is called. | 261 // with |request_id| is called. |
| 254 // Only call GetMojoServiceForRequest once for a specific |request_id|. | 262 // Only call GetMojoServiceForRequest once for a specific |request_id|. |
| 255 template <typename Interface> | 263 template <typename Interface> |
| 256 base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id); | 264 base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id); |
| 257 | 265 |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 682 |
| 675 // Called at the beginning of each Dispatch*Event function: records | 683 // Called at the beginning of each Dispatch*Event function: records |
| 676 // the time elapsed since idle (generally the time since the previous | 684 // the time elapsed since idle (generally the time since the previous |
| 677 // event ended). | 685 // event ended). |
| 678 void OnBeginEvent(); | 686 void OnBeginEvent(); |
| 679 | 687 |
| 680 // Resets |start_worker_first_purpose_| and fires and clears all start | 688 // Resets |start_worker_first_purpose_| and fires and clears all start |
| 681 // callbacks. | 689 // callbacks. |
| 682 void FinishStartWorker(ServiceWorkerStatusCode status); | 690 void FinishStartWorker(ServiceWorkerStatusCode status); |
| 683 | 691 |
| 692 // Removes any pending external request that has GUID of |request_uuid|. |
| 693 void CleanUpExternalRequest(const std::string& request_uuid, |
| 694 ServiceWorkerStatusCode status); |
| 695 |
| 684 const int64_t version_id_; | 696 const int64_t version_id_; |
| 685 const int64_t registration_id_; | 697 const int64_t registration_id_; |
| 686 const GURL script_url_; | 698 const GURL script_url_; |
| 687 const GURL scope_; | 699 const GURL scope_; |
| 688 std::vector<GURL> foreign_fetch_scopes_; | 700 std::vector<GURL> foreign_fetch_scopes_; |
| 689 std::vector<url::Origin> foreign_fetch_origins_; | 701 std::vector<url::Origin> foreign_fetch_origins_; |
| 690 FetchHandlerExistence fetch_handler_existence_; | 702 FetchHandlerExistence fetch_handler_existence_; |
| 691 ServiceWorkerMetrics::Site site_for_uma_; | 703 ServiceWorkerMetrics::Site site_for_uma_; |
| 692 | 704 |
| 693 Status status_ = NEW; | 705 Status status_ = NEW; |
| 694 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_; | 706 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_; |
| 695 std::vector<StatusCallback> start_callbacks_; | 707 std::vector<StatusCallback> start_callbacks_; |
| 696 std::vector<StatusCallback> stop_callbacks_; | 708 std::vector<StatusCallback> stop_callbacks_; |
| 697 std::vector<base::Closure> status_change_callbacks_; | 709 std::vector<base::Closure> status_change_callbacks_; |
| 698 | 710 |
| 699 // Holds in-flight requests, including requests due to outstanding push, | 711 // Holds in-flight requests, including requests due to outstanding push, |
| 700 // fetch, sync, etc. events. | 712 // fetch, sync, etc. events. |
| 701 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_; | 713 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_; |
| 702 | 714 |
| 715 // Container for pending external requests for this service worker. |
| 716 // (key, value): (request uuid, request id). |
| 717 using RequestUUIDToRequestIDMap = std::map<std::string, int>; |
| 718 RequestUUIDToRequestIDMap external_request_uuid_to_request_id_; |
| 719 |
| 703 // Stores all open connections to mojo services. Maps the service name to | 720 // Stores all open connections to mojo services. Maps the service name to |
| 704 // the actual interface pointer. When a connection is closed it is removed | 721 // the actual interface pointer. When a connection is closed it is removed |
| 705 // from this map. | 722 // from this map. |
| 706 // mojo_services_[Interface::Name_] is assumed to always contain a | 723 // mojo_services_[Interface::Name_] is assumed to always contain a |
| 707 // MojoServiceWrapper<Interface> instance. | 724 // MojoServiceWrapper<Interface> instance. |
| 708 base::ScopedPtrHashMap<const char*, std::unique_ptr<BaseMojoServiceWrapper>> | 725 base::ScopedPtrHashMap<const char*, std::unique_ptr<BaseMojoServiceWrapper>> |
| 709 mojo_services_; | 726 mojo_services_; |
| 710 | 727 |
| 711 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; | 728 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; |
| 712 | 729 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 | 855 |
| 839 // At this point |this| can have been deleted, so don't do anything other | 856 // At this point |this| can have been deleted, so don't do anything other |
| 840 // than returning. | 857 // than returning. |
| 841 | 858 |
| 842 return true; | 859 return true; |
| 843 } | 860 } |
| 844 | 861 |
| 845 } // namespace content | 862 } // namespace content |
| 846 | 863 |
| 847 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 864 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
| OLD | NEW |