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

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

Issue 1162243003: BackgroundSync sync events need to be ExtendableEvents, content side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid race condition in sync event dispatch Created 5 years, 6 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 // TODO(kinuko): Record other event statuses too. 1321 // TODO(kinuko): Record other event statuses too.
1322 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); 1322 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE);
1323 metrics_->RecordEventStatus(handled); 1323 metrics_->RecordEventStatus(handled);
1324 1324
1325 scoped_refptr<ServiceWorkerVersion> protect(this); 1325 scoped_refptr<ServiceWorkerVersion> protect(this);
1326 callback->Run(SERVICE_WORKER_OK, result, response); 1326 callback->Run(SERVICE_WORKER_OK, result, response);
1327 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id); 1327 RemoveCallbackAndStopIfRedundant(&fetch_callbacks_, request_id);
1328 } 1328 }
1329 1329
1330 void ServiceWorkerVersion::OnSyncEventFinished( 1330 void ServiceWorkerVersion::OnSyncEventFinished(
1331 int request_id) { 1331 int request_id,
1332 blink::WebServiceWorkerEventResult result) {
1332 TRACE_EVENT1("ServiceWorker", 1333 TRACE_EVENT1("ServiceWorker",
1333 "ServiceWorkerVersion::OnSyncEventFinished", 1334 "ServiceWorkerVersion::OnSyncEventFinished",
1334 "Request id", request_id); 1335 "Request id", request_id);
1335 StatusCallback* callback = sync_callbacks_.Lookup(request_id); 1336 StatusCallback* callback = sync_callbacks_.Lookup(request_id);
1336 if (!callback) { 1337 if (!callback) {
1337 NOTREACHED() << "Got unexpected message: " << request_id; 1338 NOTREACHED() << "Got unexpected message: " << request_id;
1338 return; 1339 return;
1339 } 1340 }
1340 1341
1342 ServiceWorkerStatusCode status = SERVICE_WORKER_OK;
1343 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1344 switches::kEnableServiceWorkerSync)) {
1345 // Avoid potential race condition where flag is disabled after a sync event
1346 // was dispatched
1347 status = SERVICE_WORKER_ERROR_ABORT;
1348 } else if (result == blink::WebServiceWorkerEventResultRejected) {
1349 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED;
1350 }
1351
1341 scoped_refptr<ServiceWorkerVersion> protect(this); 1352 scoped_refptr<ServiceWorkerVersion> protect(this);
1342 callback->Run(SERVICE_WORKER_OK); 1353 callback->Run(status);
1343 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id); 1354 RemoveCallbackAndStopIfRedundant(&sync_callbacks_, request_id);
1344 } 1355 }
1345 1356
1346 void ServiceWorkerVersion::OnNotificationClickEventFinished( 1357 void ServiceWorkerVersion::OnNotificationClickEventFinished(
1347 int request_id) { 1358 int request_id) {
1348 TRACE_EVENT1("ServiceWorker", 1359 TRACE_EVENT1("ServiceWorker",
1349 "ServiceWorkerVersion::OnNotificationClickEventFinished", 1360 "ServiceWorkerVersion::OnNotificationClickEventFinished",
1350 "Request id", request_id); 1361 "Request id", request_id);
1351 StatusCallback* callback = notification_click_callbacks_.Lookup(request_id); 1362 StatusCallback* callback = notification_click_callbacks_.Lookup(request_id);
1352 if (!callback) { 1363 if (!callback) {
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 return SERVICE_WORKER_ERROR_ABORT; 2030 return SERVICE_WORKER_ERROR_ABORT;
2020 default: 2031 default:
2021 return SERVICE_WORKER_ERROR_NETWORK; 2032 return SERVICE_WORKER_ERROR_NETWORK;
2022 } 2033 }
2023 } 2034 }
2024 2035
2025 return default_code; 2036 return default_code;
2026 } 2037 }
2027 2038
2028 } // namespace content 2039 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/common/service_worker/service_worker_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698