Chromium Code Reviews| Index: content/browser/service_worker/service_worker_version.cc |
| diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc |
| index 62a6a6029ff47545d29b5f3434101158c090118e..30d9fd5a0a1b0ae5ce39b581c24c49d385544d4a 100644 |
| --- a/content/browser/service_worker/service_worker_version.cc |
| +++ b/content/browser/service_worker/service_worker_version.cc |
| @@ -374,6 +374,43 @@ void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, |
| } |
| } |
| +void ServiceWorkerVersion::DispatchGeofencingEvent( |
| + const StatusCallback& callback, |
| + blink::WebGeofencingEventType event_type, |
| + const std::string& region_id, |
| + const blink::WebCircularGeofencingRegion& region) { |
| + DCHECK_EQ(ACTIVATED, status()) << status(); |
|
palmer
2014/10/27 22:27:37
What are the consequences of continuing in a produ
michaeln
2014/10/28 00:02:59
nothing harmful, this just catches cases where the
Marijn Kruisselbrink
2014/10/29 17:31:29
as michaeln said, this is purely about correctness
|
| + |
| + if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kEnableExperimentalWebPlatformFeatures)) { |
| + callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| + return; |
| + } |
| + |
| + if (running_status() != RUNNING) { |
| + // Schedule calling this method after starting the worker. |
| + StartWorker(base::Bind(&RunTaskAfterStartWorker, |
| + weak_factory_.GetWeakPtr(), |
| + callback, |
| + base::Bind(&self::DispatchGeofencingEvent, |
| + weak_factory_.GetWeakPtr(), |
| + callback, |
| + event_type, |
| + region_id, |
| + region))); |
| + return; |
| + } |
| + |
| + int request_id = geofencing_callbacks_.Add(new StatusCallback(callback)); |
| + ServiceWorkerStatusCode status = |
| + embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent( |
| + request_id, event_type, region_id, region)); |
| + if (status != SERVICE_WORKER_OK) { |
| + geofencing_callbacks_.Remove(request_id); |
| + RunSoon(base::Bind(callback, status)); |
| + } |
| +} |
| + |
| void ServiceWorkerVersion::AddControllee( |
| ServiceWorkerProviderHost* provider_host) { |
| DCHECK(!ContainsKey(controllee_map_, provider_host)); |
| @@ -456,6 +493,9 @@ void ServiceWorkerVersion::OnStopped() { |
| RunIDMapCallbacks(&push_callbacks_, |
| &StatusCallback::Run, |
| MakeTuple(SERVICE_WORKER_ERROR_FAILED)); |
| + RunIDMapCallbacks(&geofencing_callbacks_, |
| + &StatusCallback::Run, |
| + MakeTuple(SERVICE_WORKER_ERROR_FAILED)); |
| FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStopped(this)); |
| @@ -507,6 +547,8 @@ bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { |
| OnSyncEventFinished) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, |
| OnPushEventFinished) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, |
| + OnGeofencingEventFinished) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument, |
| OnPostMessageToDocument) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| @@ -660,6 +702,22 @@ void ServiceWorkerVersion::OnPushEventFinished( |
| push_callbacks_.Remove(request_id); |
| } |
| +void ServiceWorkerVersion::OnGeofencingEventFinished(int request_id) { |
| + TRACE_EVENT1("ServiceWorker", |
| + "ServiceWorkerVersion::OnGeofencingEventFinished", |
| + "Request id", |
| + request_id); |
| + StatusCallback* callback = geofencing_callbacks_.Lookup(request_id); |
| + if (!callback) { |
| + NOTREACHED() << "Got unexpected message: " << request_id; |
| + return; |
| + } |
| + |
| + scoped_refptr<ServiceWorkerVersion> protect(this); |
| + callback->Run(SERVICE_WORKER_OK); |
| + geofencing_callbacks_.Remove(request_id); |
| +} |
| + |
| void ServiceWorkerVersion::OnPostMessageToDocument( |
| int client_id, |
| const base::string16& message, |