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

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

Issue 991743002: Service Worker: Coalesce the start worker timer into the timeout timer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 years, 9 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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 { NOT_PINGING, PINGING, PING_TIMED_OUT };
320
321 // Timeout for the worker to start.
322 static const int kStartWorkerTimeoutMinutes;
323
319 ~ServiceWorkerVersion() override; 324 ~ServiceWorkerVersion() override;
320 325
321 // EmbeddedWorkerInstance::Listener overrides: 326 // EmbeddedWorkerInstance::Listener overrides:
322 void OnScriptLoaded() override; 327 void OnScriptLoaded() override;
323 void OnStarted() override; 328 void OnStarted() override;
324 void OnStopped(EmbeddedWorkerInstance::Status old_status) override; 329 void OnStopped(EmbeddedWorkerInstance::Status old_status) override;
325 void OnReportException(const base::string16& error_message, 330 void OnReportException(const base::string16& error_message,
326 int line_number, 331 int line_number,
327 int column_number, 332 int column_number,
328 const GURL& source_url) override; 333 const GURL& source_url) override;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 398
394 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker 399 // The timeout timer periodically calls OnTimeoutTimer, which stops the worker
395 // if it is excessively idle or unresponsive to ping. 400 // if it is excessively idle or unresponsive to ping.
396 void StartTimeoutTimer(); 401 void StartTimeoutTimer();
397 void StopTimeoutTimer(); 402 void StopTimeoutTimer();
398 void OnTimeoutTimer(); 403 void OnTimeoutTimer();
399 404
400 // The ping protocol is for terminating workers that are taking excessively 405 // The ping protocol is for terminating workers that are taking excessively
401 // long executing JavaScript (e.g., stuck in while(true) {}). Periodically a 406 // 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 407 // ping IPC is sent to the worker context and if we timeout waiting for a
403 // pong, the worker is terminated. 408 // pong, the worker is terminated. Pinging starts after the script is loaded.
404 void PingWorker(); 409 void PingWorker();
405 void OnPingTimeout(); 410 void OnPingTimeout();
406 411
407 // Stops the worker if it is idle (has no in-flight requests) or timed out 412 // Stops the worker if it is idle (has no in-flight requests) or timed out
408 // ping. 413 // ping.
409 void StopWorkerIfIdle(); 414 void StopWorkerIfIdle();
410 bool HasInflightRequests() const; 415 bool HasInflightRequests() const;
411 416
412 // ScheduleStartWorkerTimeout is called when attempting to the start the 417 // RecordStartWorkerResult is added as a start callback by StartTimeoutTimer
413 // embedded worker. It sets a timer for calling OnStartWorkerTimeout, which 418 // 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); 419 void RecordStartWorkerResult(ServiceWorkerStatusCode status);
419 void OnStartWorkerTimeout();
420 420
421 void DoomInternal(); 421 void DoomInternal();
422 422
423 template <typename IDMAP> 423 template <typename IDMAP>
424 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id); 424 void RemoveCallbackAndStopIfDoomed(IDMAP* callbacks, int request_id);
425 425
426 const int64 version_id_; 426 const int64 version_id_;
427 int64 registration_id_; 427 int64 registration_id_;
428 GURL script_url_; 428 GURL script_url_;
429 GURL scope_; 429 GURL scope_;
(...skipping 19 matching lines...) Expand all
449 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; 449 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
450 450
451 ControlleeMap controllee_map_; 451 ControlleeMap controllee_map_;
452 ControlleeByIDMap controllee_by_id_; 452 ControlleeByIDMap controllee_by_id_;
453 // Will be null while shutting down. 453 // Will be null while shutting down.
454 base::WeakPtr<ServiceWorkerContextCore> context_; 454 base::WeakPtr<ServiceWorkerContextCore> context_;
455 ObserverList<Listener> listeners_; 455 ObserverList<Listener> listeners_;
456 ServiceWorkerScriptCacheMap script_cache_map_; 456 ServiceWorkerScriptCacheMap script_cache_map_;
457 base::OneShotTimer<ServiceWorkerVersion> update_timer_; 457 base::OneShotTimer<ServiceWorkerVersion> update_timer_;
458 458
459 // Starts running when the script is loaded (which means it is about to begin 459 // Starts running in StartWorker and continues until the worker is stopped.
460 // evaluation) and continues until the worker is stopped or a stop request is
461 // ignored because DevTools is attached.
462 base::RepeatingTimer<ServiceWorkerVersion> timeout_timer_; 460 base::RepeatingTimer<ServiceWorkerVersion> timeout_timer_;
463 // Holds the time the worker last started being considered idle. 461 // Holds the time the worker last started being considered idle.
464 base::TimeTicks idle_time_; 462 base::TimeTicks idle_time_;
465 // Holds the time that an outstanding ping was sent to the worker. 463 // Holds the time that an outstanding ping was sent to the worker.
466 base::TimeTicks ping_time_; 464 base::TimeTicks ping_time_;
467 // True if the worker was stopped because it did not respond to ping in time. 465 // The state of the ping protocol.
468 bool ping_timed_out_; 466 PingState ping_state_;
469 467 // Holds the time that the outstanding StartWorker() request started.
470 base::OneShotTimer<ServiceWorkerVersion> start_worker_timeout_timer_; 468 base::TimeTicks start_time_;
471 base::TimeTicks start_timing_;
472 469
473 bool is_doomed_; 470 bool is_doomed_;
474 std::vector<int> pending_skip_waiting_requests_; 471 std::vector<int> pending_skip_waiting_requests_;
475 bool skip_waiting_; 472 bool skip_waiting_;
476 scoped_ptr<net::HttpResponseInfo> main_script_http_info_; 473 scoped_ptr<net::HttpResponseInfo> main_script_http_info_;
477 474
478 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; 475 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
479 476
480 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); 477 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
481 }; 478 };
482 479
483 } // namespace content 480 } // namespace content
484 481
485 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 482 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_version.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698