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

Unified Diff: content/browser/service_worker/service_worker_version.cc

Issue 629393002: Chromium side of geofencing event dispatching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@geofencing_serviceworker
Patch Set: nit 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
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/common/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
+
+ 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,
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/common/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698