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

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

Issue 2164113003: [M53] service worker: Wait for inflight requests before activating (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 int source_identifier, 102 int source_identifier,
103 int message_level, 103 int message_level,
104 const base::string16& message, 104 const base::string16& message,
105 int line_number, 105 int line_number,
106 const GURL& source_url) {} 106 const GURL& source_url) {}
107 virtual void OnControlleeAdded(ServiceWorkerVersion* version, 107 virtual void OnControlleeAdded(ServiceWorkerVersion* version,
108 ServiceWorkerProviderHost* provider_host) {} 108 ServiceWorkerProviderHost* provider_host) {}
109 virtual void OnControlleeRemoved(ServiceWorkerVersion* version, 109 virtual void OnControlleeRemoved(ServiceWorkerVersion* version,
110 ServiceWorkerProviderHost* provider_host) { 110 ServiceWorkerProviderHost* provider_host) {
111 } 111 }
112 // Fires when a version transitions from having a controllee to not.
113 virtual void OnNoControllees(ServiceWorkerVersion* version) {} 112 virtual void OnNoControllees(ServiceWorkerVersion* version) {}
113 virtual void OnNoWork(ServiceWorkerVersion* version) {}
114 virtual void OnCachedMetadataUpdated(ServiceWorkerVersion* version) {} 114 virtual void OnCachedMetadataUpdated(ServiceWorkerVersion* version) {}
115 115
116 protected: 116 protected:
117 virtual ~Listener() {} 117 virtual ~Listener() {}
118 }; 118 };
119 119
120 ServiceWorkerVersion(ServiceWorkerRegistration* registration, 120 ServiceWorkerVersion(ServiceWorkerRegistration* registration,
121 const GURL& script_url, 121 const GURL& script_url,
122 int64_t version_id, 122 int64_t version_id,
123 base::WeakPtr<ServiceWorkerContextCore> context); 123 base::WeakPtr<ServiceWorkerContextCore> context);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // RegisterRequestCallback/DispatchEvent is not needed, this method can be 267 // RegisterRequestCallback/DispatchEvent is not needed, this method can be
268 // used instead. The ResponseMessage must consist 268 // used instead. The ResponseMessage must consist
269 // of just a request_id and a blink::WebServiceWorkerEventResult field. The 269 // of just a request_id and a blink::WebServiceWorkerEventResult field. The
270 // result is converted to a ServiceWorkerStatusCode and passed to the error 270 // result is converted to a ServiceWorkerStatusCode and passed to the error
271 // handler associated with the request. Additionally this methods calls 271 // handler associated with the request. Additionally this methods calls
272 // FinishRequest before passing the reply to the callback. 272 // FinishRequest before passing the reply to the callback.
273 template <typename ResponseMessage> 273 template <typename ResponseMessage>
274 void DispatchSimpleEvent(int request_id, const IPC::Message& message); 274 void DispatchSimpleEvent(int request_id, const IPC::Message& message);
275 275
276 // Adds and removes |provider_host| as a controllee of this ServiceWorker. 276 // Adds and removes |provider_host| as a controllee of this ServiceWorker.
277 // A potential controllee is a host having the version as its .installing
278 // or .waiting version.
279 void AddControllee(ServiceWorkerProviderHost* provider_host); 277 void AddControllee(ServiceWorkerProviderHost* provider_host);
280 void RemoveControllee(ServiceWorkerProviderHost* provider_host); 278 void RemoveControllee(ServiceWorkerProviderHost* provider_host);
281 279
282 // Returns if it has controllee. 280 // Returns if it has controllee.
283 bool HasControllee() const { return !controllee_map_.empty(); } 281 bool HasControllee() const { return !controllee_map_.empty(); }
284 std::map<std::string, ServiceWorkerProviderHost*> controllee_map() { 282 std::map<std::string, ServiceWorkerProviderHost*> controllee_map() {
285 return controllee_map_; 283 return controllee_map_;
286 } 284 }
287 285
288 base::WeakPtr<ServiceWorkerContextCore> context() const { return context_; } 286 base::WeakPtr<ServiceWorkerContextCore> context() const { return context_; }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // Sets the HttpResponseInfo used to load the main script. 335 // Sets the HttpResponseInfo used to load the main script.
338 // This HttpResponseInfo will be used for all responses sent back from the 336 // This HttpResponseInfo will be used for all responses sent back from the
339 // service worker, as the effective security of these responses is equivalent 337 // service worker, as the effective security of these responses is equivalent
340 // to that of the ServiceWorker. 338 // to that of the ServiceWorker.
341 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info); 339 void SetMainScriptHttpResponseInfo(const net::HttpResponseInfo& http_info);
342 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo(); 340 const net::HttpResponseInfo* GetMainScriptHttpResponseInfo();
343 341
344 // Simulate ping timeout. Should be used for tests-only. 342 // Simulate ping timeout. Should be used for tests-only.
345 void SimulatePingTimeoutForTesting(); 343 void SimulatePingTimeoutForTesting();
346 344
345 // Returns true if the service worker has work to do: it has pending
346 // requests, in-progress streaming URLRequestJobs, or pending start callbacks.
347 bool HasWork() const;
348
347 private: 349 private:
348 friend class base::RefCounted<ServiceWorkerVersion>; 350 friend class base::RefCounted<ServiceWorkerVersion>;
349 friend class ServiceWorkerMetrics; 351 friend class ServiceWorkerMetrics;
350 friend class ServiceWorkerReadFromCacheJobTest; 352 friend class ServiceWorkerReadFromCacheJobTest;
351 friend class ServiceWorkerStallInStoppingTest; 353 friend class ServiceWorkerStallInStoppingTest;
352 friend class ServiceWorkerURLRequestJobTest; 354 friend class ServiceWorkerURLRequestJobTest;
353 friend class ServiceWorkerVersionBrowserTest; 355 friend class ServiceWorkerVersionBrowserTest;
354 friend class ServiceWorkerVersionTest; 356 friend class ServiceWorkerVersionTest;
355 357
356 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, 358 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
(...skipping 16 matching lines...) Expand all
373 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart); 375 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenStart);
374 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart); 376 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerStallInStoppingTest, DetachThenRestart);
375 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, 377 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest,
376 RegisterForeignFetchScopes); 378 RegisterForeignFetchScopes);
377 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout); 379 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, RequestCustomizedTimeout);
378 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, 380 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest,
379 RequestCustomizedTimeoutKill); 381 RequestCustomizedTimeoutKill);
380 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts); 382 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, MixedRequestTimeouts);
381 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse); 383 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, EarlyResponse);
382 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest); 384 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerURLRequestJobTest, CancelRequest);
385 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest, SkipWaiting);
386 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerActivationTest,
387 SkipWaitingWithInflightRequest);
383 388
384 class Metrics; 389 class Metrics;
385 class PingController; 390 class PingController;
386 391
387 struct RequestInfo { 392 struct RequestInfo {
388 RequestInfo(int id, 393 RequestInfo(int id,
389 ServiceWorkerMetrics::EventType event_type, 394 ServiceWorkerMetrics::EventType event_type,
390 const base::TimeTicks& expiration, 395 const base::TimeTicks& expiration,
391 TimeoutBehavior timeout_behavior); 396 TimeoutBehavior timeout_behavior);
392 ~RequestInfo(); 397 ~RequestInfo();
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 void OnTimeoutTimer(); 592 void OnTimeoutTimer();
588 void SetTimeoutTimerInterval(base::TimeDelta interval); 593 void SetTimeoutTimerInterval(base::TimeDelta interval);
589 594
590 // Called by PingController for ping protocol. 595 // Called by PingController for ping protocol.
591 ServiceWorkerStatusCode PingWorker(); 596 ServiceWorkerStatusCode PingWorker();
592 void OnPingTimeout(); 597 void OnPingTimeout();
593 598
594 // Stops the worker if it is idle (has no in-flight requests) or timed out 599 // Stops the worker if it is idle (has no in-flight requests) or timed out
595 // ping. 600 // ping.
596 void StopWorkerIfIdle(); 601 void StopWorkerIfIdle();
597 bool HasInflightRequests() const;
598 602
599 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer 603 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer
600 // and records metrics about startup. 604 // and records metrics about startup.
601 void RecordStartWorkerResult(ServiceWorkerMetrics::EventType purpose, 605 void RecordStartWorkerResult(ServiceWorkerMetrics::EventType purpose,
602 Status prestart_status, 606 Status prestart_status,
603 int trace_id, 607 int trace_id,
604 bool is_browser_startup_complete, 608 bool is_browser_startup_complete,
605 ServiceWorkerStatusCode status); 609 ServiceWorkerStatusCode status);
606 610
607 bool MaybeTimeOutRequest(const RequestInfo& info); 611 bool MaybeTimeOutRequest(const RequestInfo& info);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 787
784 // At this point |this| can have been deleted, so don't do anything other 788 // At this point |this| can have been deleted, so don't do anything other
785 // than returning. 789 // than returning.
786 790
787 return true; 791 return true;
788 } 792 }
789 793
790 } // namespace content 794 } // namespace content
791 795
792 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 796 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698