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

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: sync@tott 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 int StartRequest(ServiceWorkerMetrics::EventType event_type, 229 int StartRequest(ServiceWorkerMetrics::EventType event_type,
230 const StatusCallback& error_callback); 230 const StatusCallback& error_callback);
231 231
232 // Same as StartRequest, but allows the caller to specify a custom timeout for 232 // Same as StartRequest, but allows the caller to specify a custom timeout for
233 // the event, as well as the behavior for when the request times out. 233 // the event, as well as the behavior for when the request times out.
234 int StartRequestWithCustomTimeout(ServiceWorkerMetrics::EventType event_type, 234 int StartRequestWithCustomTimeout(ServiceWorkerMetrics::EventType event_type,
235 const StatusCallback& error_callback, 235 const StatusCallback& error_callback,
236 const base::TimeDelta& timeout, 236 const base::TimeDelta& timeout,
237 TimeoutBehavior timeout_behavior); 237 TimeoutBehavior timeout_behavior);
238 238
239 // Starts a request of type EventType::EXTERNAL_REQUEST.
240 // Provides a mechanism to external clients to keep the worker running.
241 // |request_uuid| is a GUID for clients to identify the request.
242 // Returns true if the request was successfully scheduled to starrt.
243 bool StartExternalRequest(const std::string& request_uuid);
244
239 // Informs ServiceWorkerVersion that an event has finished being dispatched. 245 // Informs ServiceWorkerVersion that an event has finished being dispatched.
240 // Returns false if no pending requests with the provided id exist, for 246 // Returns false if no pending requests with the provided id exist, for
241 // example if the request has already timed out. 247 // example if the request has already timed out.
242 // Pass the result of the event to |was_handled|, which is used to record 248 // Pass the result of the event to |was_handled|, which is used to record
243 // statistics based on the event status. 249 // statistics based on the event status.
244 // TODO(mek): Use something other than a bool for event status. 250 // TODO(mek): Use something other than a bool for event status.
245 bool FinishRequest(int request_id, 251 bool FinishRequest(int request_id,
246 bool was_handled, 252 bool was_handled,
247 base::Time dispatch_event_time); 253 base::Time dispatch_event_time);
248 254
255 // Finishes an external request that was started by StartExternalRequest().
256 // Returns false if there was an error finishing the request: e.g. the request
257 // was not found or the worker already terminated.
258 bool FinishExternalRequest(const std::string& request_uuid);
259
249 // Connects to a specific mojo service exposed by the (running) service 260 // Connects to a specific mojo service exposed by the (running) service
250 // worker. If a connection to a service for the same Interface already exists 261 // worker. If a connection to a service for the same Interface already exists
251 // this will return that existing connection. The |request_id| must be a value 262 // this will return that existing connection. The |request_id| must be a value
252 // previously returned by StartRequest. If the connection to the service 263 // previously returned by StartRequest. If the connection to the service
253 // fails or closes before the request finished, the error callback associated 264 // fails or closes before the request finished, the error callback associated
254 // with |request_id| is called. 265 // with |request_id| is called.
255 // Only call GetMojoServiceForRequest once for a specific |request_id|. 266 // Only call GetMojoServiceForRequest once for a specific |request_id|.
256 template <typename Interface> 267 template <typename Interface>
257 base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id); 268 base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id);
258 269
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info); 387 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info);
377 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo(); 388 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo();
378 389
379 // Simulate ping timeout. Should be used for tests-only. 390 // Simulate ping timeout. Should be used for tests-only.
380 void SimulatePingTimeoutForTesting(); 391 void SimulatePingTimeoutForTesting();
381 392
382 // Returns true if the service worker has work to do: it has pending 393 // Returns true if the service worker has work to do: it has pending
383 // requests, in-progress streaming URLRequestJobs, or pending start callbacks. 394 // requests, in-progress streaming URLRequestJobs, or pending start callbacks.
384 bool HasWork() const; 395 bool HasWork() const;
385 396
397 // Returns the number of pending external request count of this worker.
398 size_t GetExternalRequestCountForTest() const {
399 return external_request_uuid_to_request_id_.size();
400 }
401
386 private: 402 private:
387 friend class base::RefCounted<ServiceWorkerVersion>; 403 friend class base::RefCounted<ServiceWorkerVersion>;
388 friend class ServiceWorkerMetrics; 404 friend class ServiceWorkerMetrics;
389 friend class ServiceWorkerReadFromCacheJobTest; 405 friend class ServiceWorkerReadFromCacheJobTest;
390 friend class ServiceWorkerStallInStoppingTest; 406 friend class ServiceWorkerStallInStoppingTest;
391 friend class ServiceWorkerURLRequestJobTest; 407 friend class ServiceWorkerURLRequestJobTest;
392 friend class ServiceWorkerVersionBrowserTest; 408 friend class ServiceWorkerVersionBrowserTest;
393 friend class ServiceWorkerVersionTest; 409 friend class ServiceWorkerVersionTest;
394 410
395 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, 411 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 704
689 // Called at the beginning of each Dispatch*Event function: records 705 // Called at the beginning of each Dispatch*Event function: records
690 // the time elapsed since idle (generally the time since the previous 706 // the time elapsed since idle (generally the time since the previous
691 // event ended). 707 // event ended).
692 void OnBeginEvent(); 708 void OnBeginEvent();
693 709
694 // Resets |start_worker_first_purpose_| and fires and clears all start 710 // Resets |start_worker_first_purpose_| and fires and clears all start
695 // callbacks. 711 // callbacks.
696 void FinishStartWorker(ServiceWorkerStatusCode status); 712 void FinishStartWorker(ServiceWorkerStatusCode status);
697 713
714 // Removes any pending external request that has GUID of |request_uuid|.
715 void CleanUpExternalRequest(const std::string& request_uuid,
716 ServiceWorkerStatusCode status);
717
698 const int64_t version_id_; 718 const int64_t version_id_;
699 const int64_t registration_id_; 719 const int64_t registration_id_;
700 const GURL script_url_; 720 const GURL script_url_;
701 const GURL scope_; 721 const GURL scope_;
702 std::vector<GURL> foreign_fetch_scopes_; 722 std::vector<GURL> foreign_fetch_scopes_;
703 std::vector<url::Origin> foreign_fetch_origins_; 723 std::vector<url::Origin> foreign_fetch_origins_;
704 FetchHandlerExistence fetch_handler_existence_; 724 FetchHandlerExistence fetch_handler_existence_;
705 ServiceWorkerMetrics::Site site_for_uma_; 725 ServiceWorkerMetrics::Site site_for_uma_;
706 726
707 Status status_ = NEW; 727 Status status_ = NEW;
708 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_; 728 std::unique_ptr<EmbeddedWorkerInstance> embedded_worker_;
709 std::vector<StatusCallback> start_callbacks_; 729 std::vector<StatusCallback> start_callbacks_;
710 std::vector<StatusCallback> stop_callbacks_; 730 std::vector<StatusCallback> stop_callbacks_;
711 std::vector<base::Closure> status_change_callbacks_; 731 std::vector<base::Closure> status_change_callbacks_;
712 732
713 // Holds in-flight requests, including requests due to outstanding push, 733 // Holds in-flight requests, including requests due to outstanding push,
714 // fetch, sync, etc. events. 734 // fetch, sync, etc. events.
715 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_; 735 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_;
716 736
737 // Container for pending external requests for this service worker.
738 // (key, value): (request uuid, request id).
739 using RequestUUIDToRequestIDMap = std::map<std::string, int>;
740 RequestUUIDToRequestIDMap external_request_uuid_to_request_id_;
741
717 // Stores all open connections to mojo services. Maps the service name to 742 // Stores all open connections to mojo services. Maps the service name to
718 // the actual interface pointer. When a connection is closed it is removed 743 // the actual interface pointer. When a connection is closed it is removed
719 // from this map. 744 // from this map.
720 // mojo_services_[Interface::Name_] is assumed to always contain a 745 // mojo_services_[Interface::Name_] is assumed to always contain a
721 // MojoServiceWrapper<Interface> instance. 746 // MojoServiceWrapper<Interface> instance.
722 base::ScopedPtrHashMap<const char*, std::unique_ptr<BaseMojoServiceWrapper>> 747 base::ScopedPtrHashMap<const char*, std::unique_ptr<BaseMojoServiceWrapper>>
723 mojo_services_; 748 mojo_services_;
724 749
725 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; 750 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
726 751
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 879
855 // At this point |this| can have been deleted, so don't do anything other 880 // At this point |this| can have been deleted, so don't do anything other
856 // than returning. 881 // than returning.
857 882
858 return true; 883 return true;
859 } 884 }
860 885
861 } // namespace content 886 } // namespace content
862 887
863 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 888 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_metrics.cc ('k') | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698