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

Unified Diff: content/browser/geofencing/geofencing_manager.cc

Issue 623823002: Chrome side of passing on the service worker registration with geofencing API calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/geofencing/geofencing_manager.cc
diff --git a/content/browser/geofencing/geofencing_manager.cc b/content/browser/geofencing/geofencing_manager.cc
index 33afae5ef02d8948b9a4775a85d36923222f2b21..1147d7d26a5c5a22239556f4e846dee9a34cf4c2 100644
--- a/content/browser/geofencing/geofencing_manager.cc
+++ b/content/browser/geofencing/geofencing_manager.cc
@@ -16,12 +16,14 @@ namespace content {
struct GeofencingManager::Registration {
Registration(int64 service_worker_registration_id,
+ const GURL& service_worker_origin,
const std::string& region_id,
const blink::WebCircularGeofencingRegion& region,
const StatusCallback& callback,
int64 geofencing_registration_id);
int64 service_worker_registration_id;
+ GURL service_worker_origin;
std::string region_id;
blink::WebCircularGeofencingRegion region;
@@ -39,6 +41,7 @@ struct GeofencingManager::Registration {
GeofencingManager::Registration::Registration(
int64 service_worker_registration_id,
+ const GURL& service_worker_origin,
const std::string& region_id,
const blink::WebCircularGeofencingRegion& region,
const GeofencingManager::StatusCallback& callback,
@@ -98,6 +101,21 @@ void GeofencingManager::RegisterRegion(
// TODO(mek): Validate region_id and region.
+ // Look up service worker. In unit tests |service_worker_context_| might not
+ // be set.
+ GURL service_worker_origin;
+ if (service_worker_context_.get()) {
+ ServiceWorkerRegistration* service_worker_registration =
+ service_worker_context_->context()->GetLiveRegistration(
+ service_worker_registration_id);
+ if (!service_worker_registration) {
+ callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER);
+ return;
+ }
+
+ service_worker_origin = service_worker_registration->pattern().GetOrigin();
+ }
+
if (!service_->IsServiceAvailable()) {
callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE);
return;
@@ -111,6 +129,7 @@ void GeofencingManager::RegisterRegion(
}
AddRegistration(service_worker_registration_id,
+ service_worker_origin,
region_id,
region,
callback,
@@ -124,6 +143,18 @@ void GeofencingManager::UnregisterRegion(int64 service_worker_registration_id,
// TODO(mek): Validate region_id.
+ // Look up service worker. In unit tests |service_worker_context_| might not
+ // be set.
+ if (service_worker_context_.get()) {
+ ServiceWorkerRegistration* service_worker_registration =
+ service_worker_context_->context()->GetLiveRegistration(
+ service_worker_registration_id);
+ if (!service_worker_registration) {
+ callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER);
+ return;
+ }
+ }
+
if (!service_->IsServiceAvailable()) {
callback.Run(GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE);
return;
@@ -154,6 +185,17 @@ GeofencingStatus GeofencingManager::GetRegisteredRegions(
DCHECK_CURRENTLY_ON(BrowserThread::IO);
CHECK(result);
+ // Look up service worker. In unit tests |service_worker_context_| might not
+ // be set.
+ if (service_worker_context_.get()) {
+ ServiceWorkerRegistration* service_worker_registration =
+ service_worker_context_->context()->GetLiveRegistration(
+ service_worker_registration_id);
+ if (!service_worker_registration) {
+ return GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER;
+ }
+ }
+
if (!service_->IsServiceAvailable()) {
return GEOFENCING_STATUS_OPERATION_FAILED_SERVICE_NOT_AVAILABLE;
}
@@ -212,6 +254,7 @@ GeofencingManager::Registration* GeofencingManager::FindRegistrationById(
GeofencingManager::Registration& GeofencingManager::AddRegistration(
int64 service_worker_registration_id,
+ const GURL& service_worker_origin,
const std::string& region_id,
const blink::WebCircularGeofencingRegion& region,
const StatusCallback& callback,
@@ -222,6 +265,7 @@ GeofencingManager::Registration& GeofencingManager::AddRegistration(
registrations_[service_worker_registration_id]
.insert(std::make_pair(region_id,
Registration(service_worker_registration_id,
+ service_worker_origin,
region_id,
region,
callback,
« no previous file with comments | « content/browser/geofencing/geofencing_manager.h ('k') | content/browser/service_worker/service_worker_registration_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698