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

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: nit Created 6 years, 1 month 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
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/common/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 &FetchCallback::Run, 486 &FetchCallback::Run,
450 MakeTuple(SERVICE_WORKER_ERROR_FAILED, 487 MakeTuple(SERVICE_WORKER_ERROR_FAILED,
451 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, 488 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK,
452 ServiceWorkerResponse())); 489 ServiceWorkerResponse()));
453 RunIDMapCallbacks(&sync_callbacks_, 490 RunIDMapCallbacks(&sync_callbacks_,
454 &StatusCallback::Run, 491 &StatusCallback::Run,
455 MakeTuple(SERVICE_WORKER_ERROR_FAILED)); 492 MakeTuple(SERVICE_WORKER_ERROR_FAILED));
456 RunIDMapCallbacks(&push_callbacks_, 493 RunIDMapCallbacks(&push_callbacks_,
457 &StatusCallback::Run, 494 &StatusCallback::Run,
458 MakeTuple(SERVICE_WORKER_ERROR_FAILED)); 495 MakeTuple(SERVICE_WORKER_ERROR_FAILED));
496 RunIDMapCallbacks(&geofencing_callbacks_,
497 &StatusCallback::Run,
498 MakeTuple(SERVICE_WORKER_ERROR_FAILED));
459 499
460 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStopped(this)); 500 FOR_EACH_OBSERVER(Listener, listeners_, OnWorkerStopped(this));
461 501
462 // There should be no more communication from/to a stopped worker. Deleting 502 // There should be no more communication from/to a stopped worker. Deleting
463 // the listener prevents any pending completion callbacks from causing 503 // the listener prevents any pending completion callbacks from causing
464 // messages to be sent to the stopped worker. 504 // messages to be sent to the stopped worker.
465 cache_listener_.reset(); 505 cache_listener_.reset();
466 } 506 }
467 507
468 void ServiceWorkerVersion::OnReportException( 508 void ServiceWorkerVersion::OnReportException(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, 540 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished,
501 OnActivateEventFinished) 541 OnActivateEventFinished)
502 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, 542 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished,
503 OnInstallEventFinished) 543 OnInstallEventFinished)
504 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, 544 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished,
505 OnFetchEventFinished) 545 OnFetchEventFinished)
506 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, 546 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished,
507 OnSyncEventFinished) 547 OnSyncEventFinished)
508 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, 548 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished,
509 OnPushEventFinished) 549 OnPushEventFinished)
550 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished,
551 OnGeofencingEventFinished)
510 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument, 552 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument,
511 OnPostMessageToDocument) 553 OnPostMessageToDocument)
512 IPC_MESSAGE_UNHANDLED(handled = false) 554 IPC_MESSAGE_UNHANDLED(handled = false)
513 IPC_END_MESSAGE_MAP() 555 IPC_END_MESSAGE_MAP()
514 return handled; 556 return handled;
515 } 557 }
516 558
517 void ServiceWorkerVersion::OnStartMessageSent( 559 void ServiceWorkerVersion::OnStartMessageSent(
518 ServiceWorkerStatusCode status) { 560 ServiceWorkerStatusCode status) {
519 if (status != SERVICE_WORKER_OK) 561 if (status != SERVICE_WORKER_OK)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 if (!callback) { 695 if (!callback) {
654 NOTREACHED() << "Got unexpected message: " << request_id; 696 NOTREACHED() << "Got unexpected message: " << request_id;
655 return; 697 return;
656 } 698 }
657 699
658 scoped_refptr<ServiceWorkerVersion> protect(this); 700 scoped_refptr<ServiceWorkerVersion> protect(this);
659 callback->Run(SERVICE_WORKER_OK); 701 callback->Run(SERVICE_WORKER_OK);
660 push_callbacks_.Remove(request_id); 702 push_callbacks_.Remove(request_id);
661 } 703 }
662 704
705 void ServiceWorkerVersion::OnGeofencingEventFinished(int request_id) {
706 TRACE_EVENT1("ServiceWorker",
707 "ServiceWorkerVersion::OnGeofencingEventFinished",
708 "Request id",
709 request_id);
710 StatusCallback* callback = geofencing_callbacks_.Lookup(request_id);
711 if (!callback) {
712 NOTREACHED() << "Got unexpected message: " << request_id;
713 return;
714 }
715
716 scoped_refptr<ServiceWorkerVersion> protect(this);
717 callback->Run(SERVICE_WORKER_OK);
718 geofencing_callbacks_.Remove(request_id);
719 }
720
663 void ServiceWorkerVersion::OnPostMessageToDocument( 721 void ServiceWorkerVersion::OnPostMessageToDocument(
664 int client_id, 722 int client_id,
665 const base::string16& message, 723 const base::string16& message,
666 const std::vector<int>& sent_message_port_ids) { 724 const std::vector<int>& sent_message_port_ids) {
667 TRACE_EVENT1("ServiceWorker", 725 TRACE_EVENT1("ServiceWorker",
668 "ServiceWorkerVersion::OnPostMessageToDocument", 726 "ServiceWorkerVersion::OnPostMessageToDocument",
669 "Client id", client_id); 727 "Client id", client_id);
670 ServiceWorkerProviderHost* provider_host = 728 ServiceWorkerProviderHost* provider_host =
671 controllee_by_id_.Lookup(client_id); 729 controllee_by_id_.Lookup(client_id);
672 if (!provider_host) { 730 if (!provider_host) {
(...skipping 22 matching lines...) Expand all
695 SetStatus(REDUNDANT); 753 SetStatus(REDUNDANT);
696 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 754 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
697 if (!context_) 755 if (!context_)
698 return; 756 return;
699 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 757 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
700 script_cache_map_.GetResources(&resources); 758 script_cache_map_.GetResources(&resources);
701 context_->storage()->PurgeResources(resources); 759 context_->storage()->PurgeResources(resources);
702 } 760 }
703 761
704 } // namespace content 762 } // namespace content
OLDNEW
« 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