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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "content/browser/service_worker/embedded_worker_instance.h" 10 #include "content/browser/service_worker/embedded_worker_instance.h"
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 367
368 int request_id = push_callbacks_.Add(new StatusCallback(callback)); 368 int request_id = push_callbacks_.Add(new StatusCallback(callback));
369 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( 369 ServiceWorkerStatusCode status = embedded_worker_->SendMessage(
370 ServiceWorkerMsg_PushEvent(request_id, data)); 370 ServiceWorkerMsg_PushEvent(request_id, data));
371 if (status != SERVICE_WORKER_OK) { 371 if (status != SERVICE_WORKER_OK) {
372 push_callbacks_.Remove(request_id); 372 push_callbacks_.Remove(request_id);
373 RunSoon(base::Bind(callback, status)); 373 RunSoon(base::Bind(callback, status));
374 } 374 }
375 } 375 }
376 376
377 void ServiceWorkerVersion::DispatchGeofencingEvent(
378 const StatusCallback& callback,
379 blink::WebGeofencingEventType event_type,
380 const std::string& region_id,
381 const blink::WebCircularGeofencingRegion& region) {
382 DCHECK_EQ(ACTIVATED, status()) << status();
383
384 if (!CommandLine::ForCurrentProcess()->HasSwitch(
385 switches::kEnableExperimentalWebPlatformFeatures)) {
386 callback.Run(SERVICE_WORKER_ERROR_ABORT);
387 return;
388 }
389
390 if (running_status() != RUNNING) {
391 // Schedule calling this method after starting the worker.
392 StartWorker(base::Bind(&RunTaskAfterStartWorker,
393 weak_factory_.GetWeakPtr(),
394 callback,
395 base::Bind(&self::DispatchGeofencingEvent,
396 weak_factory_.GetWeakPtr(),
397 callback,
398 event_type,
399 region_id,
400 region)));
401 return;
402 }
403
404 int request_id = geofencing_callbacks_.Add(new StatusCallback(callback));
405 ServiceWorkerStatusCode status =
406 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent(
407 request_id, event_type, region_id, region));
408 if (status != SERVICE_WORKER_OK) {
409 geofencing_callbacks_.Remove(request_id);
410 RunSoon(base::Bind(callback, status));
411 }
412 }
413
377 void ServiceWorkerVersion::AddControllee( 414 void ServiceWorkerVersion::AddControllee(
378 ServiceWorkerProviderHost* provider_host) { 415 ServiceWorkerProviderHost* provider_host) {
379 DCHECK(!ContainsKey(controllee_map_, provider_host)); 416 DCHECK(!ContainsKey(controllee_map_, provider_host));
380 int controllee_id = controllee_by_id_.Add(provider_host); 417 int controllee_id = controllee_by_id_.Add(provider_host);
381 controllee_map_[provider_host] = controllee_id; 418 controllee_map_[provider_host] = controllee_id;
382 if (stop_worker_timer_.IsRunning()) 419 if (stop_worker_timer_.IsRunning())
383 stop_worker_timer_.Stop(); 420 stop_worker_timer_.Stop();
384 } 421 }
385 422
386 void ServiceWorkerVersion::RemoveControllee( 423 void ServiceWorkerVersion::RemoveControllee(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, 531 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished,
495 OnActivateEventFinished) 532 OnActivateEventFinished)
496 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, 533 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished,
497 OnInstallEventFinished) 534 OnInstallEventFinished)
498 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, 535 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished,
499 OnFetchEventFinished) 536 OnFetchEventFinished)
500 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, 537 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished,
501 OnSyncEventFinished) 538 OnSyncEventFinished)
502 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, 539 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished,
503 OnPushEventFinished) 540 OnPushEventFinished)
541 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished,
542 OnGeofencingEventFinished)
504 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument, 543 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument,
505 OnPostMessageToDocument) 544 OnPostMessageToDocument)
506 IPC_MESSAGE_UNHANDLED(handled = false) 545 IPC_MESSAGE_UNHANDLED(handled = false)
507 IPC_END_MESSAGE_MAP() 546 IPC_END_MESSAGE_MAP()
508 return handled; 547 return handled;
509 } 548 }
510 549
511 void ServiceWorkerVersion::RunStartWorkerCallbacksOnError( 550 void ServiceWorkerVersion::RunStartWorkerCallbacksOnError(
512 ServiceWorkerStatusCode status) { 551 ServiceWorkerStatusCode status) {
513 if (status != SERVICE_WORKER_OK) 552 if (status != SERVICE_WORKER_OK)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 if (!callback) { 686 if (!callback) {
648 NOTREACHED() << "Got unexpected message: " << request_id; 687 NOTREACHED() << "Got unexpected message: " << request_id;
649 return; 688 return;
650 } 689 }
651 690
652 scoped_refptr<ServiceWorkerVersion> protect(this); 691 scoped_refptr<ServiceWorkerVersion> protect(this);
653 callback->Run(SERVICE_WORKER_OK); 692 callback->Run(SERVICE_WORKER_OK);
654 push_callbacks_.Remove(request_id); 693 push_callbacks_.Remove(request_id);
655 } 694 }
656 695
696 void ServiceWorkerVersion::OnGeofencingEventFinished(int request_id) {
697 TRACE_EVENT1("ServiceWorker",
698 "ServiceWorkerVersion::OnGeofencingEventFinished",
699 "Request id",
700 request_id);
701 StatusCallback* callback = geofencing_callbacks_.Lookup(request_id);
702 if (!callback) {
703 NOTREACHED() << "Got unexpected message: " << request_id;
704 return;
705 }
706
707 scoped_refptr<ServiceWorkerVersion> protect(this);
708 callback->Run(SERVICE_WORKER_OK);
709 geofencing_callbacks_.Remove(request_id);
710 }
711
657 void ServiceWorkerVersion::OnPostMessageToDocument( 712 void ServiceWorkerVersion::OnPostMessageToDocument(
658 int client_id, 713 int client_id,
659 const base::string16& message, 714 const base::string16& message,
660 const std::vector<int>& sent_message_port_ids) { 715 const std::vector<int>& sent_message_port_ids) {
661 TRACE_EVENT1("ServiceWorker", 716 TRACE_EVENT1("ServiceWorker",
662 "ServiceWorkerVersion::OnPostMessageToDocument", 717 "ServiceWorkerVersion::OnPostMessageToDocument",
663 "Client id", client_id); 718 "Client id", client_id);
664 ServiceWorkerProviderHost* provider_host = 719 ServiceWorkerProviderHost* provider_host =
665 controllee_by_id_.Lookup(client_id); 720 controllee_by_id_.Lookup(client_id);
666 if (!provider_host) { 721 if (!provider_host) {
(...skipping 22 matching lines...) Expand all
689 SetStatus(REDUNDANT); 744 SetStatus(REDUNDANT);
690 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 745 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
691 if (!context_) 746 if (!context_)
692 return; 747 return;
693 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 748 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
694 script_cache_map_.GetResources(&resources); 749 script_cache_map_.GetResources(&resources);
695 context_->storage()->PurgeResources(resources); 750 context_->storage()->PurgeResources(resources);
696 } 751 }
697 752
698 } // namespace content 753 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698