Index: content/browser/geofencing/geofencing_dispatcher_host.cc |
diff --git a/content/browser/geofencing/geofencing_dispatcher_host.cc b/content/browser/geofencing/geofencing_dispatcher_host.cc |
index 077485b38f6a31407c7dc2400408c09bce9bcd31..3acf72575b894752068375947ebeefed163dab87 100644 |
--- a/content/browser/geofencing/geofencing_dispatcher_host.cc |
+++ b/content/browser/geofencing/geofencing_dispatcher_host.cc |
@@ -5,6 +5,9 @@ |
#include "content/browser/geofencing/geofencing_dispatcher_host.h" |
#include "content/browser/geofencing/geofencing_manager.h" |
+#include "content/browser/service_worker/service_worker_context_core.h" |
+#include "content/browser/service_worker/service_worker_context_wrapper.h" |
+#include "content/browser/service_worker/service_worker_registration.h" |
#include "content/common/geofencing_messages.h" |
#include "third_party/WebKit/public/platform/WebCircularGeofencingRegion.h" |
#include "url/gurl.h" |
@@ -14,9 +17,11 @@ namespace content { |
static const int kMaxRegionIdLength = 200; |
GeofencingDispatcherHost::GeofencingDispatcherHost( |
- BrowserContext* browser_context) |
+ BrowserContext* browser_context, |
+ scoped_refptr<ServiceWorkerContextWrapper> service_worker_context) |
: BrowserMessageFilter(GeofencingMsgStart), |
browser_context_(browser_context), |
+ service_worker_context_(service_worker_context), |
weak_factory_(this) { |
} |
@@ -39,18 +44,38 @@ void GeofencingDispatcherHost::OnRegisterRegion( |
int thread_id, |
int request_id, |
const std::string& region_id, |
- const blink::WebCircularGeofencingRegion& region) { |
+ const blink::WebCircularGeofencingRegion& region, |
+ int64 service_worker_registration_id) { |
// Sanity check on region_id |
if (region_id.length() > kMaxRegionIdLength) { |
Send(new GeofencingMsg_RegisterRegionComplete( |
thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); |
return; |
} |
- // TODO(mek): Actually pass service worker information to manager. |
+ |
+ // Look up service worker. |
+ ServiceWorkerRegistration* service_worker_registration = |
+ service_worker_context_->context()->GetLiveRegistration( |
+ service_worker_registration_id); |
+ |
+ if (!service_worker_registration) { |
+ Send(new GeofencingMsg_RegisterRegionComplete( |
+ thread_id, |
+ request_id, |
+ GeofencingStatus:: |
+ GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER)); |
+ return; |
+ } |
+ |
+ GURL service_worker_origin = |
+ service_worker_registration |
michaeln
2014/10/14 01:03:52
don't need to check for null here
Marijn Kruisselbrink
2014/10/14 18:51:22
Done.
|
+ ? service_worker_registration->pattern().GetOrigin() |
+ : GURL(); |
+ |
GeofencingManager::GetInstance()->RegisterRegion( |
browser_context_, |
- 0, /* service_worker_registration_id */ |
- GURL(), /* service_worker_origin */ |
+ service_worker_registration_id, |
+ service_worker_origin, |
region_id, |
region, |
base::Bind(&GeofencingDispatcherHost::RegisterRegionCompleted, |
@@ -62,18 +87,38 @@ void GeofencingDispatcherHost::OnRegisterRegion( |
void GeofencingDispatcherHost::OnUnregisterRegion( |
int thread_id, |
int request_id, |
- const std::string& region_id) { |
+ const std::string& region_id, |
+ int64 service_worker_registration_id) { |
// Sanity check on region_id |
if (region_id.length() > kMaxRegionIdLength) { |
Send(new GeofencingMsg_UnregisterRegionComplete( |
thread_id, request_id, GeofencingStatus::GEOFENCING_STATUS_ERROR)); |
return; |
} |
- // TODO(mek): Actually pass service worker information to manager. |
+ |
+ // Look up service worker. |
+ ServiceWorkerRegistration* service_worker_registration = |
+ service_worker_context_->context()->GetLiveRegistration( |
+ service_worker_registration_id); |
+ |
+ if (!service_worker_registration) { |
+ Send(new GeofencingMsg_UnregisterRegionComplete( |
+ thread_id, |
+ request_id, |
+ GeofencingStatus:: |
+ GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER)); |
+ return; |
+ } |
+ |
+ GURL service_worker_origin = |
+ service_worker_registration |
+ ? service_worker_registration->pattern().GetOrigin() |
michaeln
2014/10/14 01:03:52
ditto, null check not needed
Marijn Kruisselbrink
2014/10/14 18:51:22
Done.
|
+ : GURL(); |
+ |
GeofencingManager::GetInstance()->UnregisterRegion( |
browser_context_, |
- 0, /* service_worker_registration_id */ |
- GURL(), /* service_worker_origin */ |
+ service_worker_registration_id, |
+ service_worker_origin, |
region_id, |
base::Bind(&GeofencingDispatcherHost::UnregisterRegionCompleted, |
weak_factory_.GetWeakPtr(), |
@@ -81,15 +126,36 @@ void GeofencingDispatcherHost::OnUnregisterRegion( |
request_id)); |
} |
-void GeofencingDispatcherHost::OnGetRegisteredRegions(int thread_id, |
- int request_id) { |
+void GeofencingDispatcherHost::OnGetRegisteredRegions( |
+ int thread_id, |
+ int request_id, |
+ int64 service_worker_registration_id) { |
GeofencingRegistrations result; |
- // TODO(mek): Actually pass service worker information to manager. |
+ |
+ // Look up service worker. |
+ ServiceWorkerRegistration* service_worker_registration = |
+ service_worker_context_->context()->GetLiveRegistration( |
+ service_worker_registration_id); |
+ |
+ if (!service_worker_registration) { |
+ Send(new GeofencingMsg_GetRegisteredRegionsComplete( |
+ thread_id, |
+ request_id, |
+ GeofencingStatus::GEOFENCING_STATUS_OPERATION_FAILED_NO_SERVICE_WORKER, |
+ result)); |
+ return; |
+ } |
+ |
+ GURL service_worker_origin = |
+ service_worker_registration |
michaeln
2014/10/14 01:03:52
here too
Marijn Kruisselbrink
2014/10/14 18:51:22
Done.
|
+ ? service_worker_registration->pattern().GetOrigin() |
+ : GURL(); |
+ |
GeofencingStatus status = |
GeofencingManager::GetInstance()->GetRegisteredRegions( |
browser_context_, |
- 0, /* service_worker_registration_id */ |
- GURL(), /* service_worker_origin */ |
+ service_worker_registration_id, |
+ service_worker_origin, |
&result); |
Send(new GeofencingMsg_GetRegisteredRegionsComplete( |
thread_id, request_id, status, result)); |