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

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

Issue 1731073002: Relax timeout for starting a service worker from 10 sec to 1 minute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | no next file » | 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 #include "content/browser/service_worker/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 case ServiceWorkerVersion::ACTIVATED: 198 case ServiceWorkerVersion::ACTIVATED:
199 return true; 199 return true;
200 } 200 }
201 NOTREACHED() << "Unexpected status: " << status; 201 NOTREACHED() << "Unexpected status: " << status;
202 return false; 202 return false;
203 } 203 }
204 204
205 } // namespace 205 } // namespace
206 206
207 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30; 207 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30;
208 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 10; 208 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60;
209 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5; 209 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5;
210 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; 210 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5;
211 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5; 211 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5;
212 212
213 class ServiceWorkerVersion::Metrics { 213 class ServiceWorkerVersion::Metrics {
214 public: 214 public:
215 using EventType = ServiceWorkerMetrics::EventType; 215 using EventType = ServiceWorkerMetrics::EventType;
216 explicit Metrics(ServiceWorkerVersion* owner) : owner_(owner) {} 216 explicit Metrics(ServiceWorkerVersion* owner) : owner_(owner) {}
217 ~Metrics() { 217 ~Metrics() {
218 if (owner_->should_exclude_from_uma_) 218 if (owner_->should_exclude_from_uma_)
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 } 801 }
802 802
803 void ServiceWorkerVersion::OnStarting() { 803 void ServiceWorkerVersion::OnStarting() {
804 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 804 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
805 } 805 }
806 806
807 void ServiceWorkerVersion::OnStarted() { 807 void ServiceWorkerVersion::OnStarted() {
808 DCHECK_EQ(RUNNING, running_status()); 808 DCHECK_EQ(RUNNING, running_status());
809 RestartTick(&idle_time_); 809 RestartTick(&idle_time_);
810 810
811 // Reset the interval to normal. If may have been shortened so starting an
812 // existing worker can timeout quickly.
813 SetTimeoutTimerInterval(
814 base::TimeDelta::FromSeconds(kTimeoutTimerDelaySeconds));
815
816 // Fire all start callbacks. 811 // Fire all start callbacks.
817 scoped_refptr<ServiceWorkerVersion> protect(this); 812 scoped_refptr<ServiceWorkerVersion> protect(this);
818 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK); 813 RunCallbacks(this, &start_callbacks_, SERVICE_WORKER_OK);
819 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); 814 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this));
820 } 815 }
821 816
822 void ServiceWorkerVersion::OnStopping() { 817 void ServiceWorkerVersion::OnStopping() {
823 DCHECK(stop_time_.is_null()); 818 DCHECK(stop_time_.is_null());
824 RestartTick(&stop_time_); 819 RestartTick(&stop_time_);
825 820
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 RestartTick(&start_time_); 1380 RestartTick(&start_time_);
1386 skip_recording_startup_time_ = false; 1381 skip_recording_startup_time_ = false;
1387 } 1382 }
1388 1383
1389 // The worker is starting up and not yet idle. 1384 // The worker is starting up and not yet idle.
1390 ClearTick(&idle_time_); 1385 ClearTick(&idle_time_);
1391 1386
1392 // Ping will be activated in OnScriptLoaded. 1387 // Ping will be activated in OnScriptLoaded.
1393 ping_controller_->Deactivate(); 1388 ping_controller_->Deactivate();
1394 1389
1395 // Make the timer delay shorter for starting an existing
1396 // worker so stalled in starting workers can be timed out quickly.
1397 // The timer will be reset to normal in OnStarted or the next start
1398 // attempt.
1399 const int delay_in_seconds = IsInstalled(status_)
1400 ? kStartInstalledWorkerTimeoutSeconds
1401 : kTimeoutTimerDelaySeconds;
1402 timeout_timer_.Start(FROM_HERE, 1390 timeout_timer_.Start(FROM_HERE,
1403 base::TimeDelta::FromSeconds(delay_in_seconds), this, 1391 base::TimeDelta::FromSeconds(kTimeoutTimerDelaySeconds),
1404 &ServiceWorkerVersion::OnTimeoutTimer); 1392 this, &ServiceWorkerVersion::OnTimeoutTimer);
1405 } 1393 }
1406 1394
1407 void ServiceWorkerVersion::StopTimeoutTimer() { 1395 void ServiceWorkerVersion::StopTimeoutTimer() {
1408 timeout_timer_.Stop(); 1396 timeout_timer_.Stop();
1409 ClearTick(&idle_time_); 1397 ClearTick(&idle_time_);
1410 1398
1411 // Trigger update if worker is stale. 1399 // Trigger update if worker is stale.
1412 if (!in_dtor_ && !stale_time_.is_null()) { 1400 if (!in_dtor_ && !stale_time_.is_null()) {
1413 ClearTick(&stale_time_); 1401 ClearTick(&stale_time_);
1414 if (!update_timer_.IsRunning()) 1402 if (!update_timer_.IsRunning())
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 void ServiceWorkerVersion::OnBeginEvent() { 1757 void ServiceWorkerVersion::OnBeginEvent() {
1770 if (should_exclude_from_uma_ || running_status() != RUNNING || 1758 if (should_exclude_from_uma_ || running_status() != RUNNING ||
1771 idle_time_.is_null()) { 1759 idle_time_.is_null()) {
1772 return; 1760 return;
1773 } 1761 }
1774 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - 1762 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() -
1775 idle_time_); 1763 idle_time_);
1776 } 1764 }
1777 1765
1778 } // namespace content 1766 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698