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

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: rebase 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, 537 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished,
501 OnActivateEventFinished) 538 OnActivateEventFinished)
502 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, 539 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished,
503 OnInstallEventFinished) 540 OnInstallEventFinished)
504 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, 541 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished,
505 OnFetchEventFinished) 542 OnFetchEventFinished)
506 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, 543 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished,
507 OnSyncEventFinished) 544 OnSyncEventFinished)
508 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, 545 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished,
509 OnPushEventFinished) 546 OnPushEventFinished)
547 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished,
548 OnGeofencingEventFinished)
510 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument, 549 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument,
511 OnPostMessageToDocument) 550 OnPostMessageToDocument)
512 IPC_MESSAGE_UNHANDLED(handled = false) 551 IPC_MESSAGE_UNHANDLED(handled = false)
513 IPC_END_MESSAGE_MAP() 552 IPC_END_MESSAGE_MAP()
514 return handled; 553 return handled;
515 } 554 }
516 555
517 void ServiceWorkerVersion::OnStartMessageSent( 556 void ServiceWorkerVersion::OnStartMessageSent(
518 ServiceWorkerStatusCode status) { 557 ServiceWorkerStatusCode status) {
519 if (status != SERVICE_WORKER_OK) 558 if (status != SERVICE_WORKER_OK)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 if (!callback) { 692 if (!callback) {
654 NOTREACHED() << "Got unexpected message: " << request_id; 693 NOTREACHED() << "Got unexpected message: " << request_id;
655 return; 694 return;
656 } 695 }
657 696
658 scoped_refptr<ServiceWorkerVersion> protect(this); 697 scoped_refptr<ServiceWorkerVersion> protect(this);
659 callback->Run(SERVICE_WORKER_OK); 698 callback->Run(SERVICE_WORKER_OK);
660 push_callbacks_.Remove(request_id); 699 push_callbacks_.Remove(request_id);
661 } 700 }
662 701
702 void ServiceWorkerVersion::OnGeofencingEventFinished(int request_id) {
703 TRACE_EVENT1("ServiceWorker",
704 "ServiceWorkerVersion::OnGeofencingEventFinished",
705 "Request id",
706 request_id);
707 StatusCallback* callback = geofencing_callbacks_.Lookup(request_id);
708 if (!callback) {
709 NOTREACHED() << "Got unexpected message: " << request_id;
710 return;
711 }
712
713 scoped_refptr<ServiceWorkerVersion> protect(this);
714 callback->Run(SERVICE_WORKER_OK);
715 geofencing_callbacks_.Remove(request_id);
716 }
717
663 void ServiceWorkerVersion::OnPostMessageToDocument( 718 void ServiceWorkerVersion::OnPostMessageToDocument(
664 int client_id, 719 int client_id,
665 const base::string16& message, 720 const base::string16& message,
666 const std::vector<int>& sent_message_port_ids) { 721 const std::vector<int>& sent_message_port_ids) {
667 TRACE_EVENT1("ServiceWorker", 722 TRACE_EVENT1("ServiceWorker",
668 "ServiceWorkerVersion::OnPostMessageToDocument", 723 "ServiceWorkerVersion::OnPostMessageToDocument",
669 "Client id", client_id); 724 "Client id", client_id);
670 ServiceWorkerProviderHost* provider_host = 725 ServiceWorkerProviderHost* provider_host =
671 controllee_by_id_.Lookup(client_id); 726 controllee_by_id_.Lookup(client_id);
672 if (!provider_host) { 727 if (!provider_host) {
(...skipping 22 matching lines...) Expand all
695 SetStatus(REDUNDANT); 750 SetStatus(REDUNDANT);
696 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 751 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
697 if (!context_) 752 if (!context_)
698 return; 753 return;
699 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 754 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
700 script_cache_map_.GetResources(&resources); 755 script_cache_map_.GetResources(&resources);
701 context_->storage()->PurgeResources(resources); 756 context_->storage()->PurgeResources(resources);
702 } 757 }
703 758
704 } // namespace content 759 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698