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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 618 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
619 ServiceWorkerMsg_FetchEvent(request_id, request)); | 619 ServiceWorkerMsg_FetchEvent(request_id, request)); |
620 if (status != SERVICE_WORKER_OK) { | 620 if (status != SERVICE_WORKER_OK) { |
621 fetch_requests_.Remove(request_id); | 621 fetch_requests_.Remove(request_id); |
622 RunSoon(base::Bind(&RunErrorFetchCallback, | 622 RunSoon(base::Bind(&RunErrorFetchCallback, |
623 fetch_callback, | 623 fetch_callback, |
624 SERVICE_WORKER_ERROR_FAILED)); | 624 SERVICE_WORKER_ERROR_FAILED)); |
625 } | 625 } |
626 } | 626 } |
627 | 627 |
628 void ServiceWorkerVersion::DispatchNotificationClickEvent( | |
629 const StatusCallback& callback, | |
630 int64_t persistent_notification_id, | |
631 const PlatformNotificationData& notification_data, | |
632 int action_index) { | |
633 OnBeginEvent(); | |
634 DCHECK_EQ(ACTIVATED, status()) << status(); | |
johnme
2016/01/15 16:52:58
Is there any equivalent to this DCHECK in the new
Marijn Kruisselbrink
2016/01/15 23:48:49
Good question. Not currently. I considered adding
johnme
2016/01/18 16:31:05
Both push and notifications have experienced a lot
Marijn Kruisselbrink
2016/01/19 23:50:17
I think most of the subtle bugs have been adressed
| |
635 if (running_status() != RUNNING) { | |
636 // Schedule calling this method after starting the worker. | |
637 StartWorker(base::Bind( | |
638 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, | |
639 base::Bind(&self::DispatchNotificationClickEvent, | |
640 weak_factory_.GetWeakPtr(), callback, | |
641 persistent_notification_id, notification_data, | |
642 action_index))); | |
643 return; | |
644 } | |
645 | |
646 int request_id = AddRequest( | |
647 callback, ¬ification_click_requests_, REQUEST_NOTIFICATION_CLICK, | |
648 ServiceWorkerMetrics::EventType::NOTIFICATION_CLICK); | |
649 ServiceWorkerStatusCode status = | |
650 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( | |
651 request_id, persistent_notification_id, notification_data, | |
652 action_index)); | |
653 if (status != SERVICE_WORKER_OK) { | |
654 notification_click_requests_.Remove(request_id); | |
655 RunSoon(base::Bind(callback, status)); | |
656 } | |
657 } | |
658 | |
659 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, | 628 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, |
660 const std::string& data) { | 629 const std::string& data) { |
661 OnBeginEvent(); | 630 OnBeginEvent(); |
662 DCHECK_EQ(ACTIVATED, status()) << status(); | 631 DCHECK_EQ(ACTIVATED, status()) << status(); |
663 if (running_status() != RUNNING) { | 632 if (running_status() != RUNNING) { |
664 // Schedule calling this method after starting the worker. | 633 // Schedule calling this method after starting the worker. |
665 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 634 StartWorker(base::Bind(&RunTaskAfterStartWorker, |
666 weak_factory_.GetWeakPtr(), callback, | 635 weak_factory_.GetWeakPtr(), callback, |
667 base::Bind(&self::DispatchPushEvent, | 636 base::Bind(&self::DispatchPushEvent, |
668 weak_factory_.GetWeakPtr(), | 637 weak_factory_.GetWeakPtr(), |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 bool handled = true; | 944 bool handled = true; |
976 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) | 945 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) |
977 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, | 946 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
978 OnGetClients) | 947 OnGetClients) |
979 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 948 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
980 OnActivateEventFinished) | 949 OnActivateEventFinished) |
981 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 950 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
982 OnInstallEventFinished) | 951 OnInstallEventFinished) |
983 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 952 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
984 OnFetchEventFinished) | 953 OnFetchEventFinished) |
985 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | |
986 OnNotificationClickEventFinished) | |
987 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, | 954 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, |
988 OnPushEventFinished) | 955 OnPushEventFinished) |
989 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 956 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
990 OnOpenWindow) | 957 OnOpenWindow) |
991 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, | 958 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, |
992 OnSetCachedMetadata) | 959 OnSetCachedMetadata) |
993 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, | 960 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, |
994 OnClearCachedMetadata) | 961 OnClearCachedMetadata) |
995 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, | 962 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, |
996 OnPostMessageToClient) | 963 OnPostMessageToClient) |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1148 handled); | 1115 handled); |
1149 | 1116 |
1150 ServiceWorkerMetrics::RecordFetchEventTime( | 1117 ServiceWorkerMetrics::RecordFetchEventTime( |
1151 result, base::TimeTicks::Now() - request->start_time); | 1118 result, base::TimeTicks::Now() - request->start_time); |
1152 | 1119 |
1153 scoped_refptr<ServiceWorkerVersion> protect(this); | 1120 scoped_refptr<ServiceWorkerVersion> protect(this); |
1154 request->callback.Run(SERVICE_WORKER_OK, result, response); | 1121 request->callback.Run(SERVICE_WORKER_OK, result, response); |
1155 RemoveCallbackAndStopIfRedundant(&fetch_requests_, request_id); | 1122 RemoveCallbackAndStopIfRedundant(&fetch_requests_, request_id); |
1156 } | 1123 } |
1157 | 1124 |
1158 void ServiceWorkerVersion::OnNotificationClickEventFinished( | |
1159 int request_id) { | |
1160 TRACE_EVENT1("ServiceWorker", | |
1161 "ServiceWorkerVersion::OnNotificationClickEventFinished", | |
1162 "Request id", request_id); | |
1163 PendingRequest<StatusCallback>* request = | |
1164 notification_click_requests_.Lookup(request_id); | |
1165 if (!request) { | |
1166 NOTREACHED() << "Got unexpected message: " << request_id; | |
1167 return; | |
1168 } | |
1169 | |
1170 ServiceWorkerMetrics::RecordEventDuration( | |
1171 request->event_type, base::TimeTicks::Now() - request->start_time); | |
1172 | |
1173 scoped_refptr<ServiceWorkerVersion> protect(this); | |
1174 request->callback.Run(SERVICE_WORKER_OK); | |
1175 RemoveCallbackAndStopIfRedundant(¬ification_click_requests_, request_id); | |
1176 } | |
1177 | |
1178 void ServiceWorkerVersion::OnPushEventFinished( | 1125 void ServiceWorkerVersion::OnPushEventFinished( |
1179 int request_id, | 1126 int request_id, |
1180 blink::WebServiceWorkerEventResult result) { | 1127 blink::WebServiceWorkerEventResult result) { |
1181 TRACE_EVENT1("ServiceWorker", | 1128 TRACE_EVENT1("ServiceWorker", |
1182 "ServiceWorkerVersion::OnPushEventFinished", | 1129 "ServiceWorkerVersion::OnPushEventFinished", |
1183 "Request id", request_id); | 1130 "Request id", request_id); |
1184 PendingRequest<StatusCallback>* request = push_requests_.Lookup(request_id); | 1131 PendingRequest<StatusCallback>* request = push_requests_.Lookup(request_id); |
1185 if (!request) { | 1132 if (!request) { |
1186 NOTREACHED() << "Got unexpected message: " << request_id; | 1133 NOTREACHED() << "Got unexpected message: " << request_id; |
1187 return; | 1134 return; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1725 if (running_status() == STOPPED || running_status() == STOPPING || | 1672 if (running_status() == STOPPED || running_status() == STOPPING || |
1726 !stop_callbacks_.empty()) { | 1673 !stop_callbacks_.empty()) { |
1727 return; | 1674 return; |
1728 } | 1675 } |
1729 | 1676 |
1730 embedded_worker_->StopIfIdle(); | 1677 embedded_worker_->StopIfIdle(); |
1731 } | 1678 } |
1732 | 1679 |
1733 bool ServiceWorkerVersion::HasInflightRequests() const { | 1680 bool ServiceWorkerVersion::HasInflightRequests() const { |
1734 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || | 1681 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || |
1735 !fetch_requests_.IsEmpty() || | 1682 !fetch_requests_.IsEmpty() || !push_requests_.IsEmpty() || |
1736 !notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() || | |
1737 !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty(); | 1683 !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty(); |
1738 } | 1684 } |
1739 | 1685 |
1740 void ServiceWorkerVersion::RecordStartWorkerResult( | 1686 void ServiceWorkerVersion::RecordStartWorkerResult( |
1741 ServiceWorkerStatusCode status) { | 1687 ServiceWorkerStatusCode status) { |
1742 base::TimeTicks start_time = start_time_; | 1688 base::TimeTicks start_time = start_time_; |
1743 ClearTick(&start_time_); | 1689 ClearTick(&start_time_); |
1744 | 1690 |
1745 ServiceWorkerMetrics::RecordStartWorkerStatus(status, | 1691 ServiceWorkerMetrics::RecordStartWorkerStatus(status, |
1746 IsInstalled(prestart_status_)); | 1692 IsInstalled(prestart_status_)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1821 return RunIDMapCallback(&activate_requests_, info.id, | 1767 return RunIDMapCallback(&activate_requests_, info.id, |
1822 SERVICE_WORKER_ERROR_TIMEOUT); | 1768 SERVICE_WORKER_ERROR_TIMEOUT); |
1823 case REQUEST_INSTALL: | 1769 case REQUEST_INSTALL: |
1824 return RunIDMapCallback(&install_requests_, info.id, | 1770 return RunIDMapCallback(&install_requests_, info.id, |
1825 SERVICE_WORKER_ERROR_TIMEOUT); | 1771 SERVICE_WORKER_ERROR_TIMEOUT); |
1826 case REQUEST_FETCH: | 1772 case REQUEST_FETCH: |
1827 return RunIDMapCallback( | 1773 return RunIDMapCallback( |
1828 &fetch_requests_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, | 1774 &fetch_requests_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, |
1829 /* The other args are ignored for non-OK status. */ | 1775 /* The other args are ignored for non-OK status. */ |
1830 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); | 1776 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); |
1831 case REQUEST_NOTIFICATION_CLICK: | |
1832 return RunIDMapCallback(¬ification_click_requests_, info.id, | |
1833 SERVICE_WORKER_ERROR_TIMEOUT); | |
1834 case REQUEST_PUSH: | 1777 case REQUEST_PUSH: |
1835 return RunIDMapCallback(&push_requests_, info.id, | 1778 return RunIDMapCallback(&push_requests_, info.id, |
1836 SERVICE_WORKER_ERROR_TIMEOUT); | 1779 SERVICE_WORKER_ERROR_TIMEOUT); |
1837 case REQUEST_CUSTOM: | 1780 case REQUEST_CUSTOM: |
1838 return RunIDMapCallback(&custom_requests_, info.id, | 1781 return RunIDMapCallback(&custom_requests_, info.id, |
1839 SERVICE_WORKER_ERROR_TIMEOUT); | 1782 SERVICE_WORKER_ERROR_TIMEOUT); |
1840 case NUM_REQUEST_TYPES: | 1783 case NUM_REQUEST_TYPES: |
1841 break; | 1784 break; |
1842 } | 1785 } |
1843 NOTREACHED() << "Got unexpected request type: " << info.type; | 1786 NOTREACHED() << "Got unexpected request type: " << info.type; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1945 // Let all message callbacks fail (this will also fire and clear all | 1888 // Let all message callbacks fail (this will also fire and clear all |
1946 // callbacks for events). | 1889 // callbacks for events). |
1947 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. | 1890 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. |
1948 RunIDMapCallbacks(&activate_requests_, | 1891 RunIDMapCallbacks(&activate_requests_, |
1949 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); | 1892 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); |
1950 RunIDMapCallbacks(&install_requests_, | 1893 RunIDMapCallbacks(&install_requests_, |
1951 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); | 1894 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); |
1952 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, | 1895 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, |
1953 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, | 1896 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
1954 ServiceWorkerResponse()); | 1897 ServiceWorkerResponse()); |
1955 RunIDMapCallbacks(¬ification_click_requests_, SERVICE_WORKER_ERROR_FAILED); | |
1956 RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED); | 1898 RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED); |
1957 RunIDMapCallbacks(&custom_requests_, SERVICE_WORKER_ERROR_FAILED); | 1899 RunIDMapCallbacks(&custom_requests_, SERVICE_WORKER_ERROR_FAILED); |
1958 | 1900 |
1959 // Close all mojo services. This will also fire and clear all callbacks | 1901 // Close all mojo services. This will also fire and clear all callbacks |
1960 // for messages that are still outstanding for those services. | 1902 // for messages that are still outstanding for those services. |
1961 mojo_services_.clear(); | 1903 mojo_services_.clear(); |
1962 | 1904 |
1963 // TODO(falken): Call SWURLRequestJob::ClearStream here? | 1905 // TODO(falken): Call SWURLRequestJob::ClearStream here? |
1964 streaming_url_request_jobs_.clear(); | 1906 streaming_url_request_jobs_.clear(); |
1965 | 1907 |
(...skipping 12 matching lines...) Expand all Loading... | |
1978 void ServiceWorkerVersion::OnBeginEvent() { | 1920 void ServiceWorkerVersion::OnBeginEvent() { |
1979 if (should_exclude_from_uma_ || running_status() != RUNNING || | 1921 if (should_exclude_from_uma_ || running_status() != RUNNING || |
1980 idle_time_.is_null()) { | 1922 idle_time_.is_null()) { |
1981 return; | 1923 return; |
1982 } | 1924 } |
1983 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1925 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
1984 idle_time_); | 1926 idle_time_); |
1985 } | 1927 } |
1986 | 1928 |
1987 } // namespace content | 1929 } // namespace content |
OLD | NEW |