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

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

Issue 1974613002: Remove code that was only used by navigator.connect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comment Created 4 years, 7 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_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 bad_message::ReceivedBadMessage( 673 bad_message::ReceivedBadMessage(
674 this, bad_message::SWDH_GET_REGISTRATION_FOR_READY_ALREADY_IN_PROGRESS); 674 this, bad_message::SWDH_GET_REGISTRATION_FOR_READY_ALREADY_IN_PROGRESS);
675 } 675 }
676 } 676 }
677 677
678 void ServiceWorkerDispatcherHost::OnPostMessageToWorker( 678 void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
679 int handle_id, 679 int handle_id,
680 int provider_id, 680 int provider_id,
681 const base::string16& message, 681 const base::string16& message,
682 const url::Origin& source_origin, 682 const url::Origin& source_origin,
683 const std::vector<TransferredMessagePort>& sent_message_ports) { 683 const std::vector<int>& sent_message_ports) {
684 TRACE_EVENT0("ServiceWorker", 684 TRACE_EVENT0("ServiceWorker",
685 "ServiceWorkerDispatcherHost::OnPostMessageToWorker"); 685 "ServiceWorkerDispatcherHost::OnPostMessageToWorker");
686 if (!GetContext()) 686 if (!GetContext())
687 return; 687 return;
688 688
689 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); 689 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
690 if (!handle) { 690 if (!handle) {
691 bad_message::ReceivedBadMessage(this, bad_message::SWDH_POST_MESSAGE); 691 bad_message::ReceivedBadMessage(this, bad_message::SWDH_POST_MESSAGE);
692 return; 692 return;
693 } 693 }
694 694
695 ServiceWorkerProviderHost* sender_provider_host = 695 ServiceWorkerProviderHost* sender_provider_host =
696 GetContext()->GetProviderHost(render_process_id_, provider_id); 696 GetContext()->GetProviderHost(render_process_id_, provider_id);
697 if (!sender_provider_host) { 697 if (!sender_provider_host) {
698 bad_message::ReceivedBadMessage(this, bad_message::SWDH_POST_MESSAGE); 698 bad_message::ReceivedBadMessage(this, bad_message::SWDH_POST_MESSAGE);
699 return; 699 return;
700 } 700 }
701 701
702 DispatchExtendableMessageEvent( 702 DispatchExtendableMessageEvent(
703 make_scoped_refptr(handle->version()), message, source_origin, 703 make_scoped_refptr(handle->version()), message, source_origin,
704 sent_message_ports, sender_provider_host, 704 sent_message_ports, sender_provider_host,
705 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 705 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
706 } 706 }
707 707
708 void ServiceWorkerDispatcherHost::DispatchExtendableMessageEvent( 708 void ServiceWorkerDispatcherHost::DispatchExtendableMessageEvent(
709 scoped_refptr<ServiceWorkerVersion> worker, 709 scoped_refptr<ServiceWorkerVersion> worker,
710 const base::string16& message, 710 const base::string16& message,
711 const url::Origin& source_origin, 711 const url::Origin& source_origin,
712 const std::vector<TransferredMessagePort>& sent_message_ports, 712 const std::vector<int>& sent_message_ports,
713 ServiceWorkerProviderHost* sender_provider_host, 713 ServiceWorkerProviderHost* sender_provider_host,
714 const StatusCallback& callback) { 714 const StatusCallback& callback) {
715 for (const TransferredMessagePort& port : sent_message_ports) 715 for (int port : sent_message_ports)
716 MessagePortService::GetInstance()->HoldMessages(port.id); 716 MessagePortService::GetInstance()->HoldMessages(port);
717 717
718 switch (sender_provider_host->provider_type()) { 718 switch (sender_provider_host->provider_type()) {
719 case SERVICE_WORKER_PROVIDER_FOR_WINDOW: 719 case SERVICE_WORKER_PROVIDER_FOR_WINDOW:
720 case SERVICE_WORKER_PROVIDER_FOR_WORKER: 720 case SERVICE_WORKER_PROVIDER_FOR_WORKER:
721 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER: 721 case SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER:
722 service_worker_client_utils::GetClient( 722 service_worker_client_utils::GetClient(
723 sender_provider_host, 723 sender_provider_host,
724 base::Bind(&ServiceWorkerDispatcherHost:: 724 base::Bind(&ServiceWorkerDispatcherHost::
725 DispatchExtendableMessageEventInternal< 725 DispatchExtendableMessageEventInternal<
726 ServiceWorkerClientInfo>, 726 ServiceWorkerClientInfo>,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 855
856 Send(new ServiceWorkerMsg_AssociateRegistration(kDocumentMainThreadId, 856 Send(new ServiceWorkerMsg_AssociateRegistration(kDocumentMainThreadId,
857 provider_id, info, attrs)); 857 provider_id, info, attrs));
858 } 858 }
859 859
860 template <typename SourceInfo> 860 template <typename SourceInfo>
861 void ServiceWorkerDispatcherHost::DispatchExtendableMessageEventInternal( 861 void ServiceWorkerDispatcherHost::DispatchExtendableMessageEventInternal(
862 scoped_refptr<ServiceWorkerVersion> worker, 862 scoped_refptr<ServiceWorkerVersion> worker,
863 const base::string16& message, 863 const base::string16& message,
864 const url::Origin& source_origin, 864 const url::Origin& source_origin,
865 const std::vector<TransferredMessagePort>& sent_message_ports, 865 const std::vector<int>& sent_message_ports,
866 const StatusCallback& callback, 866 const StatusCallback& callback,
867 const SourceInfo& source_info) { 867 const SourceInfo& source_info) {
868 if (!source_info.IsValid()) { 868 if (!source_info.IsValid()) {
869 DidFailToDispatchExtendableMessageEvent<SourceInfo>( 869 DidFailToDispatchExtendableMessageEvent<SourceInfo>(
870 sent_message_ports, source_info, callback, SERVICE_WORKER_ERROR_FAILED); 870 sent_message_ports, source_info, callback, SERVICE_WORKER_ERROR_FAILED);
871 return; 871 return;
872 } 872 }
873 worker->RunAfterStartWorker( 873 worker->RunAfterStartWorker(
874 ServiceWorkerMetrics::EventType::MESSAGE, 874 ServiceWorkerMetrics::EventType::MESSAGE,
875 base::Bind(&ServiceWorkerDispatcherHost:: 875 base::Bind(&ServiceWorkerDispatcherHost::
876 DispatchExtendableMessageEventAfterStartWorker, 876 DispatchExtendableMessageEventAfterStartWorker,
877 this, worker, message, source_origin, sent_message_ports, 877 this, worker, message, source_origin, sent_message_ports,
878 ExtendableMessageEventSource(source_info), callback), 878 ExtendableMessageEventSource(source_info), callback),
879 base::Bind( 879 base::Bind(
880 &ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent< 880 &ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent<
881 SourceInfo>, 881 SourceInfo>,
882 this, sent_message_ports, source_info, callback)); 882 this, sent_message_ports, source_info, callback));
883 } 883 }
884 884
885 void ServiceWorkerDispatcherHost:: 885 void ServiceWorkerDispatcherHost::
886 DispatchExtendableMessageEventAfterStartWorker( 886 DispatchExtendableMessageEventAfterStartWorker(
887 scoped_refptr<ServiceWorkerVersion> worker, 887 scoped_refptr<ServiceWorkerVersion> worker,
888 const base::string16& message, 888 const base::string16& message,
889 const url::Origin& source_origin, 889 const url::Origin& source_origin,
890 const std::vector<TransferredMessagePort>& sent_message_ports, 890 const std::vector<int>& sent_message_ports,
891 const ExtendableMessageEventSource& source, 891 const ExtendableMessageEventSource& source,
892 const StatusCallback& callback) { 892 const StatusCallback& callback) {
893 int request_id = 893 int request_id =
894 worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, callback); 894 worker->StartRequest(ServiceWorkerMetrics::EventType::MESSAGE, callback);
895 895
896 MessagePortMessageFilter* filter = 896 MessagePortMessageFilter* filter =
897 worker->embedded_worker()->message_port_message_filter(); 897 worker->embedded_worker()->message_port_message_filter();
898 std::vector<int> new_routing_ids; 898 std::vector<int> new_routing_ids;
899 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); 899 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids);
900 900
(...skipping 12 matching lines...) Expand all
913 params.source.service_worker_info.url = GURL(); 913 params.source.service_worker_info.url = GURL();
914 } 914 }
915 915
916 worker->DispatchSimpleEvent< 916 worker->DispatchSimpleEvent<
917 ServiceWorkerHostMsg_ExtendableMessageEventFinished>( 917 ServiceWorkerHostMsg_ExtendableMessageEventFinished>(
918 request_id, ServiceWorkerMsg_ExtendableMessageEvent(request_id, params)); 918 request_id, ServiceWorkerMsg_ExtendableMessageEvent(request_id, params));
919 } 919 }
920 920
921 template <typename SourceInfo> 921 template <typename SourceInfo>
922 void ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent( 922 void ServiceWorkerDispatcherHost::DidFailToDispatchExtendableMessageEvent(
923 const std::vector<TransferredMessagePort>& sent_message_ports, 923 const std::vector<int>& sent_message_ports,
924 const SourceInfo& source_info, 924 const SourceInfo& source_info,
925 const StatusCallback& callback, 925 const StatusCallback& callback,
926 ServiceWorkerStatusCode status) { 926 ServiceWorkerStatusCode status) {
927 // Transfering the message ports failed, so destroy the ports. 927 // Transfering the message ports failed, so destroy the ports.
928 for (const TransferredMessagePort& port : sent_message_ports) 928 for (int port : sent_message_ports)
929 MessagePortService::GetInstance()->ClosePort(port.id); 929 MessagePortService::GetInstance()->ClosePort(port);
930 if (source_info.IsValid()) 930 if (source_info.IsValid())
931 ReleaseSourceInfo(source_info); 931 ReleaseSourceInfo(source_info);
932 callback.Run(status); 932 callback.Run(status);
933 } 933 }
934 934
935 void ServiceWorkerDispatcherHost::ReleaseSourceInfo( 935 void ServiceWorkerDispatcherHost::ReleaseSourceInfo(
936 const ServiceWorkerClientInfo& source_info) { 936 const ServiceWorkerClientInfo& source_info) {
937 // ServiceWorkerClientInfo is just a snapshot of the client. There is no need 937 // ServiceWorkerClientInfo is just a snapshot of the client. There is no need
938 // to do anything for it. 938 // to do anything for it.
939 } 939 }
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 if (!handle) { 1405 if (!handle) {
1406 bad_message::ReceivedBadMessage(this, 1406 bad_message::ReceivedBadMessage(this,
1407 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1407 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1408 return; 1408 return;
1409 } 1409 }
1410 handle->version()->StopWorker( 1410 handle->version()->StopWorker(
1411 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1411 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1412 } 1412 }
1413 1413
1414 } // namespace content 1414 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698