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 <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, | 309 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
310 TimeoutStartingWorker); | 310 TimeoutStartingWorker); |
311 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, | 311 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionBrowserTest, |
312 TimeoutWorkerInEvent); | 312 TimeoutWorkerInEvent); |
313 friend class ServiceWorkerVersionBrowserTest; | 313 friend class ServiceWorkerVersionBrowserTest; |
314 | 314 |
315 typedef ServiceWorkerVersion self; | 315 typedef ServiceWorkerVersion self; |
316 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; | 316 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; |
317 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; | 317 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; |
318 | 318 |
| 319 enum PingState { PING_NOT_STARTED, PING_STARTED, PING_TIMED_OUT }; |
| 320 |
319 ~ServiceWorkerVersion() override; | 321 ~ServiceWorkerVersion() override; |
320 | 322 |
321 // EmbeddedWorkerInstance::Listener overrides: | 323 // EmbeddedWorkerInstance::Listener overrides: |
322 void OnScriptLoaded() override; | 324 void OnScriptLoaded() override; |
323 void OnStarted() override; | 325 void OnStarted() override; |
324 void OnStopped(EmbeddedWorkerInstance::Status old_status) override; | 326 void OnStopped(EmbeddedWorkerInstance::Status old_status) override; |
325 void OnReportException(const base::string16& error_message, | 327 void OnReportException(const base::string16& error_message, |
326 int line_number, | 328 int line_number, |
327 int column_number, | 329 int column_number, |
328 const GURL& source_url) override; | 330 const GURL& source_url) override; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 395 |
394 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker | 396 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker |
395 // if it is excessively idle or unresponsive to ping. | 397 // if it is excessively idle or unresponsive to ping. |
396 void StartTimeoutTimer(); | 398 void StartTimeoutTimer(); |
397 void StopTimeoutTimer(); | 399 void StopTimeoutTimer(); |
398 void OnTimeoutTimer(); | 400 void OnTimeoutTimer(); |
399 | 401 |
400 // The ping protocol is for terminating workers that are taking excessively | 402 // The ping protocol is for terminating workers that are taking excessively |
401 // long executing JavaScript (e.g., stuck in while(true) {}). Periodically a | 403 // long executing JavaScript (e.g., stuck in while(true) {}). Periodically a |
402 // ping IPC is sent to the worker context and if we timeout waiting for a | 404 // ping IPC is sent to the worker context and if we timeout waiting for a |
403 // pong, the worker is terminated. | 405 // pong, the worker is terminated. Pinging starts after the script is loaded. |
404 void PingWorker(); | 406 void PingWorker(); |
405 void OnPingTimeout(); | 407 void OnPingTimeout(); |
406 | 408 |
407 // Stops the worker if it is idle (has no in-flight requests) or timed out | 409 // Stops the worker if it is idle (has no in-flight requests) or timed out |
408 // ping. | 410 // ping. |
409 void StopWorkerIfIdle(); | 411 void StopWorkerIfIdle(); |
410 bool HasInflightRequests() const; | 412 bool HasInflightRequests() const; |
411 | 413 |
412 // ScheduleStartWorkerTimeout is called when attempting to the start the | 414 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer |
413 // embedded worker. It sets a timer for calling OnStartWorkerTimeout, which | 415 // and records metrics about startup. |
414 // invokes start callbacks with ERROR_TIMEOUT. It also adds its own start | |
415 // callback RecordStartWorkerResult which cancels the timer and records | |
416 // metrics about startup. | |
417 void ScheduleStartWorkerTimeout(); | |
418 void RecordStartWorkerResult(ServiceWorkerStatusCode status); | 416 void RecordStartWorkerResult(ServiceWorkerStatusCode status); |
419 void OnStartWorkerTimeout(); | |
420 | 417 |
421 void DoomInternal(); | 418 void DoomInternal(); |
422 | 419 |
423 template <typename IDMAP> | 420 template <typename IDMAP> |
424 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id); | 421 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id); |
425 | 422 |
426 const int64 version_id_; | 423 const int64 version_id_; |
427 int64 registration_id_; | 424 int64 registration_id_; |
428 GURL script_url_; | 425 GURL script_url_; |
429 GURL scope_; | 426 GURL scope_; |
(...skipping 19 matching lines...) Expand all Loading... |
449 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; | 446 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; |
450 | 447 |
451 ControlleeMap controllee_map_; | 448 ControlleeMap controllee_map_; |
452 ControlleeByIDMap controllee_by_id_; | 449 ControlleeByIDMap controllee_by_id_; |
453 // Will be null while shutting down. | 450 // Will be null while shutting down. |
454 base::WeakPtr<ServiceWorkerContextCore> context_; | 451 base::WeakPtr<ServiceWorkerContextCore> context_; |
455 ObserverList<Listener> listeners_; | 452 ObserverList<Listener> listeners_; |
456 ServiceWorkerScriptCacheMap script_cache_map_; | 453 ServiceWorkerScriptCacheMap script_cache_map_; |
457 base::OneShotTimer<ServiceWorkerVersion> update_timer_; | 454 base::OneShotTimer<ServiceWorkerVersion> update_timer_; |
458 | 455 |
459 // Starts running when the script is loaded (which means it is about to begin | 456 // Starts running in StartWorker and continues until the worker is stopped or |
460 // evaluation) and continues until the worker is stopped or a stop request is | 457 // a stop request is ignored because DevTools is attached. |
461 // ignored because DevTools is attached. | |
462 base::RepeatingTimer<ServiceWorkerVersion> timeout_timer_; | 458 base::RepeatingTimer<ServiceWorkerVersion> timeout_timer_; |
463 // Holds the time the worker last started being considered idle. | 459 // Holds the time the worker last started being considered idle. |
464 base::TimeTicks idle_time_; | 460 base::TimeTicks idle_time_; |
465 // Holds the time that an outstanding ping was sent to the worker. | 461 // Holds the time that an outstanding ping was sent to the worker. |
466 base::TimeTicks ping_time_; | 462 base::TimeTicks ping_time_; |
467 // True if the worker was stopped because it did not respond to ping in time. | 463 // The state of the ping protocol. |
468 bool ping_timed_out_; | 464 PingState ping_state_; |
469 | 465 // Holds the time that the outstanding StartWorker() request started. |
470 base::OneShotTimer<ServiceWorkerVersion> start_worker_timeout_timer_; | 466 base::TimeTicks start_time_; |
471 base::TimeTicks start_timing_; | |
472 | 467 |
473 bool is_doomed_; | 468 bool is_doomed_; |
474 std::vector<int> pending_skip_waiting_requests_; | 469 std::vector<int> pending_skip_waiting_requests_; |
475 bool skip_waiting_; | 470 bool skip_waiting_; |
476 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; | 471 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; |
477 | 472 |
478 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 473 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
479 | 474 |
480 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 475 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
481 }; | 476 }; |
482 | 477 |
483 } // namespace content | 478 } // namespace content |
484 | 479 |
485 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 480 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |