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

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

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 #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 <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "net/http/http_response_headers.h" 48 #include "net/http/http_response_headers.h"
49 #include "net/http/http_response_info.h" 49 #include "net/http/http_response_info.h"
50 50
51 namespace content { 51 namespace content {
52 52
53 using StatusCallback = ServiceWorkerVersion::StatusCallback; 53 using StatusCallback = ServiceWorkerVersion::StatusCallback;
54 54
55 namespace { 55 namespace {
56 56
57 // Time to wait until stopping an idle worker. 57 // Time to wait until stopping an idle worker.
58 const int kIdleWorkerTimeoutSeconds = 30; 58 const int kIdleWorkerTimeoutSeconds = 3;
59 59
60 // Default delay for scheduled update. 60 // Default delay for scheduled update.
61 const int kUpdateDelaySeconds = 1; 61 const int kUpdateDelaySeconds = 1;
62 62
63 // Timeout for waiting for a response to a ping. 63 // Timeout for waiting for a response to a ping.
64 const int kPingTimeoutSeconds = 30; 64 const int kPingTimeoutSeconds = 30;
65 65
66 const char kClaimClientsStateErrorMesage[] = 66 const char kClaimClientsStateErrorMesage[] =
67 "Only the active worker can claim clients."; 67 "Only the active worker can claim clients.";
68 68
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (trace_id == std::numeric_limits<int>::max()) 185 if (trace_id == std::numeric_limits<int>::max())
186 trace_id = 0; 186 trace_id = 0;
187 else 187 else
188 ++trace_id; 188 ++trace_id;
189 DCHECK_NE(kInvalidTraceId, trace_id); 189 DCHECK_NE(kInvalidTraceId, trace_id);
190 return trace_id; 190 return trace_id;
191 } 191 }
192 192
193 } // namespace 193 } // namespace
194 194
195 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30; 195 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 3;
falken 2016/07/22 05:06:02 Are these timer changes just for proof of concept?
lazyboy 2016/07/26 17:45:48 Yes, these are entirely for proof of concept, espe
196 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60; 196 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60;
197 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5; 197 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5;
198 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; 198 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5;
199 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5; 199 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5;
200 200
201 class ServiceWorkerVersion::Metrics { 201 class ServiceWorkerVersion::Metrics {
202 public: 202 public:
203 using EventType = ServiceWorkerMetrics::EventType; 203 using EventType = ServiceWorkerMetrics::EventType;
204 explicit Metrics(ServiceWorkerVersion* owner) : owner_(owner) {} 204 explicit Metrics(ServiceWorkerVersion* owner) : owner_(owner) {}
205 ~Metrics() { 205 ~Metrics() {
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 void ServiceWorkerVersion::SetTimeoutTimerInterval(base::TimeDelta interval) { 1405 void ServiceWorkerVersion::SetTimeoutTimerInterval(base::TimeDelta interval) {
1406 DCHECK(timeout_timer_.IsRunning()); 1406 DCHECK(timeout_timer_.IsRunning());
1407 if (timeout_timer_.GetCurrentDelay() != interval) { 1407 if (timeout_timer_.GetCurrentDelay() != interval) {
1408 timeout_timer_.Stop(); 1408 timeout_timer_.Stop();
1409 timeout_timer_.Start(FROM_HERE, interval, this, 1409 timeout_timer_.Start(FROM_HERE, interval, this,
1410 &ServiceWorkerVersion::OnTimeoutTimer); 1410 &ServiceWorkerVersion::OnTimeoutTimer);
1411 } 1411 }
1412 } 1412 }
1413 1413
1414 void ServiceWorkerVersion::OnTimeoutTimer() { 1414 void ServiceWorkerVersion::OnTimeoutTimer() {
1415 LOG(ERROR) << "ServiceWorkerVersion::OnTimeoutTimer";
1415 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING || 1416 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING ||
1416 running_status() == EmbeddedWorkerStatus::RUNNING || 1417 running_status() == EmbeddedWorkerStatus::RUNNING ||
1417 running_status() == EmbeddedWorkerStatus::STOPPING) 1418 running_status() == EmbeddedWorkerStatus::STOPPING)
1418 << static_cast<int>(running_status()); 1419 << static_cast<int>(running_status());
1419 1420
1420 if (!context_) 1421 if (!context_)
1421 return; 1422 return;
1422 1423
1423 MarkIfStale(); 1424 MarkIfStale();
1424 1425
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 void ServiceWorkerVersion::OnPingTimeout() { 1512 void ServiceWorkerVersion::OnPingTimeout() {
1512 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING || 1513 DCHECK(running_status() == EmbeddedWorkerStatus::STARTING ||
1513 running_status() == EmbeddedWorkerStatus::RUNNING); 1514 running_status() == EmbeddedWorkerStatus::RUNNING);
1514 // TODO(falken): Show a message to the developer that the SW was stopped due 1515 // TODO(falken): Show a message to the developer that the SW was stopped due
1515 // to timeout (crbug.com/457968). Also, change the error code to 1516 // to timeout (crbug.com/457968). Also, change the error code to
1516 // SERVICE_WORKER_ERROR_TIMEOUT. 1517 // SERVICE_WORKER_ERROR_TIMEOUT.
1517 StopWorkerIfIdle(); 1518 StopWorkerIfIdle();
1518 } 1519 }
1519 1520
1520 void ServiceWorkerVersion::StopWorkerIfIdle() { 1521 void ServiceWorkerVersion::StopWorkerIfIdle() {
1522 LOG(ERROR) << "ServiceWorkerVersion::StopWorkerIfIdle";
1521 if (HasWork() && !ping_controller_->IsTimedOut()) 1523 if (HasWork() && !ping_controller_->IsTimedOut())
1522 return; 1524 return;
1523 if (running_status() == EmbeddedWorkerStatus::STOPPED || 1525 if (running_status() == EmbeddedWorkerStatus::STOPPED ||
1524 running_status() == EmbeddedWorkerStatus::STOPPING || 1526 running_status() == EmbeddedWorkerStatus::STOPPING ||
1525 !stop_callbacks_.empty()) { 1527 !stop_callbacks_.empty()) {
1526 return; 1528 return;
1527 } 1529 }
1528 1530
1529 embedded_worker_->StopIfIdle(); 1531 embedded_worker_->StopIfIdle();
1530 } 1532 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 if (should_exclude_from_uma_ || 1739 if (should_exclude_from_uma_ ||
1738 running_status() != EmbeddedWorkerStatus::RUNNING || 1740 running_status() != EmbeddedWorkerStatus::RUNNING ||
1739 idle_time_.is_null()) { 1741 idle_time_.is_null()) {
1740 return; 1742 return;
1741 } 1743 }
1742 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - 1744 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() -
1743 idle_time_); 1745 idle_time_);
1744 } 1746 }
1745 1747
1746 } // namespace content 1748 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698