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

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 668303004: WIP DO NOT COMMIT chromium side of navigator.connect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years 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/message_port_message_filter.h" 10 #include "content/browser/message_port_message_filter.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 task.Run(); 82 task.Run();
83 } 83 }
84 84
85 void RunErrorFetchCallback(const ServiceWorkerVersion::FetchCallback& callback, 85 void RunErrorFetchCallback(const ServiceWorkerVersion::FetchCallback& callback,
86 ServiceWorkerStatusCode status) { 86 ServiceWorkerStatusCode status) {
87 callback.Run(status, 87 callback.Run(status,
88 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, 88 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK,
89 ServiceWorkerResponse()); 89 ServiceWorkerResponse());
90 } 90 }
91 91
92 void RunErrorCrossOriginConnectCallback(
93 const ServiceWorkerVersion::CrossOriginConnectCallback& callback,
94 ServiceWorkerStatusCode status) {
95 callback.Run(status, false);
96 }
97
92 void RunErrorMessageCallback( 98 void RunErrorMessageCallback(
93 const std::vector<int>& sent_message_port_ids, 99 const std::vector<int>& sent_message_port_ids,
94 const ServiceWorkerVersion::StatusCallback& callback, 100 const ServiceWorkerVersion::StatusCallback& callback,
95 ServiceWorkerStatusCode status) { 101 ServiceWorkerStatusCode status) {
96 // Transfering the message ports failed, so destroy the ports. 102 // Transfering the message ports failed, so destroy the ports.
97 for (int message_port_id : sent_message_port_ids) { 103 for (int message_port_id : sent_message_port_ids) {
98 MessagePortService::GetInstance()->ClosePort(message_port_id); 104 MessagePortService::GetInstance()->ClosePort(message_port_id);
99 } 105 }
100 callback.Run(status); 106 callback.Run(status);
101 } 107 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 embedded_worker_->message_port_message_filter(); 296 embedded_worker_->message_port_message_filter();
291 std::vector<int> new_routing_ids; 297 std::vector<int> new_routing_ids;
292 filter->UpdateMessagePortsWithNewRoutes(sent_message_port_ids, 298 filter->UpdateMessagePortsWithNewRoutes(sent_message_port_ids,
293 &new_routing_ids); 299 &new_routing_ids);
294 ServiceWorkerStatusCode status = 300 ServiceWorkerStatusCode status =
295 embedded_worker_->SendMessage(ServiceWorkerMsg_MessageToWorker( 301 embedded_worker_->SendMessage(ServiceWorkerMsg_MessageToWorker(
296 message, sent_message_port_ids, new_routing_ids)); 302 message, sent_message_port_ids, new_routing_ids));
297 RunSoon(base::Bind(callback, status)); 303 RunSoon(base::Bind(callback, status));
298 } 304 }
299 305
306 void ServiceWorkerVersion::SendCrossOriginMessage(
307 const CrossOriginServiceWorkerClient& client,
308 const base::string16& message,
309 const std::vector<int>& sent_message_port_ids,
310 const ServiceWorkerVersion::StatusCallback& callback) {
311 if (running_status() != RUNNING) {
312 // Schedule calling this method after starting the worker.
313 StartWorker(base::Bind(
314 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback,
315 base::Bind(&self::SendCrossOriginMessage, weak_factory_.GetWeakPtr(),
316 client, message, sent_message_port_ids, callback)));
317 return;
318 }
319
320 MessagePortMessageFilter* filter =
321 embedded_worker_->message_port_message_filter();
322 std::vector<int> new_routing_ids;
323 filter->UpdateMessagePortsWithNewRoutes(sent_message_port_ids,
324 &new_routing_ids);
325 ServiceWorkerStatusCode status =
326 embedded_worker_->SendMessage(ServiceWorkerMsg_CrossOriginMessageToWorker(
327 client, message, sent_message_port_ids, new_routing_ids));
328 RunSoon(base::Bind(callback, status));
329 }
330
300 void ServiceWorkerVersion::DispatchInstallEvent( 331 void ServiceWorkerVersion::DispatchInstallEvent(
301 int active_version_id, 332 int active_version_id,
302 const StatusCallback& callback) { 333 const StatusCallback& callback) {
303 DCHECK_EQ(INSTALLING, status()) << status(); 334 DCHECK_EQ(INSTALLING, status()) << status();
304 335
305 if (running_status() != RUNNING) { 336 if (running_status() != RUNNING) {
306 // Schedule calling this method after starting the worker. 337 // Schedule calling this method after starting the worker.
307 StartWorker( 338 StartWorker(
308 base::Bind(&RunTaskAfterStartWorker, 339 base::Bind(&RunTaskAfterStartWorker,
309 weak_factory_.GetWeakPtr(), 340 weak_factory_.GetWeakPtr(),
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 int request_id = geofencing_callbacks_.Add(new StatusCallback(callback)); 516 int request_id = geofencing_callbacks_.Add(new StatusCallback(callback));
486 ServiceWorkerStatusCode status = 517 ServiceWorkerStatusCode status =
487 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent( 518 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent(
488 request_id, event_type, region_id, region)); 519 request_id, event_type, region_id, region));
489 if (status != SERVICE_WORKER_OK) { 520 if (status != SERVICE_WORKER_OK) {
490 geofencing_callbacks_.Remove(request_id); 521 geofencing_callbacks_.Remove(request_id);
491 RunSoon(base::Bind(callback, status)); 522 RunSoon(base::Bind(callback, status));
492 } 523 }
493 } 524 }
494 525
526 void ServiceWorkerVersion::DispatchCrossOriginConnectEvent(
527 const CrossOriginConnectCallback& callback,
528 const GURL& target_url,
529 int message_port_id) {
530 DCHECK_EQ(ACTIVATED, status()) << status();
531
532 if (!CommandLine::ForCurrentProcess()->HasSwitch(
533 switches::kEnableExperimentalWebPlatformFeatures)) {
534 callback.Run(SERVICE_WORKER_ERROR_ABORT, false);
535 return;
536 }
537
538 if (running_status() != RUNNING) {
539 // Schedule calling this method after starting the worker.
540 StartWorker(
541 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(),
542 base::Bind(&RunErrorCrossOriginConnectCallback, callback),
543 base::Bind(&self::DispatchCrossOriginConnectEvent,
544 weak_factory_.GetWeakPtr(), callback, target_url,
545 message_port_id)));
546 return;
547 }
548
549 int request_id = cross_origin_connect_callbacks_.Add(
550 new CrossOriginConnectCallback(callback));
551 ServiceWorkerStatusCode status =
552 embedded_worker_->SendMessage(ServiceWorkerMsg_CrossOriginConnectEvent(
553 request_id,
554 CrossOriginServiceWorkerClient(target_url, message_port_id)));
555 if (status != SERVICE_WORKER_OK) {
556 cross_origin_connect_callbacks_.Remove(request_id);
557 RunSoon(base::Bind(callback, status, false));
558 }
559 }
560
495 void ServiceWorkerVersion::AddControllee( 561 void ServiceWorkerVersion::AddControllee(
496 ServiceWorkerProviderHost* provider_host) { 562 ServiceWorkerProviderHost* provider_host) {
497 DCHECK(!ContainsKey(controllee_map_, provider_host)); 563 DCHECK(!ContainsKey(controllee_map_, provider_host));
498 int controllee_id = controllee_by_id_.Add(provider_host); 564 int controllee_id = controllee_by_id_.Add(provider_host);
499 controllee_map_[provider_host] = controllee_id; 565 controllee_map_[provider_host] = controllee_id;
500 if (stop_worker_timer_.IsRunning()) 566 if (stop_worker_timer_.IsRunning())
501 stop_worker_timer_.Stop(); 567 stop_worker_timer_.Stop();
502 } 568 }
503 569
504 void ServiceWorkerVersion::RemoveControllee( 570 void ServiceWorkerVersion::RemoveControllee(
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, 691 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished,
626 OnFetchEventFinished) 692 OnFetchEventFinished)
627 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished, 693 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SyncEventFinished,
628 OnSyncEventFinished) 694 OnSyncEventFinished)
629 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, 695 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished,
630 OnNotificationClickEventFinished) 696 OnNotificationClickEventFinished)
631 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, 697 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished,
632 OnPushEventFinished) 698 OnPushEventFinished)
633 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, 699 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished,
634 OnGeofencingEventFinished) 700 OnGeofencingEventFinished)
701 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished,
702 OnCrossOriginConnectEventFinished)
635 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument, 703 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument,
636 OnPostMessageToDocument) 704 OnPostMessageToDocument)
637 IPC_MESSAGE_UNHANDLED(handled = false) 705 IPC_MESSAGE_UNHANDLED(handled = false)
638 IPC_END_MESSAGE_MAP() 706 IPC_END_MESSAGE_MAP()
639 return handled; 707 return handled;
640 } 708 }
641 709
642 void ServiceWorkerVersion::OnStartMessageSent( 710 void ServiceWorkerVersion::OnStartMessageSent(
643 ServiceWorkerStatusCode status) { 711 ServiceWorkerStatusCode status) {
644 if (status != SERVICE_WORKER_OK) 712 if (status != SERVICE_WORKER_OK)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 if (!callback) { 882 if (!callback) {
815 NOTREACHED() << "Got unexpected message: " << request_id; 883 NOTREACHED() << "Got unexpected message: " << request_id;
816 return; 884 return;
817 } 885 }
818 886
819 scoped_refptr<ServiceWorkerVersion> protect(this); 887 scoped_refptr<ServiceWorkerVersion> protect(this);
820 callback->Run(SERVICE_WORKER_OK); 888 callback->Run(SERVICE_WORKER_OK);
821 geofencing_callbacks_.Remove(request_id); 889 geofencing_callbacks_.Remove(request_id);
822 } 890 }
823 891
892 void ServiceWorkerVersion::OnCrossOriginConnectEventFinished(
893 int request_id,
894 bool allow_connect) {
895 TRACE_EVENT1("ServiceWorker",
896 "ServiceWorkerVersion::OnCrossOriginConnectEventFinished",
897 "Request id", request_id);
898 CrossOriginConnectCallback* callback =
899 cross_origin_connect_callbacks_.Lookup(request_id);
900 if (!callback) {
901 NOTREACHED() << "Got unexpected message: " << request_id;
902 return;
903 }
904
905 scoped_refptr<ServiceWorkerVersion> protect(this);
906 callback->Run(SERVICE_WORKER_OK, allow_connect);
907 cross_origin_connect_callbacks_.Remove(request_id);
908 }
909
824 void ServiceWorkerVersion::OnPostMessageToDocument( 910 void ServiceWorkerVersion::OnPostMessageToDocument(
825 int client_id, 911 int client_id,
826 const base::string16& message, 912 const base::string16& message,
827 const std::vector<int>& sent_message_port_ids) { 913 const std::vector<int>& sent_message_port_ids) {
828 TRACE_EVENT1("ServiceWorker", 914 TRACE_EVENT1("ServiceWorker",
829 "ServiceWorkerVersion::OnPostMessageToDocument", 915 "ServiceWorkerVersion::OnPostMessageToDocument",
830 "Client id", client_id); 916 "Client id", client_id);
831 ServiceWorkerProviderHost* provider_host = 917 ServiceWorkerProviderHost* provider_host =
832 controllee_by_id_.Lookup(client_id); 918 controllee_by_id_.Lookup(client_id);
833 if (!provider_host) { 919 if (!provider_host) {
(...skipping 22 matching lines...) Expand all
856 SetStatus(REDUNDANT); 942 SetStatus(REDUNDANT);
857 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 943 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
858 if (!context_) 944 if (!context_)
859 return; 945 return;
860 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; 946 std::vector<ServiceWorkerDatabase::ResourceRecord> resources;
861 script_cache_map_.GetResources(&resources); 947 script_cache_map_.GetResources(&resources);
862 context_->storage()->PurgeResources(resources); 948 context_->storage()->PurgeResources(resources);
863 } 949 }
864 950
865 } // namespace content 951 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/browser/shared_worker/shared_worker_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698