| 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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 ServiceWorkerStatusCode status = | 649 ServiceWorkerStatusCode status = |
| 650 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( | 650 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( |
| 651 request_id, persistent_notification_id, notification_data, | 651 request_id, persistent_notification_id, notification_data, |
| 652 action_index)); | 652 action_index)); |
| 653 if (status != SERVICE_WORKER_OK) { | 653 if (status != SERVICE_WORKER_OK) { |
| 654 notification_click_requests_.Remove(request_id); | 654 notification_click_requests_.Remove(request_id); |
| 655 RunSoon(base::Bind(callback, status)); | 655 RunSoon(base::Bind(callback, status)); |
| 656 } | 656 } |
| 657 } | 657 } |
| 658 | 658 |
| 659 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, | |
| 660 const std::string& data) { | |
| 661 OnBeginEvent(); | |
| 662 DCHECK_EQ(ACTIVATED, status()) << status(); | |
| 663 if (running_status() != RUNNING) { | |
| 664 // Schedule calling this method after starting the worker. | |
| 665 StartWorker(base::Bind(&RunTaskAfterStartWorker, | |
| 666 weak_factory_.GetWeakPtr(), callback, | |
| 667 base::Bind(&self::DispatchPushEvent, | |
| 668 weak_factory_.GetWeakPtr(), | |
| 669 callback, data))); | |
| 670 return; | |
| 671 } | |
| 672 | |
| 673 int request_id = AddRequest(callback, &push_requests_, REQUEST_PUSH, | |
| 674 ServiceWorkerMetrics::EventType::PUSH); | |
| 675 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | |
| 676 ServiceWorkerMsg_PushEvent(request_id, data)); | |
| 677 if (status != SERVICE_WORKER_OK) { | |
| 678 push_requests_.Remove(request_id); | |
| 679 RunSoon(base::Bind(callback, status)); | |
| 680 } | |
| 681 } | |
| 682 | |
| 683 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( | 659 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( |
| 684 const NavigatorConnectClient& client, | 660 const NavigatorConnectClient& client, |
| 685 const base::string16& message, | 661 const base::string16& message, |
| 686 const std::vector<TransferredMessagePort>& sent_message_ports, | 662 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 687 const StatusCallback& callback) { | 663 const StatusCallback& callback) { |
| 688 OnBeginEvent(); | 664 OnBeginEvent(); |
| 689 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to | 665 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to |
| 690 // have already put all the sent message ports on hold. So no need to do that | 666 // have already put all the sent message ports on hold. So no need to do that |
| 691 // here again. | 667 // here again. |
| 692 | 668 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, | 953 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
| 978 OnGetClients) | 954 OnGetClients) |
| 979 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 955 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
| 980 OnActivateEventFinished) | 956 OnActivateEventFinished) |
| 981 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 957 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
| 982 OnInstallEventFinished) | 958 OnInstallEventFinished) |
| 983 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 959 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
| 984 OnFetchEventFinished) | 960 OnFetchEventFinished) |
| 985 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 961 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
| 986 OnNotificationClickEventFinished) | 962 OnNotificationClickEventFinished) |
| 987 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, | |
| 988 OnPushEventFinished) | |
| 989 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 963 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
| 990 OnOpenWindow) | 964 OnOpenWindow) |
| 991 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, | 965 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, |
| 992 OnSetCachedMetadata) | 966 OnSetCachedMetadata) |
| 993 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, | 967 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, |
| 994 OnClearCachedMetadata) | 968 OnClearCachedMetadata) |
| 995 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, | 969 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, |
| 996 OnPostMessageToClient) | 970 OnPostMessageToClient) |
| 997 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, | 971 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, |
| 998 OnFocusClient) | 972 OnFocusClient) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 } | 1142 } |
| 1169 | 1143 |
| 1170 ServiceWorkerMetrics::RecordEventDuration( | 1144 ServiceWorkerMetrics::RecordEventDuration( |
| 1171 request->event_type, base::TimeTicks::Now() - request->start_time); | 1145 request->event_type, base::TimeTicks::Now() - request->start_time); |
| 1172 | 1146 |
| 1173 scoped_refptr<ServiceWorkerVersion> protect(this); | 1147 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 1174 request->callback.Run(SERVICE_WORKER_OK); | 1148 request->callback.Run(SERVICE_WORKER_OK); |
| 1175 RemoveCallbackAndStopIfRedundant(¬ification_click_requests_, request_id); | 1149 RemoveCallbackAndStopIfRedundant(¬ification_click_requests_, request_id); |
| 1176 } | 1150 } |
| 1177 | 1151 |
| 1178 void ServiceWorkerVersion::OnPushEventFinished( | |
| 1179 int request_id, | |
| 1180 blink::WebServiceWorkerEventResult result) { | |
| 1181 TRACE_EVENT1("ServiceWorker", | |
| 1182 "ServiceWorkerVersion::OnPushEventFinished", | |
| 1183 "Request id", request_id); | |
| 1184 PendingRequest<StatusCallback>* request = push_requests_.Lookup(request_id); | |
| 1185 if (!request) { | |
| 1186 NOTREACHED() << "Got unexpected message: " << request_id; | |
| 1187 return; | |
| 1188 } | |
| 1189 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | |
| 1190 if (result == blink::WebServiceWorkerEventResultRejected) | |
| 1191 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
| 1192 | |
| 1193 ServiceWorkerMetrics::RecordEventDuration( | |
| 1194 request->event_type, base::TimeTicks::Now() - request->start_time); | |
| 1195 | |
| 1196 scoped_refptr<ServiceWorkerVersion> protect(this); | |
| 1197 request->callback.Run(status); | |
| 1198 RemoveCallbackAndStopIfRedundant(&push_requests_, request_id); | |
| 1199 } | |
| 1200 | |
| 1201 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { | 1152 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { |
| 1202 // Just abort if we are shutting down. | 1153 // Just abort if we are shutting down. |
| 1203 if (!context_) | 1154 if (!context_) |
| 1204 return; | 1155 return; |
| 1205 | 1156 |
| 1206 if (!url.is_valid()) { | 1157 if (!url.is_valid()) { |
| 1207 DVLOG(1) << "Received unexpected invalid URL from renderer process."; | 1158 DVLOG(1) << "Received unexpected invalid URL from renderer process."; |
| 1208 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1159 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 1209 base::Bind(&KillEmbeddedWorkerProcess, | 1160 base::Bind(&KillEmbeddedWorkerProcess, |
| 1210 embedded_worker_->process_id(), | 1161 embedded_worker_->process_id(), |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1726 !stop_callbacks_.empty()) { | 1677 !stop_callbacks_.empty()) { |
| 1727 return; | 1678 return; |
| 1728 } | 1679 } |
| 1729 | 1680 |
| 1730 embedded_worker_->StopIfIdle(); | 1681 embedded_worker_->StopIfIdle(); |
| 1731 } | 1682 } |
| 1732 | 1683 |
| 1733 bool ServiceWorkerVersion::HasInflightRequests() const { | 1684 bool ServiceWorkerVersion::HasInflightRequests() const { |
| 1734 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || | 1685 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || |
| 1735 !fetch_requests_.IsEmpty() || | 1686 !fetch_requests_.IsEmpty() || |
| 1736 !notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() || | 1687 !notification_click_requests_.IsEmpty() || |
| 1737 !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty(); | 1688 !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty(); |
| 1738 } | 1689 } |
| 1739 | 1690 |
| 1740 void ServiceWorkerVersion::RecordStartWorkerResult( | 1691 void ServiceWorkerVersion::RecordStartWorkerResult( |
| 1741 ServiceWorkerStatusCode status) { | 1692 ServiceWorkerStatusCode status) { |
| 1742 base::TimeTicks start_time = start_time_; | 1693 base::TimeTicks start_time = start_time_; |
| 1743 ClearTick(&start_time_); | 1694 ClearTick(&start_time_); |
| 1744 | 1695 |
| 1745 ServiceWorkerMetrics::RecordStartWorkerStatus(status, | 1696 ServiceWorkerMetrics::RecordStartWorkerStatus(status, |
| 1746 IsInstalled(prestart_status_)); | 1697 IsInstalled(prestart_status_)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 return RunIDMapCallback(&install_requests_, info.id, | 1775 return RunIDMapCallback(&install_requests_, info.id, |
| 1825 SERVICE_WORKER_ERROR_TIMEOUT); | 1776 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1826 case REQUEST_FETCH: | 1777 case REQUEST_FETCH: |
| 1827 return RunIDMapCallback( | 1778 return RunIDMapCallback( |
| 1828 &fetch_requests_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, | 1779 &fetch_requests_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, |
| 1829 /* The other args are ignored for non-OK status. */ | 1780 /* The other args are ignored for non-OK status. */ |
| 1830 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); | 1781 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); |
| 1831 case REQUEST_NOTIFICATION_CLICK: | 1782 case REQUEST_NOTIFICATION_CLICK: |
| 1832 return RunIDMapCallback(¬ification_click_requests_, info.id, | 1783 return RunIDMapCallback(¬ification_click_requests_, info.id, |
| 1833 SERVICE_WORKER_ERROR_TIMEOUT); | 1784 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1834 case REQUEST_PUSH: | |
| 1835 return RunIDMapCallback(&push_requests_, info.id, | |
| 1836 SERVICE_WORKER_ERROR_TIMEOUT); | |
| 1837 case REQUEST_CUSTOM: | 1785 case REQUEST_CUSTOM: |
| 1838 return RunIDMapCallback(&custom_requests_, info.id, | 1786 return RunIDMapCallback(&custom_requests_, info.id, |
| 1839 SERVICE_WORKER_ERROR_TIMEOUT); | 1787 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1840 case NUM_REQUEST_TYPES: | 1788 case NUM_REQUEST_TYPES: |
| 1841 break; | 1789 break; |
| 1842 } | 1790 } |
| 1843 NOTREACHED() << "Got unexpected request type: " << info.type; | 1791 NOTREACHED() << "Got unexpected request type: " << info.type; |
| 1844 return false; | 1792 return false; |
| 1845 } | 1793 } |
| 1846 | 1794 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1946 // callbacks for events). | 1894 // callbacks for events). |
| 1947 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. | 1895 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. |
| 1948 RunIDMapCallbacks(&activate_requests_, | 1896 RunIDMapCallbacks(&activate_requests_, |
| 1949 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); | 1897 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); |
| 1950 RunIDMapCallbacks(&install_requests_, | 1898 RunIDMapCallbacks(&install_requests_, |
| 1951 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); | 1899 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); |
| 1952 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, | 1900 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, |
| 1953 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, | 1901 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
| 1954 ServiceWorkerResponse()); | 1902 ServiceWorkerResponse()); |
| 1955 RunIDMapCallbacks(¬ification_click_requests_, SERVICE_WORKER_ERROR_FAILED); | 1903 RunIDMapCallbacks(¬ification_click_requests_, SERVICE_WORKER_ERROR_FAILED); |
| 1956 RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED); | |
| 1957 RunIDMapCallbacks(&custom_requests_, SERVICE_WORKER_ERROR_FAILED); | 1904 RunIDMapCallbacks(&custom_requests_, SERVICE_WORKER_ERROR_FAILED); |
| 1958 | 1905 |
| 1959 // Close all mojo services. This will also fire and clear all callbacks | 1906 // Close all mojo services. This will also fire and clear all callbacks |
| 1960 // for messages that are still outstanding for those services. | 1907 // for messages that are still outstanding for those services. |
| 1961 mojo_services_.clear(); | 1908 mojo_services_.clear(); |
| 1962 | 1909 |
| 1963 // TODO(falken): Call SWURLRequestJob::ClearStream here? | 1910 // TODO(falken): Call SWURLRequestJob::ClearStream here? |
| 1964 streaming_url_request_jobs_.clear(); | 1911 streaming_url_request_jobs_.clear(); |
| 1965 | 1912 |
| 1966 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 1913 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1978 void ServiceWorkerVersion::OnBeginEvent() { | 1925 void ServiceWorkerVersion::OnBeginEvent() { |
| 1979 if (should_exclude_from_uma_ || running_status() != RUNNING || | 1926 if (should_exclude_from_uma_ || running_status() != RUNNING || |
| 1980 idle_time_.is_null()) { | 1927 idle_time_.is_null()) { |
| 1981 return; | 1928 return; |
| 1982 } | 1929 } |
| 1983 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1930 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 1984 idle_time_); | 1931 idle_time_); |
| 1985 } | 1932 } |
| 1986 | 1933 |
| 1987 } // namespace content | 1934 } // namespace content |
| OLD | NEW |