OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 const std::vector<TransferredMessagePort>& sent_message_ports, | 151 const std::vector<TransferredMessagePort>& sent_message_ports, |
152 const ServiceWorkerVersion::StatusCallback& callback, | 152 const ServiceWorkerVersion::StatusCallback& callback, |
153 ServiceWorkerStatusCode status) { | 153 ServiceWorkerStatusCode status) { |
154 // Transfering the message ports failed, so destroy the ports. | 154 // Transfering the message ports failed, so destroy the ports. |
155 for (const TransferredMessagePort& port : sent_message_ports) { | 155 for (const TransferredMessagePort& port : sent_message_ports) { |
156 MessagePortService::GetInstance()->ClosePort(port.id); | 156 MessagePortService::GetInstance()->ClosePort(port.id); |
157 } | 157 } |
158 callback.Run(status); | 158 callback.Run(status); |
159 } | 159 } |
160 | 160 |
161 void RunErrorServicePortConnectCallback( | |
162 const ServiceWorkerVersion::ServicePortConnectCallback& callback, | |
163 ServiceWorkerStatusCode status) { | |
164 callback.Run(status, false /* accept_connection */, base::string16(), | |
165 base::string16()); | |
166 } | |
167 | |
168 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { | 161 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { |
169 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 162 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
170 RenderProcessHost* render_process_host = | 163 RenderProcessHost* render_process_host = |
171 RenderProcessHost::FromID(process_id); | 164 RenderProcessHost::FromID(process_id); |
172 if (render_process_host->GetHandle() != base::kNullProcessHandle) { | 165 if (render_process_host->GetHandle() != base::kNullProcessHandle) { |
173 bad_message::ReceivedBadMessage(render_process_host, | 166 bad_message::ReceivedBadMessage(render_process_host, |
174 bad_message::SERVICE_WORKER_BAD_URL); | 167 bad_message::SERVICE_WORKER_BAD_URL); |
175 } | 168 } |
176 } | 169 } |
177 | 170 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 registration_id_, scope_.GetOrigin(), | 466 registration_id_, scope_.GetOrigin(), |
474 base::Bind(&ServiceWorkerVersion::FoundRegistrationForUpdate, | 467 base::Bind(&ServiceWorkerVersion::FoundRegistrationForUpdate, |
475 weak_factory_.GetWeakPtr())); | 468 weak_factory_.GetWeakPtr())); |
476 } | 469 } |
477 | 470 |
478 void ServiceWorkerVersion::DeferScheduledUpdate() { | 471 void ServiceWorkerVersion::DeferScheduledUpdate() { |
479 if (update_timer_.IsRunning()) | 472 if (update_timer_.IsRunning()) |
480 update_timer_.Reset(); | 473 update_timer_.Reset(); |
481 } | 474 } |
482 | 475 |
| 476 int ServiceWorkerVersion::StartRequest( |
| 477 ServiceWorkerMetrics::EventType event_type, |
| 478 const StatusCallback& error_callback) { |
| 479 OnBeginEvent(); |
| 480 DCHECK_EQ(RUNNING, running_status()) |
| 481 << "Can only start a request with a running worker."; |
| 482 return AddRequest(error_callback, &custom_requests_, REQUEST_CUSTOM, |
| 483 event_type); |
| 484 } |
| 485 |
| 486 bool ServiceWorkerVersion::FinishRequest(int request_id) { |
| 487 PendingRequest<StatusCallback>* request = custom_requests_.Lookup(request_id); |
| 488 if (!request) |
| 489 return false; |
| 490 RemoveCallbackAndStopIfRedundant(&custom_requests_, request_id); |
| 491 return true; |
| 492 } |
| 493 |
| 494 void ServiceWorkerVersion::RunAfterStartWorker( |
| 495 const StatusCallback& error_callback, |
| 496 const base::Closure& task) { |
| 497 StartWorker(base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), |
| 498 error_callback, task)); |
| 499 } |
| 500 |
483 void ServiceWorkerVersion::DispatchMessageEvent( | 501 void ServiceWorkerVersion::DispatchMessageEvent( |
484 const base::string16& message, | 502 const base::string16& message, |
485 const std::vector<TransferredMessagePort>& sent_message_ports, | 503 const std::vector<TransferredMessagePort>& sent_message_ports, |
486 const StatusCallback& callback) { | 504 const StatusCallback& callback) { |
487 for (const TransferredMessagePort& port : sent_message_ports) { | 505 for (const TransferredMessagePort& port : sent_message_ports) { |
488 MessagePortService::GetInstance()->HoldMessages(port.id); | 506 MessagePortService::GetInstance()->HoldMessages(port.id); |
489 } | 507 } |
490 | 508 |
491 DispatchMessageEventInternal(message, sent_message_ports, callback); | 509 DispatchMessageEventInternal(message, sent_message_ports, callback); |
492 } | 510 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 base::Bind(&self::DispatchFetchEvent, | 592 base::Bind(&self::DispatchFetchEvent, |
575 weak_factory_.GetWeakPtr(), | 593 weak_factory_.GetWeakPtr(), |
576 request, | 594 request, |
577 prepare_callback, | 595 prepare_callback, |
578 fetch_callback))); | 596 fetch_callback))); |
579 return; | 597 return; |
580 } | 598 } |
581 | 599 |
582 prepare_callback.Run(); | 600 prepare_callback.Run(); |
583 | 601 |
584 int request_id = AddRequest(fetch_callback, &fetch_requests_, REQUEST_FETCH); | 602 int request_id = AddRequest(fetch_callback, &fetch_requests_, REQUEST_FETCH, |
| 603 ServiceWorkerMetrics::EventType::FETCH); |
585 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 604 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
586 ServiceWorkerMsg_FetchEvent(request_id, request)); | 605 ServiceWorkerMsg_FetchEvent(request_id, request)); |
587 if (status != SERVICE_WORKER_OK) { | 606 if (status != SERVICE_WORKER_OK) { |
588 fetch_requests_.Remove(request_id); | 607 fetch_requests_.Remove(request_id); |
589 RunSoon(base::Bind(&RunErrorFetchCallback, | 608 RunSoon(base::Bind(&RunErrorFetchCallback, |
590 fetch_callback, | 609 fetch_callback, |
591 SERVICE_WORKER_ERROR_FAILED)); | 610 SERVICE_WORKER_ERROR_FAILED)); |
592 } | 611 } |
593 } | 612 } |
594 | 613 |
595 void ServiceWorkerVersion::DispatchSyncEvent( | 614 void ServiceWorkerVersion::DispatchSyncEvent( |
596 BackgroundSyncRegistrationHandle::HandleId handle_id, | 615 BackgroundSyncRegistrationHandle::HandleId handle_id, |
597 BackgroundSyncEventLastChance last_chance, | 616 BackgroundSyncEventLastChance last_chance, |
598 base::TimeDelta max_duration, | 617 base::TimeDelta max_duration, |
599 const StatusCallback& callback) { | 618 const StatusCallback& callback) { |
600 OnBeginEvent(); | 619 OnBeginEvent(); |
601 DCHECK_EQ(ACTIVATED, status()) << status(); | 620 DCHECK_EQ(ACTIVATED, status()) << status(); |
602 if (running_status() != RUNNING) { | 621 if (running_status() != RUNNING) { |
603 // Schedule calling this method after starting the worker. | 622 // Schedule calling this method after starting the worker. |
604 StartWorker(base::Bind( | 623 StartWorker(base::Bind( |
605 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, | 624 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, |
606 base::Bind(&self::DispatchSyncEvent, weak_factory_.GetWeakPtr(), | 625 base::Bind(&self::DispatchSyncEvent, weak_factory_.GetWeakPtr(), |
607 handle_id, last_chance, max_duration, callback))); | 626 handle_id, last_chance, max_duration, callback))); |
608 return; | 627 return; |
609 } | 628 } |
610 | 629 |
611 int request_id = | 630 int request_id = |
612 AddRequestWithExpiration(callback, &sync_requests_, REQUEST_SYNC, | 631 AddRequestWithExpiration(callback, &sync_requests_, REQUEST_SYNC, |
| 632 ServiceWorkerMetrics::EventType::SYNC, |
613 base::TimeTicks::Now() + max_duration); | 633 base::TimeTicks::Now() + max_duration); |
614 if (!background_sync_dispatcher_) { | 634 if (!background_sync_dispatcher_) { |
615 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( | 635 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( |
616 mojo::GetProxy(&background_sync_dispatcher_)); | 636 mojo::GetProxy(&background_sync_dispatcher_)); |
617 background_sync_dispatcher_.set_connection_error_handler(base::Bind( | 637 background_sync_dispatcher_.set_connection_error_handler(base::Bind( |
618 &ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError, | 638 &ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError, |
619 weak_factory_.GetWeakPtr())); | 639 weak_factory_.GetWeakPtr())); |
620 } | 640 } |
621 | 641 |
622 background_sync_dispatcher_->Sync( | 642 background_sync_dispatcher_->Sync( |
(...skipping 13 matching lines...) Expand all Loading... |
636 // Schedule calling this method after starting the worker. | 656 // Schedule calling this method after starting the worker. |
637 StartWorker(base::Bind( | 657 StartWorker(base::Bind( |
638 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, | 658 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, |
639 base::Bind(&self::DispatchNotificationClickEvent, | 659 base::Bind(&self::DispatchNotificationClickEvent, |
640 weak_factory_.GetWeakPtr(), callback, | 660 weak_factory_.GetWeakPtr(), callback, |
641 persistent_notification_id, notification_data, | 661 persistent_notification_id, notification_data, |
642 action_index))); | 662 action_index))); |
643 return; | 663 return; |
644 } | 664 } |
645 | 665 |
646 int request_id = AddRequest(callback, ¬ification_click_requests_, | 666 int request_id = AddRequest( |
647 REQUEST_NOTIFICATION_CLICK); | 667 callback, ¬ification_click_requests_, REQUEST_NOTIFICATION_CLICK, |
| 668 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK); |
648 ServiceWorkerStatusCode status = | 669 ServiceWorkerStatusCode status = |
649 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( | 670 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( |
650 request_id, persistent_notification_id, notification_data, | 671 request_id, persistent_notification_id, notification_data, |
651 action_index)); | 672 action_index)); |
652 if (status != SERVICE_WORKER_OK) { | 673 if (status != SERVICE_WORKER_OK) { |
653 notification_click_requests_.Remove(request_id); | 674 notification_click_requests_.Remove(request_id); |
654 RunSoon(base::Bind(callback, status)); | 675 RunSoon(base::Bind(callback, status)); |
655 } | 676 } |
656 } | 677 } |
657 | 678 |
658 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, | 679 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, |
659 const std::string& data) { | 680 const std::string& data) { |
660 OnBeginEvent(); | 681 OnBeginEvent(); |
661 DCHECK_EQ(ACTIVATED, status()) << status(); | 682 DCHECK_EQ(ACTIVATED, status()) << status(); |
662 if (running_status() != RUNNING) { | 683 if (running_status() != RUNNING) { |
663 // Schedule calling this method after starting the worker. | 684 // Schedule calling this method after starting the worker. |
664 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 685 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
665 weak_factory_.GetWeakPtr(), callback, | 686 weak_factory_.GetWeakPtr(), callback, |
666 base::Bind(&self::DispatchPushEvent, | 687 base::Bind(&self::DispatchPushEvent, |
667 weak_factory_.GetWeakPtr(), | 688 weak_factory_.GetWeakPtr(), |
668 callback, data))); | 689 callback, data))); |
669 return; | 690 return; |
670 } | 691 } |
671 | 692 |
672 int request_id = AddRequest(callback, &push_requests_, REQUEST_PUSH); | 693 int request_id = AddRequest(callback, &push_requests_, REQUEST_PUSH, |
| 694 ServiceWorkerMetrics::EventType::PUSH); |
673 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 695 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
674 ServiceWorkerMsg_PushEvent(request_id, data)); | 696 ServiceWorkerMsg_PushEvent(request_id, data)); |
675 if (status != SERVICE_WORKER_OK) { | 697 if (status != SERVICE_WORKER_OK) { |
676 push_requests_.Remove(request_id); | 698 push_requests_.Remove(request_id); |
677 RunSoon(base::Bind(callback, status)); | 699 RunSoon(base::Bind(callback, status)); |
678 } | 700 } |
679 } | 701 } |
680 | 702 |
681 void ServiceWorkerVersion::DispatchGeofencingEvent( | 703 void ServiceWorkerVersion::DispatchGeofencingEvent( |
682 const StatusCallback& callback, | 704 const StatusCallback& callback, |
(...skipping 17 matching lines...) Expand all Loading... |
700 base::Bind(&self::DispatchGeofencingEvent, | 722 base::Bind(&self::DispatchGeofencingEvent, |
701 weak_factory_.GetWeakPtr(), | 723 weak_factory_.GetWeakPtr(), |
702 callback, | 724 callback, |
703 event_type, | 725 event_type, |
704 region_id, | 726 region_id, |
705 region))); | 727 region))); |
706 return; | 728 return; |
707 } | 729 } |
708 | 730 |
709 int request_id = | 731 int request_id = |
710 AddRequest(callback, &geofencing_requests_, REQUEST_GEOFENCING); | 732 AddRequest(callback, &geofencing_requests_, REQUEST_GEOFENCING, |
| 733 ServiceWorkerMetrics::EventType::GEOFENCING); |
711 ServiceWorkerStatusCode status = | 734 ServiceWorkerStatusCode status = |
712 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent( | 735 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent( |
713 request_id, event_type, region_id, region)); | 736 request_id, event_type, region_id, region)); |
714 if (status != SERVICE_WORKER_OK) { | 737 if (status != SERVICE_WORKER_OK) { |
715 geofencing_requests_.Remove(request_id); | 738 geofencing_requests_.Remove(request_id); |
716 RunSoon(base::Bind(callback, status)); | 739 RunSoon(base::Bind(callback, status)); |
717 } | 740 } |
718 } | 741 } |
719 | 742 |
720 void ServiceWorkerVersion::DispatchServicePortConnectEvent( | |
721 const ServicePortConnectCallback& callback, | |
722 const GURL& target_url, | |
723 const GURL& origin, | |
724 int port_id) { | |
725 OnBeginEvent(); | |
726 DCHECK_EQ(ACTIVATED, status()) << status(); | |
727 | |
728 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
729 switches::kEnableExperimentalWebPlatformFeatures)) { | |
730 callback.Run(SERVICE_WORKER_ERROR_ABORT, false, base::string16(), | |
731 base::string16()); | |
732 return; | |
733 } | |
734 | |
735 if (running_status() != RUNNING) { | |
736 // Schedule calling this method after starting the worker. | |
737 StartWorker( | |
738 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), | |
739 base::Bind(&RunErrorServicePortConnectCallback, callback), | |
740 base::Bind(&self::DispatchServicePortConnectEvent, | |
741 weak_factory_.GetWeakPtr(), callback, target_url, | |
742 origin, port_id))); | |
743 return; | |
744 } | |
745 | |
746 int request_id = AddRequest(callback, &service_port_connect_requests_, | |
747 REQUEST_SERVICE_PORT_CONNECT); | |
748 if (!service_port_dispatcher_) { | |
749 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( | |
750 mojo::GetProxy(&service_port_dispatcher_)); | |
751 service_port_dispatcher_.set_connection_error_handler(base::Bind( | |
752 &ServiceWorkerVersion::OnServicePortDispatcherConnectionError, | |
753 weak_factory_.GetWeakPtr())); | |
754 } | |
755 service_port_dispatcher_->Connect( | |
756 mojo::String::From(target_url), mojo::String::From(origin), port_id, | |
757 base::Bind(&ServiceWorkerVersion::OnServicePortConnectEventFinished, | |
758 weak_factory_.GetWeakPtr(), request_id)); | |
759 } | |
760 | |
761 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( | 743 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( |
762 const NavigatorConnectClient& client, | 744 const NavigatorConnectClient& client, |
763 const base::string16& message, | 745 const base::string16& message, |
764 const std::vector<TransferredMessagePort>& sent_message_ports, | 746 const std::vector<TransferredMessagePort>& sent_message_ports, |
765 const StatusCallback& callback) { | 747 const StatusCallback& callback) { |
766 OnBeginEvent(); | 748 OnBeginEvent(); |
767 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to | 749 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to |
768 // have already put all the sent message ports on hold. So no need to do that | 750 // have already put all the sent message ports on hold. So no need to do that |
769 // here again. | 751 // here again. |
770 | 752 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 } | 885 } |
904 | 886 |
905 const net::HttpResponseInfo* | 887 const net::HttpResponseInfo* |
906 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { | 888 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { |
907 return main_script_http_info_.get(); | 889 return main_script_http_info_.get(); |
908 } | 890 } |
909 | 891 |
910 ServiceWorkerVersion::RequestInfo::RequestInfo( | 892 ServiceWorkerVersion::RequestInfo::RequestInfo( |
911 int id, | 893 int id, |
912 RequestType type, | 894 RequestType type, |
| 895 ServiceWorkerMetrics::EventType event_type, |
913 const base::TimeTicks& expiration) | 896 const base::TimeTicks& expiration) |
914 : id(id), type(type), expiration(expiration) {} | 897 : id(id), type(type), event_type(event_type), expiration(expiration) {} |
915 | 898 |
916 ServiceWorkerVersion::RequestInfo::~RequestInfo() { | 899 ServiceWorkerVersion::RequestInfo::~RequestInfo() { |
917 } | 900 } |
918 | 901 |
919 bool ServiceWorkerVersion::RequestInfo::operator>( | 902 bool ServiceWorkerVersion::RequestInfo::operator>( |
920 const RequestInfo& other) const { | 903 const RequestInfo& other) const { |
921 return expiration > other.expiration; | 904 return expiration > other.expiration; |
922 } | 905 } |
923 | 906 |
924 template <typename CallbackType> | 907 template <typename CallbackType> |
925 ServiceWorkerVersion::PendingRequest<CallbackType>::PendingRequest( | 908 ServiceWorkerVersion::PendingRequest<CallbackType>::PendingRequest( |
926 const CallbackType& callback, | 909 const CallbackType& callback, |
927 const base::TimeTicks& time) | 910 const base::TimeTicks& time) |
928 : callback(callback), start_time(time) { | 911 : callback(callback), start_time(time) { |
929 } | 912 } |
930 | 913 |
931 template <typename CallbackType> | 914 template <typename CallbackType> |
932 ServiceWorkerVersion::PendingRequest<CallbackType>::~PendingRequest() { | 915 ServiceWorkerVersion::PendingRequest<CallbackType>::~PendingRequest() { |
933 } | 916 } |
934 | 917 |
| 918 ServiceWorkerVersion::BaseMojoServiceWrapper::BaseMojoServiceWrapper( |
| 919 ServiceWorkerVersion* worker, |
| 920 const char* service_name) |
| 921 : worker_(worker), service_name_(service_name) {} |
| 922 |
| 923 ServiceWorkerVersion::BaseMojoServiceWrapper::~BaseMojoServiceWrapper() { |
| 924 IDMap<PendingRequest<StatusCallback>, IDMapOwnPointer>::iterator iter( |
| 925 &worker_->custom_requests_); |
| 926 while (!iter.IsAtEnd()) { |
| 927 PendingRequest<StatusCallback>* request = iter.GetCurrentValue(); |
| 928 if (request->mojo_service == service_name_) { |
| 929 request->callback.Run(SERVICE_WORKER_ERROR_FAILED); |
| 930 worker_->custom_requests_.Remove(iter.GetCurrentKey()); |
| 931 } |
| 932 iter.Advance(); |
| 933 } |
| 934 } |
| 935 |
935 void ServiceWorkerVersion::OnThreadStarted() { | 936 void ServiceWorkerVersion::OnThreadStarted() { |
936 if (running_status() == STOPPING) | 937 if (running_status() == STOPPING) |
937 return; | 938 return; |
938 DCHECK_EQ(STARTING, running_status()); | 939 DCHECK_EQ(STARTING, running_status()); |
939 // Activate ping/pong now that JavaScript execution will start. | 940 // Activate ping/pong now that JavaScript execution will start. |
940 ping_controller_->Activate(); | 941 ping_controller_->Activate(); |
941 } | 942 } |
942 | 943 |
943 void ServiceWorkerVersion::OnStarting() { | 944 void ServiceWorkerVersion::OnStarting() { |
944 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 945 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 RunCallbacks(this, &start_callbacks_, | 1077 RunCallbacks(this, &start_callbacks_, |
1077 DeduceStartWorkerFailureReason(status)); | 1078 DeduceStartWorkerFailureReason(status)); |
1078 } | 1079 } |
1079 } | 1080 } |
1080 | 1081 |
1081 void ServiceWorkerVersion::DispatchInstallEventAfterStartWorker( | 1082 void ServiceWorkerVersion::DispatchInstallEventAfterStartWorker( |
1082 const StatusCallback& callback) { | 1083 const StatusCallback& callback) { |
1083 DCHECK_EQ(RUNNING, running_status()) | 1084 DCHECK_EQ(RUNNING, running_status()) |
1084 << "Worker stopped too soon after it was started."; | 1085 << "Worker stopped too soon after it was started."; |
1085 | 1086 |
1086 int request_id = AddRequest(callback, &install_requests_, REQUEST_INSTALL); | 1087 int request_id = AddRequest(callback, &install_requests_, REQUEST_INSTALL, |
| 1088 ServiceWorkerMetrics::EventType::INSTALL); |
1087 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 1089 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
1088 ServiceWorkerMsg_InstallEvent(request_id)); | 1090 ServiceWorkerMsg_InstallEvent(request_id)); |
1089 if (status != SERVICE_WORKER_OK) { | 1091 if (status != SERVICE_WORKER_OK) { |
1090 install_requests_.Remove(request_id); | 1092 install_requests_.Remove(request_id); |
1091 RunSoon(base::Bind(callback, status)); | 1093 RunSoon(base::Bind(callback, status)); |
1092 } | 1094 } |
1093 } | 1095 } |
1094 | 1096 |
1095 void ServiceWorkerVersion::DispatchActivateEventAfterStartWorker( | 1097 void ServiceWorkerVersion::DispatchActivateEventAfterStartWorker( |
1096 const StatusCallback& callback) { | 1098 const StatusCallback& callback) { |
1097 DCHECK_EQ(RUNNING, running_status()) | 1099 DCHECK_EQ(RUNNING, running_status()) |
1098 << "Worker stopped too soon after it was started."; | 1100 << "Worker stopped too soon after it was started."; |
1099 | 1101 |
1100 int request_id = AddRequest(callback, &activate_requests_, REQUEST_ACTIVATE); | 1102 int request_id = AddRequest(callback, &activate_requests_, REQUEST_ACTIVATE, |
| 1103 ServiceWorkerMetrics::EventType::ACTIVATE); |
1101 ServiceWorkerStatusCode status = | 1104 ServiceWorkerStatusCode status = |
1102 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); | 1105 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); |
1103 if (status != SERVICE_WORKER_OK) { | 1106 if (status != SERVICE_WORKER_OK) { |
1104 activate_requests_.Remove(request_id); | 1107 activate_requests_.Remove(request_id); |
1105 RunSoon(base::Bind(callback, status)); | 1108 RunSoon(base::Bind(callback, status)); |
1106 } | 1109 } |
1107 } | 1110 } |
1108 | 1111 |
1109 void ServiceWorkerVersion::OnGetClients( | 1112 void ServiceWorkerVersion::OnGetClients( |
1110 int request_id, | 1113 int request_id, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 "ServiceWorkerVersion::OnFetchEventFinished", | 1198 "ServiceWorkerVersion::OnFetchEventFinished", |
1196 "Request id", request_id); | 1199 "Request id", request_id); |
1197 PendingRequest<FetchCallback>* request = fetch_requests_.Lookup(request_id); | 1200 PendingRequest<FetchCallback>* request = fetch_requests_.Lookup(request_id); |
1198 if (!request) { | 1201 if (!request) { |
1199 NOTREACHED() << "Got unexpected message: " << request_id; | 1202 NOTREACHED() << "Got unexpected message: " << request_id; |
1200 return; | 1203 return; |
1201 } | 1204 } |
1202 | 1205 |
1203 // TODO(kinuko): Record other event statuses too. | 1206 // TODO(kinuko): Record other event statuses too. |
1204 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); | 1207 const bool handled = (result == SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE); |
1205 metrics_->RecordEventHandledStatus(ServiceWorkerMetrics::EVENT_TYPE_FETCH, | 1208 metrics_->RecordEventHandledStatus(ServiceWorkerMetrics::EventType::FETCH, |
1206 handled); | 1209 handled); |
1207 | 1210 |
1208 ServiceWorkerMetrics::RecordFetchEventTime( | 1211 ServiceWorkerMetrics::RecordFetchEventTime( |
1209 result, base::TimeTicks::Now() - request->start_time); | 1212 result, base::TimeTicks::Now() - request->start_time); |
1210 | 1213 |
1211 scoped_refptr<ServiceWorkerVersion> protect(this); | 1214 scoped_refptr<ServiceWorkerVersion> protect(this); |
1212 request->callback.Run(SERVICE_WORKER_OK, result, response); | 1215 request->callback.Run(SERVICE_WORKER_OK, result, response); |
1213 RemoveCallbackAndStopIfRedundant(&fetch_requests_, request_id); | 1216 RemoveCallbackAndStopIfRedundant(&fetch_requests_, request_id); |
1214 } | 1217 } |
1215 | 1218 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 if (!request) { | 1289 if (!request) { |
1287 NOTREACHED() << "Got unexpected message: " << request_id; | 1290 NOTREACHED() << "Got unexpected message: " << request_id; |
1288 return; | 1291 return; |
1289 } | 1292 } |
1290 | 1293 |
1291 scoped_refptr<ServiceWorkerVersion> protect(this); | 1294 scoped_refptr<ServiceWorkerVersion> protect(this); |
1292 request->callback.Run(SERVICE_WORKER_OK); | 1295 request->callback.Run(SERVICE_WORKER_OK); |
1293 RemoveCallbackAndStopIfRedundant(&geofencing_requests_, request_id); | 1296 RemoveCallbackAndStopIfRedundant(&geofencing_requests_, request_id); |
1294 } | 1297 } |
1295 | 1298 |
1296 void ServiceWorkerVersion::OnServicePortConnectEventFinished( | |
1297 int request_id, | |
1298 ServicePortConnectResult result, | |
1299 const mojo::String& name, | |
1300 const mojo::String& data) { | |
1301 TRACE_EVENT1("ServiceWorker", | |
1302 "ServiceWorkerVersion::OnServicePortConnectEventFinished", | |
1303 "Request id", request_id); | |
1304 PendingRequest<ServicePortConnectCallback>* request = | |
1305 service_port_connect_requests_.Lookup(request_id); | |
1306 if (!request) { | |
1307 NOTREACHED() << "Got unexpected message: " << request_id; | |
1308 return; | |
1309 } | |
1310 | |
1311 scoped_refptr<ServiceWorkerVersion> protect(this); | |
1312 request->callback.Run(SERVICE_WORKER_OK, | |
1313 result == SERVICE_PORT_CONNECT_RESULT_ACCEPT, | |
1314 name.To<base::string16>(), data.To<base::string16>()); | |
1315 RemoveCallbackAndStopIfRedundant(&service_port_connect_requests_, request_id); | |
1316 } | |
1317 | |
1318 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { | 1299 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { |
1319 // Just abort if we are shutting down. | 1300 // Just abort if we are shutting down. |
1320 if (!context_) | 1301 if (!context_) |
1321 return; | 1302 return; |
1322 | 1303 |
1323 if (!url.is_valid()) { | 1304 if (!url.is_valid()) { |
1324 DVLOG(1) << "Received unexpected invalid URL from renderer process."; | 1305 DVLOG(1) << "Received unexpected invalid URL from renderer process."; |
1325 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1306 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
1326 base::Bind(&KillEmbeddedWorkerProcess, | 1307 base::Bind(&KillEmbeddedWorkerProcess, |
1327 embedded_worker_->process_id(), | 1308 embedded_worker_->process_id(), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 context_->GetProviderHostByClientID(client_uuid); | 1410 context_->GetProviderHostByClientID(client_uuid); |
1430 if (!provider_host) { | 1411 if (!provider_host) { |
1431 // The client may already have been closed, just ignore. | 1412 // The client may already have been closed, just ignore. |
1432 return; | 1413 return; |
1433 } | 1414 } |
1434 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) { | 1415 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) { |
1435 // The client does not belong to the same origin as this ServiceWorker, | 1416 // The client does not belong to the same origin as this ServiceWorker, |
1436 // possibly due to timing issue or bad message. | 1417 // possibly due to timing issue or bad message. |
1437 return; | 1418 return; |
1438 } | 1419 } |
1439 provider_host->PostMessage(this, message, sent_message_ports); | 1420 provider_host->PostMessageToClient(this, message, sent_message_ports); |
1440 } | 1421 } |
1441 | 1422 |
1442 void ServiceWorkerVersion::OnFocusClient(int request_id, | 1423 void ServiceWorkerVersion::OnFocusClient(int request_id, |
1443 const std::string& client_uuid) { | 1424 const std::string& client_uuid) { |
1444 if (!context_) | 1425 if (!context_) |
1445 return; | 1426 return; |
1446 TRACE_EVENT2("ServiceWorker", | 1427 TRACE_EVENT2("ServiceWorker", |
1447 "ServiceWorkerVersion::OnFocusClient", | 1428 "ServiceWorkerVersion::OnFocusClient", |
1448 "Request id", request_id, | 1429 "Request id", request_id, |
1449 "Client id", client_uuid); | 1430 "Client id", client_uuid); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 } | 1773 } |
1793 | 1774 |
1794 // Requests have not finished before their expiration. | 1775 // Requests have not finished before their expiration. |
1795 bool stop_for_timeout = false; | 1776 bool stop_for_timeout = false; |
1796 while (!requests_.empty()) { | 1777 while (!requests_.empty()) { |
1797 RequestInfo info = requests_.top(); | 1778 RequestInfo info = requests_.top(); |
1798 if (!RequestExpired(info.expiration)) | 1779 if (!RequestExpired(info.expiration)) |
1799 break; | 1780 break; |
1800 if (MaybeTimeOutRequest(info)) { | 1781 if (MaybeTimeOutRequest(info)) { |
1801 stop_for_timeout = stop_for_timeout || ShouldStopIfRequestTimesOut(info); | 1782 stop_for_timeout = stop_for_timeout || ShouldStopIfRequestTimesOut(info); |
1802 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.RequestTimeouts.Count", | 1783 ServiceWorkerMetrics::RecordEventTimeout(info.event_type); |
1803 info.type, NUM_REQUEST_TYPES); | |
1804 } | 1784 } |
1805 requests_.pop(); | 1785 requests_.pop(); |
1806 } | 1786 } |
1807 if (stop_for_timeout && running_status() != STOPPING) | 1787 if (stop_for_timeout && running_status() != STOPPING) |
1808 embedded_worker_->Stop(); | 1788 embedded_worker_->Stop(); |
1809 | 1789 |
1810 // For the timeouts below, there are no callbacks to timeout so there is | 1790 // For the timeouts below, there are no callbacks to timeout so there is |
1811 // nothing more to do if the worker is already stopping. | 1791 // nothing more to do if the worker is already stopping. |
1812 if (running_status() == STOPPING) | 1792 if (running_status() == STOPPING) |
1813 return; | 1793 return; |
(...skipping 30 matching lines...) Expand all Loading... |
1844 return; | 1824 return; |
1845 } | 1825 } |
1846 | 1826 |
1847 embedded_worker_->StopIfIdle(); | 1827 embedded_worker_->StopIfIdle(); |
1848 } | 1828 } |
1849 | 1829 |
1850 bool ServiceWorkerVersion::HasInflightRequests() const { | 1830 bool ServiceWorkerVersion::HasInflightRequests() const { |
1851 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || | 1831 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || |
1852 !fetch_requests_.IsEmpty() || !sync_requests_.IsEmpty() || | 1832 !fetch_requests_.IsEmpty() || !sync_requests_.IsEmpty() || |
1853 !notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() || | 1833 !notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() || |
1854 !geofencing_requests_.IsEmpty() || | 1834 !geofencing_requests_.IsEmpty() || !custom_requests_.IsEmpty() || |
1855 !service_port_connect_requests_.IsEmpty() || | |
1856 !streaming_url_request_jobs_.empty(); | 1835 !streaming_url_request_jobs_.empty(); |
1857 } | 1836 } |
1858 | 1837 |
1859 void ServiceWorkerVersion::RecordStartWorkerResult( | 1838 void ServiceWorkerVersion::RecordStartWorkerResult( |
1860 ServiceWorkerStatusCode status) { | 1839 ServiceWorkerStatusCode status) { |
1861 base::TimeTicks start_time = start_time_; | 1840 base::TimeTicks start_time = start_time_; |
1862 ClearTick(&start_time_); | 1841 ClearTick(&start_time_); |
1863 | 1842 |
1864 ServiceWorkerMetrics::RecordStartWorkerStatus(status, | 1843 ServiceWorkerMetrics::RecordStartWorkerStatus(status, |
1865 IsInstalled(prestart_status_)); | 1844 IsInstalled(prestart_status_)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 // The stop should be already scheduled, but try to stop immediately, in | 1882 // The stop should be already scheduled, but try to stop immediately, in |
1904 // order to release worker resources soon. | 1883 // order to release worker resources soon. |
1905 StopWorkerIfIdle(); | 1884 StopWorkerIfIdle(); |
1906 } | 1885 } |
1907 } | 1886 } |
1908 | 1887 |
1909 template <typename CallbackType> | 1888 template <typename CallbackType> |
1910 int ServiceWorkerVersion::AddRequest( | 1889 int ServiceWorkerVersion::AddRequest( |
1911 const CallbackType& callback, | 1890 const CallbackType& callback, |
1912 IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map, | 1891 IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map, |
1913 RequestType request_type) { | 1892 RequestType request_type, |
| 1893 ServiceWorkerMetrics::EventType event_type) { |
1914 base::TimeTicks expiration_time = | 1894 base::TimeTicks expiration_time = |
1915 base::TimeTicks::Now() + | 1895 base::TimeTicks::Now() + |
1916 base::TimeDelta::FromMinutes(kRequestTimeoutMinutes); | 1896 base::TimeDelta::FromMinutes(kRequestTimeoutMinutes); |
1917 return AddRequestWithExpiration(callback, callback_map, request_type, | 1897 return AddRequestWithExpiration(callback, callback_map, request_type, |
1918 expiration_time); | 1898 event_type, expiration_time); |
1919 } | 1899 } |
1920 | 1900 |
1921 template <typename CallbackType> | 1901 template <typename CallbackType> |
1922 int ServiceWorkerVersion::AddRequestWithExpiration( | 1902 int ServiceWorkerVersion::AddRequestWithExpiration( |
1923 const CallbackType& callback, | 1903 const CallbackType& callback, |
1924 IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map, | 1904 IDMap<PendingRequest<CallbackType>, IDMapOwnPointer>* callback_map, |
1925 RequestType request_type, | 1905 RequestType request_type, |
| 1906 ServiceWorkerMetrics::EventType event_type, |
1926 base::TimeTicks expiration) { | 1907 base::TimeTicks expiration) { |
1927 int request_id = callback_map->Add( | 1908 int request_id = callback_map->Add( |
1928 new PendingRequest<CallbackType>(callback, base::TimeTicks::Now())); | 1909 new PendingRequest<CallbackType>(callback, base::TimeTicks::Now())); |
1929 requests_.push(RequestInfo(request_id, request_type, expiration)); | 1910 requests_.push(RequestInfo(request_id, request_type, event_type, expiration)); |
1930 return request_id; | 1911 return request_id; |
1931 } | 1912 } |
1932 | 1913 |
1933 bool ServiceWorkerVersion::MaybeTimeOutRequest(const RequestInfo& info) { | 1914 bool ServiceWorkerVersion::MaybeTimeOutRequest(const RequestInfo& info) { |
1934 switch (info.type) { | 1915 switch (info.type) { |
1935 case REQUEST_ACTIVATE: | 1916 case REQUEST_ACTIVATE: |
1936 return RunIDMapCallback(&activate_requests_, info.id, | 1917 return RunIDMapCallback(&activate_requests_, info.id, |
1937 SERVICE_WORKER_ERROR_TIMEOUT); | 1918 SERVICE_WORKER_ERROR_TIMEOUT); |
1938 case REQUEST_INSTALL: | 1919 case REQUEST_INSTALL: |
1939 return RunIDMapCallback(&install_requests_, info.id, | 1920 return RunIDMapCallback(&install_requests_, info.id, |
1940 SERVICE_WORKER_ERROR_TIMEOUT); | 1921 SERVICE_WORKER_ERROR_TIMEOUT); |
1941 case REQUEST_FETCH: | 1922 case REQUEST_FETCH: |
1942 return RunIDMapCallback( | 1923 return RunIDMapCallback( |
1943 &fetch_requests_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, | 1924 &fetch_requests_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, |
1944 /* The other args are ignored for non-OK status. */ | 1925 /* The other args are ignored for non-OK status. */ |
1945 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); | 1926 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); |
1946 case REQUEST_SYNC: | 1927 case REQUEST_SYNC: |
1947 return RunIDMapCallback(&sync_requests_, info.id, | 1928 return RunIDMapCallback(&sync_requests_, info.id, |
1948 SERVICE_WORKER_ERROR_TIMEOUT); | 1929 SERVICE_WORKER_ERROR_TIMEOUT); |
1949 case REQUEST_NOTIFICATION_CLICK: | 1930 case REQUEST_NOTIFICATION_CLICK: |
1950 return RunIDMapCallback(¬ification_click_requests_, info.id, | 1931 return RunIDMapCallback(¬ification_click_requests_, info.id, |
1951 SERVICE_WORKER_ERROR_TIMEOUT); | 1932 SERVICE_WORKER_ERROR_TIMEOUT); |
1952 case REQUEST_PUSH: | 1933 case REQUEST_PUSH: |
1953 return RunIDMapCallback(&push_requests_, info.id, | 1934 return RunIDMapCallback(&push_requests_, info.id, |
1954 SERVICE_WORKER_ERROR_TIMEOUT); | 1935 SERVICE_WORKER_ERROR_TIMEOUT); |
1955 case REQUEST_GEOFENCING: | 1936 case REQUEST_GEOFENCING: |
1956 return RunIDMapCallback(&geofencing_requests_, info.id, | 1937 return RunIDMapCallback(&geofencing_requests_, info.id, |
1957 SERVICE_WORKER_ERROR_TIMEOUT); | 1938 SERVICE_WORKER_ERROR_TIMEOUT); |
1958 case REQUEST_SERVICE_PORT_CONNECT: | 1939 case REQUEST_CUSTOM: |
1959 return RunIDMapCallback(&service_port_connect_requests_, info.id, | 1940 return RunIDMapCallback(&custom_requests_, info.id, |
1960 SERVICE_WORKER_ERROR_TIMEOUT, | 1941 SERVICE_WORKER_ERROR_TIMEOUT); |
1961 false /* accept_connection */, base::string16(), | |
1962 base::string16()); | |
1963 case NUM_REQUEST_TYPES: | 1942 case NUM_REQUEST_TYPES: |
1964 break; | 1943 break; |
1965 } | 1944 } |
1966 NOTREACHED() << "Got unexpected request type: " << info.type; | 1945 NOTREACHED() << "Got unexpected request type: " << info.type; |
1967 return false; | 1946 return false; |
1968 } | 1947 } |
1969 | 1948 |
1970 bool ServiceWorkerVersion::ShouldStopIfRequestTimesOut( | 1949 bool ServiceWorkerVersion::ShouldStopIfRequestTimesOut( |
1971 const RequestInfo& info) { | 1950 const RequestInfo& info) { |
1972 // Note, returning false for a type means that the On*EventFinished should not | 1951 // Note, returning false for a type means that the On*EventFinished should not |
1973 // call NOTREACHED if it can't find the matching request, it may have simply | 1952 // call NOTREACHED if it can't find the matching request, it may have simply |
1974 // timed out. | 1953 // timed out. |
1975 switch (info.type) { | 1954 switch (info.type) { |
1976 case REQUEST_SYNC: | 1955 case REQUEST_SYNC: |
1977 return false; | 1956 return false; |
1978 case REQUEST_ACTIVATE: | 1957 case REQUEST_ACTIVATE: |
1979 case REQUEST_INSTALL: | 1958 case REQUEST_INSTALL: |
1980 case REQUEST_FETCH: | 1959 case REQUEST_FETCH: |
1981 case REQUEST_NOTIFICATION_CLICK: | 1960 case REQUEST_NOTIFICATION_CLICK: |
1982 case REQUEST_PUSH: | 1961 case REQUEST_PUSH: |
1983 case REQUEST_GEOFENCING: | 1962 case REQUEST_GEOFENCING: |
1984 case REQUEST_SERVICE_PORT_CONNECT: | 1963 return true; |
| 1964 case REQUEST_CUSTOM: |
| 1965 // TODO(mek): Custom requests need some way to specify their timeout |
| 1966 // behavior. |
1985 return true; | 1967 return true; |
1986 case NUM_REQUEST_TYPES: | 1968 case NUM_REQUEST_TYPES: |
1987 NOTREACHED() << "Got unexpected request type: " << info.type; | 1969 NOTREACHED() << "Got unexpected request type: " << info.type; |
1988 } | 1970 } |
1989 NOTREACHED() << "Got unexpected request type: " << info.type; | 1971 NOTREACHED() << "Got unexpected request type: " << info.type; |
1990 return false; | 1972 return false; |
1991 } | 1973 } |
1992 | 1974 |
1993 void ServiceWorkerVersion::SetAllRequestExpirations( | 1975 void ServiceWorkerVersion::SetAllRequestExpirations( |
1994 const base::TimeTicks& expiration) { | 1976 const base::TimeTicks& expiration) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); | 2077 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); |
2096 RunIDMapCallbacks(&install_requests_, | 2078 RunIDMapCallbacks(&install_requests_, |
2097 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); | 2079 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); |
2098 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, | 2080 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, |
2099 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, | 2081 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
2100 ServiceWorkerResponse()); | 2082 ServiceWorkerResponse()); |
2101 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); | 2083 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); |
2102 RunIDMapCallbacks(¬ification_click_requests_, SERVICE_WORKER_ERROR_FAILED); | 2084 RunIDMapCallbacks(¬ification_click_requests_, SERVICE_WORKER_ERROR_FAILED); |
2103 RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED); | 2085 RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED); |
2104 RunIDMapCallbacks(&geofencing_requests_, SERVICE_WORKER_ERROR_FAILED); | 2086 RunIDMapCallbacks(&geofencing_requests_, SERVICE_WORKER_ERROR_FAILED); |
| 2087 RunIDMapCallbacks(&custom_requests_, SERVICE_WORKER_ERROR_FAILED); |
2105 | 2088 |
2106 // Close all mojo services. This will also fire and clear all callbacks | 2089 // Close all mojo services. This will also fire and clear all callbacks |
2107 // for messages that are still outstanding for those services. | 2090 // for messages that are still outstanding for those services. |
2108 OnServicePortDispatcherConnectionError(); | 2091 mojo_services_.clear(); |
2109 | |
2110 OnBackgroundSyncDispatcherConnectionError(); | 2092 OnBackgroundSyncDispatcherConnectionError(); |
2111 | 2093 |
2112 // TODO(falken): Call SWURLRequestJob::ClearStream here? | 2094 // TODO(falken): Call SWURLRequestJob::ClearStream here? |
2113 streaming_url_request_jobs_.clear(); | 2095 streaming_url_request_jobs_.clear(); |
2114 | 2096 |
2115 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 2097 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
2116 | 2098 |
2117 if (should_restart) | 2099 if (should_restart) |
2118 StartWorkerInternal(); | 2100 StartWorkerInternal(); |
2119 } | 2101 } |
2120 | 2102 |
2121 void ServiceWorkerVersion::OnServicePortDispatcherConnectionError() { | |
2122 RunIDMapCallbacks(&service_port_connect_requests_, | |
2123 SERVICE_WORKER_ERROR_FAILED, false, base::string16(), | |
2124 base::string16()); | |
2125 service_port_dispatcher_.reset(); | |
2126 } | |
2127 | |
2128 void ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError() { | 2103 void ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError() { |
2129 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); | 2104 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); |
2130 background_sync_dispatcher_.reset(); | 2105 background_sync_dispatcher_.reset(); |
2131 } | 2106 } |
2132 | 2107 |
| 2108 void ServiceWorkerVersion::OnMojoConnectionError(const char* service_name) { |
| 2109 // Simply deleting the service will cause error callbacks to be called from |
| 2110 // the destructor of the MojoServiceWrapper instance. |
| 2111 mojo_services_.erase(service_name); |
| 2112 } |
| 2113 |
2133 void ServiceWorkerVersion::OnBeginEvent() { | 2114 void ServiceWorkerVersion::OnBeginEvent() { |
2134 if (should_exclude_from_uma_ || running_status() != RUNNING || | 2115 if (should_exclude_from_uma_ || running_status() != RUNNING || |
2135 idle_time_.is_null()) { | 2116 idle_time_.is_null()) { |
2136 return; | 2117 return; |
2137 } | 2118 } |
2138 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 2119 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
2139 idle_time_); | 2120 idle_time_); |
2140 } | 2121 } |
2141 | 2122 |
2142 } // namespace content | 2123 } // namespace content |
OLD | NEW |