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

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

Issue 2506263005: Prevent a service worker from keeping itself alive by self postMessage. (Closed)
Patch Set: fix unit test Created 4 years, 1 month 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "mojo/common/common_type_converters.h" 50 #include "mojo/common/common_type_converters.h"
51 #include "net/http/http_response_headers.h" 51 #include "net/http/http_response_headers.h"
52 #include "net/http/http_response_info.h" 52 #include "net/http/http_response_info.h"
53 53
54 namespace content { 54 namespace content {
55 55
56 using StatusCallback = ServiceWorkerVersion::StatusCallback; 56 using StatusCallback = ServiceWorkerVersion::StatusCallback;
57 57
58 namespace { 58 namespace {
59 59
60 // Time to wait until stopping an idle worker.
61 const int kIdleWorkerTimeoutSeconds = 30;
62
63 // Default delay for scheduled update. 60 // Default delay for scheduled update.
64 const int kUpdateDelaySeconds = 1; 61 const int kUpdateDelaySeconds = 1;
65 62
66 // Timeout for waiting for a response to a ping. 63 // Timeout for waiting for a response to a ping.
67 const int kPingTimeoutSeconds = 30; 64 const int kPingTimeoutSeconds = 30;
68 65
69 const char kClaimClientsStateErrorMesage[] = 66 const char kClaimClientsStateErrorMesage[] =
70 "Only the active worker can claim clients."; 67 "Only the active worker can claim clients.";
71 68
72 const char kClaimClientsShutdownErrorMesage[] = 69 const char kClaimClientsShutdownErrorMesage[] =
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return trace_id; 176 return trace_id;
180 } 177 }
181 178
182 } // namespace 179 } // namespace
183 180
184 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30; 181 const int ServiceWorkerVersion::kTimeoutTimerDelaySeconds = 30;
185 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60; 182 const int ServiceWorkerVersion::kStartInstalledWorkerTimeoutSeconds = 60;
186 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5; 183 const int ServiceWorkerVersion::kStartNewWorkerTimeoutMinutes = 5;
187 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5; 184 const int ServiceWorkerVersion::kRequestTimeoutMinutes = 5;
188 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5; 185 const int ServiceWorkerVersion::kStopWorkerTimeoutSeconds = 5;
186 const int ServiceWorkerVersion::kIdleWorkerTimeoutSeconds = 30;
189 187
190 void ServiceWorkerVersion::RestartTick(base::TimeTicks* time) const { 188 void ServiceWorkerVersion::RestartTick(base::TimeTicks* time) const {
191 *time = tick_clock_->NowTicks(); 189 *time = tick_clock_->NowTicks();
192 } 190 }
193 191
194 bool ServiceWorkerVersion::RequestExpired( 192 bool ServiceWorkerVersion::RequestExpired(
195 const base::TimeTicks& expiration) const { 193 const base::TimeTicks& expiration) const {
196 if (expiration.is_null()) 194 if (expiration.is_null())
197 return false; 195 return false;
198 return tick_clock_->NowTicks() >= expiration; 196 return tick_clock_->NowTicks() >= expiration;
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 563
566 int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>( 564 int request_id = pending_requests_.Add(base::MakeUnique<PendingRequest>(
567 error_callback, base::Time::Now(), tick_clock_->NowTicks(), event_type)); 565 error_callback, base::Time::Now(), tick_clock_->NowTicks(), event_type));
568 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", "ServiceWorkerVersion::Request", 566 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", "ServiceWorkerVersion::Request",
569 pending_requests_.Lookup(request_id), "Request id", 567 pending_requests_.Lookup(request_id), "Request id",
570 request_id, "Event type", 568 request_id, "Event type",
571 ServiceWorkerMetrics::EventTypeToString(event_type)); 569 ServiceWorkerMetrics::EventTypeToString(event_type));
572 base::TimeTicks expiration_time = tick_clock_->NowTicks() + timeout; 570 base::TimeTicks expiration_time = tick_clock_->NowTicks() + timeout;
573 timeout_queue_.push( 571 timeout_queue_.push(
574 RequestInfo(request_id, event_type, expiration_time, timeout_behavior)); 572 RequestInfo(request_id, event_type, expiration_time, timeout_behavior));
573 if (expiration_time > max_request_expiration_time_)
574 max_request_expiration_time_ = expiration_time;
falken 2016/11/21 08:01:48 It seems we never reset max to an earlier time (e.
575 return request_id; 575 return request_id;
576 } 576 }
577 577
578 bool ServiceWorkerVersion::StartExternalRequest( 578 bool ServiceWorkerVersion::StartExternalRequest(
579 const std::string& request_uuid) { 579 const std::string& request_uuid) {
580 // It's possible that the renderer is lying or the version started stopping 580 // It's possible that the renderer is lying or the version started stopping
581 // right around the time of the IPC. 581 // right around the time of the IPC.
582 if (running_status() != EmbeddedWorkerStatus::RUNNING) 582 if (running_status() != EmbeddedWorkerStatus::RUNNING)
583 return false; 583 return false;
584 584
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 1887
1888 void ServiceWorkerVersion::CleanUpExternalRequest( 1888 void ServiceWorkerVersion::CleanUpExternalRequest(
1889 const std::string& request_uuid, 1889 const std::string& request_uuid,
1890 ServiceWorkerStatusCode status) { 1890 ServiceWorkerStatusCode status) {
1891 if (status == SERVICE_WORKER_OK) 1891 if (status == SERVICE_WORKER_OK)
1892 return; 1892 return;
1893 external_request_uuid_to_request_id_.erase(request_uuid); 1893 external_request_uuid_to_request_id_.erase(request_uuid);
1894 } 1894 }
1895 1895
1896 } // namespace content 1896 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698