summaryrefslogtreecommitdiffstats
path: root/content/browser/background_sync/background_sync_manager.cc
diff options
context:
space:
mode:
authoriclelland <iclelland@chromium.org>2015-07-23 12:23:26 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-23 19:24:54 +0000
commit213183fe6e8958d2ef43543c806dc3d34ce3509e (patch)
tree5b3a72d280fc2562770aaee7cc3f653536113d35 /content/browser/background_sync/background_sync_manager.cc
parentc28691dacdd323cebbdddc5e92526cb2623429b8 (diff)
downloadchromium_src-213183fe6e8958d2ef43543c806dc3d34ce3509e.zip
chromium_src-213183fe6e8958d2ef43543c806dc3d34ce3509e.tar.gz
chromium_src-213183fe6e8958d2ef43543c806dc3d34ce3509e.tar.bz2
[Background Sync] Restrict sync registration to service workers with window clients.
BUG=479658 Review URL: https://codereview.chromium.org/1234353004 Cr-Commit-Position: refs/heads/master@{#340141}
Diffstat (limited to 'content/browser/background_sync/background_sync_manager.cc')
-rw-r--r--content/browser/background_sync/background_sync_manager.cc33
1 files changed, 20 insertions, 13 deletions
diff --git a/content/browser/background_sync/background_sync_manager.cc b/content/browser/background_sync/background_sync_manager.cc
index 2a79df5..6c33d51 100644
--- a/content/browser/background_sync/background_sync_manager.cc
+++ b/content/browser/background_sync/background_sync_manager.cc
@@ -320,6 +320,26 @@ void BackgroundSyncManager::RegisterImpl(
return;
}
+ ServiceWorkerRegistration* sw_registration =
+ service_worker_context_->GetLiveRegistration(sw_registration_id);
+ if (!sw_registration || !sw_registration->active_version()) {
+ BackgroundSyncMetrics::CountRegister(
+ options.periodicity, registration_could_fire,
+ BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
+ ERROR_TYPE_NO_SERVICE_WORKER);
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, ERROR_TYPE_NO_SERVICE_WORKER,
+ BackgroundSyncRegistration()));
+ return;
+ }
+
+ if (!sw_registration->active_version()->HasWindowClients()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(callback, ERROR_TYPE_NOT_ALLOWED,
+ BackgroundSyncRegistration()));
+ return;
+ }
+
BackgroundSyncRegistration* existing_registration =
LookupRegistration(sw_registration_id, RegistrationKey(options));
if (existing_registration &&
@@ -351,19 +371,6 @@ void BackgroundSyncManager::RegisterImpl(
&sw_to_registrations_map_[sw_registration_id];
new_registration.set_id(registrations->next_id++);
- ServiceWorkerRegistration* sw_registration =
- service_worker_context_->GetLiveRegistration(sw_registration_id);
- if (!sw_registration || !sw_registration->active_version()) {
- BackgroundSyncMetrics::CountRegister(
- options.periodicity, registration_could_fire,
- BackgroundSyncMetrics::REGISTRATION_IS_NOT_DUPLICATE,
- ERROR_TYPE_NO_SERVICE_WORKER);
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ERROR_TYPE_NO_SERVICE_WORKER,
- BackgroundSyncRegistration()));
- return;
- }
-
AddRegistrationToMap(sw_registration_id,
sw_registration->pattern().GetOrigin(),
new_registration);