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 <map> | 8 #include <map> |
9 #include <queue> | 9 #include <queue> |
10 #include <set> | 10 #include <set> |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 335 |
336 private: | 336 private: |
337 friend class base::RefCounted<ServiceWorkerVersion>; | 337 friend class base::RefCounted<ServiceWorkerVersion>; |
338 friend class ServiceWorkerURLRequestJobTest; | 338 friend class ServiceWorkerURLRequestJobTest; |
339 friend class ServiceWorkerVersionBrowserTest; | 339 friend class ServiceWorkerVersionBrowserTest; |
340 | 340 |
341 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, | 341 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, |
342 ActivateWaitingVersion); | 342 ActivateWaitingVersion); |
343 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, IdleTimeout); | 343 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, IdleTimeout); |
344 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, SetDevToolsAttached); | 344 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, SetDevToolsAttached); |
| 345 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_FreshWorker); |
| 346 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 347 StaleUpdate_NonActiveWorker); |
| 348 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_StartWorker); |
| 349 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, StaleUpdate_RunningWorker); |
| 350 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, |
| 351 StaleUpdate_DoNotDeferTimer); |
345 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, RequestTimeout); | 352 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerWaitForeverInFetchTest, RequestTimeout); |
346 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout); | 353 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerFailToStartTest, Timeout); |
347 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, | 354 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
348 TimeoutStartingWorker); | 355 TimeoutStartingWorker); |
349 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, | 356 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
350 TimeoutWorkerInEvent); | 357 TimeoutWorkerInEvent); |
351 | 358 |
352 class Metrics; | 359 class Metrics; |
353 class PingController; | 360 class PingController; |
354 | 361 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 512 |
506 bool OnRequestTimeout(const RequestInfo& info); | 513 bool OnRequestTimeout(const RequestInfo& info); |
507 void SetAllRequestTimes(const base::TimeTicks& ticks); | 514 void SetAllRequestTimes(const base::TimeTicks& ticks); |
508 | 515 |
509 // Returns the reason the embedded worker failed to start, using information | 516 // Returns the reason the embedded worker failed to start, using information |
510 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't | 517 // inaccessible to EmbeddedWorkerInstance. Returns |default_code| if it can't |
511 // deduce a reason. | 518 // deduce a reason. |
512 ServiceWorkerStatusCode DeduceStartWorkerFailureReason( | 519 ServiceWorkerStatusCode DeduceStartWorkerFailureReason( |
513 ServiceWorkerStatusCode default_code); | 520 ServiceWorkerStatusCode default_code); |
514 | 521 |
| 522 // Sets |stale_time_| if this worker is stale, causing an update to eventually |
| 523 // occur once the worker stops or is running too long. |
| 524 void MarkIfStale(); |
| 525 |
| 526 void FoundRegistrationForUpdate( |
| 527 ServiceWorkerStatusCode status, |
| 528 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 529 |
515 const int64 version_id_; | 530 const int64 version_id_; |
516 const int64 registration_id_; | 531 const int64 registration_id_; |
517 const GURL script_url_; | 532 const GURL script_url_; |
518 const GURL scope_; | 533 const GURL scope_; |
519 | 534 |
520 Status status_ = NEW; | 535 Status status_ = NEW; |
521 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; | 536 scoped_ptr<EmbeddedWorkerInstance> embedded_worker_; |
522 std::vector<StatusCallback> start_callbacks_; | 537 std::vector<StatusCallback> start_callbacks_; |
523 std::vector<StatusCallback> stop_callbacks_; | 538 std::vector<StatusCallback> stop_callbacks_; |
524 std::vector<base::Closure> status_change_callbacks_; | 539 std::vector<base::Closure> status_change_callbacks_; |
(...skipping 18 matching lines...) Expand all Loading... |
543 base::ObserverList<Listener> listeners_; | 558 base::ObserverList<Listener> listeners_; |
544 ServiceWorkerScriptCacheMap script_cache_map_; | 559 ServiceWorkerScriptCacheMap script_cache_map_; |
545 base::OneShotTimer<ServiceWorkerVersion> update_timer_; | 560 base::OneShotTimer<ServiceWorkerVersion> update_timer_; |
546 | 561 |
547 // Starts running in StartWorker and continues until the worker is stopped. | 562 // Starts running in StartWorker and continues until the worker is stopped. |
548 base::RepeatingTimer<ServiceWorkerVersion> timeout_timer_; | 563 base::RepeatingTimer<ServiceWorkerVersion> timeout_timer_; |
549 // Holds the time the worker last started being considered idle. | 564 // Holds the time the worker last started being considered idle. |
550 base::TimeTicks idle_time_; | 565 base::TimeTicks idle_time_; |
551 // Holds the time that the outstanding StartWorker() request started. | 566 // Holds the time that the outstanding StartWorker() request started. |
552 base::TimeTicks start_time_; | 567 base::TimeTicks start_time_; |
| 568 // Holds the time the worker was detected as stale and needs updating. We try |
| 569 // to update once the worker stops, but will also update if it stays alive too |
| 570 // long. |
| 571 base::TimeTicks stale_time_; |
553 | 572 |
554 // New requests are added to |requests_| along with their entry in a callback | 573 // New requests are added to |requests_| along with their entry in a callback |
555 // map. The timeout timer periodically checks |requests_| for entries that | 574 // map. The timeout timer periodically checks |requests_| for entries that |
556 // should time out or have already been fulfilled (i.e., removed from the | 575 // should time out or have already been fulfilled (i.e., removed from the |
557 // callback map). | 576 // callback map). |
558 std::queue<RequestInfo> requests_; | 577 std::queue<RequestInfo> requests_; |
559 | 578 |
560 bool skip_waiting_ = false; | 579 bool skip_waiting_ = false; |
561 bool skip_recording_startup_time_ = false; | 580 bool skip_recording_startup_time_ = false; |
562 bool force_bypass_cache_for_scripts_ = false; | 581 bool force_bypass_cache_for_scripts_ = false; |
| 582 bool is_update_scheduled_ = false; |
563 | 583 |
564 std::vector<int> pending_skip_waiting_requests_; | 584 std::vector<int> pending_skip_waiting_requests_; |
565 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; | 585 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; |
566 | 586 |
567 // The status when StartWorker was invoked. Used for UMA. | 587 // The status when StartWorker was invoked. Used for UMA. |
568 Status prestart_status_ = NEW; | 588 Status prestart_status_ = NEW; |
569 // If not OK, the reason that StartWorker failed. Used for | 589 // If not OK, the reason that StartWorker failed. Used for |
570 // running |start_callbacks_|. | 590 // running |start_callbacks_|. |
571 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK; | 591 ServiceWorkerStatusCode start_worker_status_ = SERVICE_WORKER_OK; |
572 | 592 |
573 scoped_ptr<PingController> ping_controller_; | 593 scoped_ptr<PingController> ping_controller_; |
574 scoped_ptr<Metrics> metrics_; | 594 scoped_ptr<Metrics> metrics_; |
575 | 595 |
576 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 596 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
577 | 597 |
578 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 598 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
579 }; | 599 }; |
580 | 600 |
581 } // namespace content | 601 } // namespace content |
582 | 602 |
583 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 603 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |