Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: content/browser/service_worker/service_worker_version.h

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from Devlin Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Returns true if the request was successfully scheduled to starrt.
242 bool StartExternalRequest(const std::string& request_uuid);
243
238 // Informs ServiceWorkerVersion that an event has finished being dispatched. 244 // Informs ServiceWorkerVersion that an event has finished being dispatched.
239 // Returns false if no pending requests with the provided id exist, for 245 // Returns false if no pending requests with the provided id exist, for
240 // example if the request has already timed out. 246 // example if the request has already timed out.
241 // Pass the result of the event to |was_handled|, which is used to record 247 // Pass the result of the event to |was_handled|, which is used to record
242 // statistics based on the event status. 248 // statistics based on the event status.
243 // TODO(mek): Use something other than a bool for event status. 249 // TODO(mek): Use something other than a bool for event status.
244 bool FinishRequest(int request_id, 250 bool FinishRequest(int request_id,
245 bool was_handled, 251 bool was_handled,
246 base::Time dispatch_event_time); 252 base::Time dispatch_event_time);
247 253
254 // Finishes an external request that was started by StartExternalRequest().
255 // Returns false if there was an error finishing the request: e.g. the request
256 // was not found or the worker already terminated.
257 bool FinishExternalRequest(const std::string& request_uuid);
258
248 // Connects to a specific mojo service exposed by the (running) service 259 // 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 260 // 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 261 // this will return that existing connection. The |request_id| must be a value
251 // previously returned by StartRequest. If the connection to the service 262 // previously returned by StartRequest. If the connection to the service
252 // fails or closes before the request finished, the error callback associated 263 // fails or closes before the request finished, the error callback associated
253 // with |request_id| is called. 264 // with |request_id| is called.
254 // Only call GetMojoServiceForRequest once for a specific |request_id|. 265 // Only call GetMojoServiceForRequest once for a specific |request_id|.
255 template <typename Interface> 266 template <typename Interface>
256 base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id); 267 base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id);
257 268
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 685
675 // Called at the beginning of each Dispatch*Event function: records 686 // Called at the beginning of each Dispatch*Event function: records
676 // the time elapsed since idle (generally the time since the previous 687 // the time elapsed since idle (generally the time since the previous
677 // event ended). 688 // event ended).
678 void OnBeginEvent(); 689 void OnBeginEvent();
679 690
680 // Resets |start_worker_first_purpose_| and fires and clears all start 691 // Resets |start_worker_first_purpose_| and fires and clears all start
681 // callbacks. 692 // callbacks.
682 void FinishStartWorker(ServiceWorkerStatusCode status); 693 void FinishStartWorker(ServiceWorkerStatusCode status);
683 694
695 // Removes any pending external request that has GUID of |request_uuid|.
696 void CleanUpExternalRequest(const std::string& request_uuid,
697 ServiceWorkerStatusCode status);
698
684 const int64_t version_id_; 699 const int64_t version_id_;
685 const int64_t registration_id_; 700 const int64_t registration_id_;
686 const GURL script_url_; 701 const GURL script_url_;
687 const GURL scope_; 702 const GURL scope_;
688 std::vector<GURL> foreign_fetch_scopes_; 703 std::vector<GURL> foreign_fetch_scopes_;
689 std::vector<url::Origin> foreign_fetch_origins_; 704 std::vector<url::Origin> foreign_fetch_origins_;
690 FetchHandlerExistence fetch_handler_existence_; 705 FetchHandlerExistence fetch_handler_existence_;
691 ServiceWorkerMetrics::Site site_for_uma_; 706 ServiceWorkerMetrics::Site site_for_uma_;
692 707
693 Status status_ = NEW; 708 Status status_ = NEW;
694 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_; 709 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_;
695 std::vector<StatusCallback> start_callbacks_; 710 std::vector<StatusCallback> start_callbacks_;
696 std::vector<StatusCallback> stop_callbacks_; 711 std::vector<StatusCallback> stop_callbacks_;
697 std::vector<base::Closure> status_change_callbacks_; 712 std::vector<base::Closure> status_change_callbacks_;
698 713
699 // Holds in-flight requests, including requests due to outstanding push, 714 // Holds in-flight requests, including requests due to outstanding push,
700 // fetch, sync, etc. events. 715 // fetch, sync, etc. events.
701 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_; 716 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_;
702 717
718 // Container for pending external requests for this service worker.
719 // (key, value): (request uuid, request id).
720 using RequestUUIDToRequestIDMap = std::map<std::string, int>;
721 RequestUUIDToRequestIDMap external_request_uuid_to_request_id_;
722
703 // Stores all open connections to mojo services. Maps the service name to 723 // 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 724 // the actual interface pointer. When a connection is closed it is removed
705 // from this map. 725 // from this map.
706 // mojo_services_[Interface::Name_] is assumed to always contain a 726 // mojo_services_[Interface::Name_] is assumed to always contain a
707 // MojoServiceWrapper<Interface> instance. 727 // MojoServiceWrapper<Interface> instance.
708 base::ScopedPtrHashMap<const char*, std::unique_ptr<BaseMojoServiceWrapper>> 728 base::ScopedPtrHashMap<const char*, std::unique_ptr<BaseMojoServiceWrapper>>
709 mojo_services_; 729 mojo_services_;
710 730
711 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; 731 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
712 732
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 858
839 // At this point |this| can have been deleted, so don't do anything other 859 // At this point |this| can have been deleted, so don't do anything other
840 // than returning. 860 // than returning.
841 861
842 return true; 862 return true;
843 } 863 }
844 864
845 } // namespace content 865 } // namespace content
846 866
847 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 867 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698