| Index: content/browser/geofencing/geofencing_manager.cc
|
| diff --git a/content/browser/geofencing/geofencing_manager.cc b/content/browser/geofencing/geofencing_manager.cc
|
| index 0ea5aa200d73c369e85cff417b6e62f8a4e76984..331b787ab7448e35da024dc98045abd6c67e56e5 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,
|
| @@ -95,6 +98,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;
|
| @@ -107,6 +125,7 @@ void GeofencingManager::RegisterRegion(
|
| }
|
|
|
| AddRegistration(service_worker_registration_id,
|
| + service_worker_origin,
|
| region_id,
|
| region,
|
| callback,
|
| @@ -120,6 +139,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;
|
| @@ -150,6 +181,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;
|
| }
|
| @@ -208,6 +250,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,
|
| @@ -217,6 +260,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,
|
|
|