| 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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 ServiceWorkerStatusCode status = | 660 ServiceWorkerStatusCode status = |
| 661 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( | 661 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( |
| 662 request_id, persistent_notification_id, notification_data, | 662 request_id, persistent_notification_id, notification_data, |
| 663 action_index)); | 663 action_index)); |
| 664 if (status != SERVICE_WORKER_OK) { | 664 if (status != SERVICE_WORKER_OK) { |
| 665 notification_click_requests_.Remove(request_id); | 665 notification_click_requests_.Remove(request_id); |
| 666 RunSoon(base::Bind(callback, status)); | 666 RunSoon(base::Bind(callback, status)); |
| 667 } | 667 } |
| 668 } | 668 } |
| 669 | 669 |
| 670 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, | |
| 671 const std::string& data) { | |
| 672 OnBeginEvent(); | |
| 673 DCHECK_EQ(ACTIVATED, status()) << status(); | |
| 674 if (running_status() != RUNNING) { | |
| 675 // Schedule calling this method after starting the worker. | |
| 676 StartWorker(base::Bind(&RunTaskAfterStartWorker, | |
| 677 weak_factory_.GetWeakPtr(), callback, | |
| 678 base::Bind(&self::DispatchPushEvent, | |
| 679 weak_factory_.GetWeakPtr(), | |
| 680 callback, data))); | |
| 681 return; | |
| 682 } | |
| 683 | |
| 684 int request_id = AddRequest(callback, &push_requests_, REQUEST_PUSH, | |
| 685 ServiceWorkerMetrics::EventType::PUSH); | |
| 686 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | |
| 687 ServiceWorkerMsg_PushEvent(request_id, data)); | |
| 688 if (status != SERVICE_WORKER_OK) { | |
| 689 push_requests_.Remove(request_id); | |
| 690 RunSoon(base::Bind(callback, status)); | |
| 691 } | |
| 692 } | |
| 693 | |
| 694 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( | 670 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( |
| 695 const NavigatorConnectClient& client, | 671 const NavigatorConnectClient& client, |
| 696 const base::string16& message, | 672 const base::string16& message, |
| 697 const std::vector<TransferredMessagePort>& sent_message_ports, | 673 const std::vector<TransferredMessagePort>& sent_message_ports, |
| 698 const StatusCallback& callback) { | 674 const StatusCallback& callback) { |
| 699 OnBeginEvent(); | 675 OnBeginEvent(); |
| 700 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to | 676 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to |
| 701 // have already put all the sent message ports on hold. So no need to do that | 677 // have already put all the sent message ports on hold. So no need to do that |
| 702 // here again. | 678 // here again. |
| 703 | 679 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, | 964 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, |
| 989 OnGetClients) | 965 OnGetClients) |
| 990 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, | 966 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ActivateEventFinished, |
| 991 OnActivateEventFinished) | 967 OnActivateEventFinished) |
| 992 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, | 968 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_InstallEventFinished, |
| 993 OnInstallEventFinished) | 969 OnInstallEventFinished) |
| 994 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, | 970 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FetchEventFinished, |
| 995 OnFetchEventFinished) | 971 OnFetchEventFinished) |
| 996 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 972 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
| 997 OnNotificationClickEventFinished) | 973 OnNotificationClickEventFinished) |
| 998 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, | |
| 999 OnPushEventFinished) | |
| 1000 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 974 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
| 1001 OnOpenWindow) | 975 OnOpenWindow) |
| 1002 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, | 976 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, |
| 1003 OnSetCachedMetadata) | 977 OnSetCachedMetadata) |
| 1004 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, | 978 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, |
| 1005 OnClearCachedMetadata) | 979 OnClearCachedMetadata) |
| 1006 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, | 980 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, |
| 1007 OnPostMessageToClient) | 981 OnPostMessageToClient) |
| 1008 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, | 982 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, |
| 1009 OnFocusClient) | 983 OnFocusClient) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 } | 1153 } |
| 1180 | 1154 |
| 1181 ServiceWorkerMetrics::RecordEventDuration( | 1155 ServiceWorkerMetrics::RecordEventDuration( |
| 1182 request->event_type, base::TimeTicks::Now() - request->start_time); | 1156 request->event_type, base::TimeTicks::Now() - request->start_time); |
| 1183 | 1157 |
| 1184 scoped_refptr<ServiceWorkerVersion> protect(this); | 1158 scoped_refptr<ServiceWorkerVersion> protect(this); |
| 1185 request->callback.Run(SERVICE_WORKER_OK); | 1159 request->callback.Run(SERVICE_WORKER_OK); |
| 1186 RemoveCallbackAndStopIfRedundant(¬ification_click_requests_, request_id); | 1160 RemoveCallbackAndStopIfRedundant(¬ification_click_requests_, request_id); |
| 1187 } | 1161 } |
| 1188 | 1162 |
| 1189 void ServiceWorkerVersion::OnPushEventFinished( | |
| 1190 int request_id, | |
| 1191 blink::WebServiceWorkerEventResult result) { | |
| 1192 TRACE_EVENT1("ServiceWorker", | |
| 1193 "ServiceWorkerVersion::OnPushEventFinished", | |
| 1194 "Request id", request_id); | |
| 1195 PendingRequest<StatusCallback>* request = push_requests_.Lookup(request_id); | |
| 1196 if (!request) { | |
| 1197 NOTREACHED() << "Got unexpected message: " << request_id; | |
| 1198 return; | |
| 1199 } | |
| 1200 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | |
| 1201 if (result == blink::WebServiceWorkerEventResultRejected) | |
| 1202 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | |
| 1203 | |
| 1204 ServiceWorkerMetrics::RecordEventDuration( | |
| 1205 request->event_type, base::TimeTicks::Now() - request->start_time); | |
| 1206 | |
| 1207 scoped_refptr<ServiceWorkerVersion> protect(this); | |
| 1208 request->callback.Run(status); | |
| 1209 RemoveCallbackAndStopIfRedundant(&push_requests_, request_id); | |
| 1210 } | |
| 1211 | |
| 1212 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { | 1163 void ServiceWorkerVersion::OnOpenWindow(int request_id, GURL url) { |
| 1213 // Just abort if we are shutting down. | 1164 // Just abort if we are shutting down. |
| 1214 if (!context_) | 1165 if (!context_) |
| 1215 return; | 1166 return; |
| 1216 | 1167 |
| 1217 if (!url.is_valid()) { | 1168 if (!url.is_valid()) { |
| 1218 DVLOG(1) << "Received unexpected invalid URL from renderer process."; | 1169 DVLOG(1) << "Received unexpected invalid URL from renderer process."; |
| 1219 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1170 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 1220 base::Bind(&KillEmbeddedWorkerProcess, | 1171 base::Bind(&KillEmbeddedWorkerProcess, |
| 1221 embedded_worker_->process_id(), | 1172 embedded_worker_->process_id(), |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 !stop_callbacks_.empty()) { | 1688 !stop_callbacks_.empty()) { |
| 1738 return; | 1689 return; |
| 1739 } | 1690 } |
| 1740 | 1691 |
| 1741 embedded_worker_->StopIfIdle(); | 1692 embedded_worker_->StopIfIdle(); |
| 1742 } | 1693 } |
| 1743 | 1694 |
| 1744 bool ServiceWorkerVersion::HasInflightRequests() const { | 1695 bool ServiceWorkerVersion::HasInflightRequests() const { |
| 1745 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || | 1696 return !activate_requests_.IsEmpty() || !install_requests_.IsEmpty() || |
| 1746 !fetch_requests_.IsEmpty() || | 1697 !fetch_requests_.IsEmpty() || |
| 1747 !notification_click_requests_.IsEmpty() || !push_requests_.IsEmpty() || | 1698 !notification_click_requests_.IsEmpty() || |
| 1748 !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty(); | 1699 !custom_requests_.IsEmpty() || !streaming_url_request_jobs_.empty(); |
| 1749 } | 1700 } |
| 1750 | 1701 |
| 1751 void ServiceWorkerVersion::RecordStartWorkerResult( | 1702 void ServiceWorkerVersion::RecordStartWorkerResult( |
| 1752 ServiceWorkerStatusCode status) { | 1703 ServiceWorkerStatusCode status) { |
| 1753 base::TimeTicks start_time = start_time_; | 1704 base::TimeTicks start_time = start_time_; |
| 1754 ClearTick(&start_time_); | 1705 ClearTick(&start_time_); |
| 1755 | 1706 |
| 1756 ServiceWorkerMetrics::RecordStartWorkerStatus(status, | 1707 ServiceWorkerMetrics::RecordStartWorkerStatus(status, |
| 1757 IsInstalled(prestart_status_)); | 1708 IsInstalled(prestart_status_)); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1835 return RunIDMapCallback(&install_requests_, info.id, | 1786 return RunIDMapCallback(&install_requests_, info.id, |
| 1836 SERVICE_WORKER_ERROR_TIMEOUT); | 1787 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1837 case REQUEST_FETCH: | 1788 case REQUEST_FETCH: |
| 1838 return RunIDMapCallback( | 1789 return RunIDMapCallback( |
| 1839 &fetch_requests_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, | 1790 &fetch_requests_, info.id, SERVICE_WORKER_ERROR_TIMEOUT, |
| 1840 /* The other args are ignored for non-OK status. */ | 1791 /* The other args are ignored for non-OK status. */ |
| 1841 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); | 1792 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, ServiceWorkerResponse()); |
| 1842 case REQUEST_NOTIFICATION_CLICK: | 1793 case REQUEST_NOTIFICATION_CLICK: |
| 1843 return RunIDMapCallback(¬ification_click_requests_, info.id, | 1794 return RunIDMapCallback(¬ification_click_requests_, info.id, |
| 1844 SERVICE_WORKER_ERROR_TIMEOUT); | 1795 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1845 case REQUEST_PUSH: | |
| 1846 return RunIDMapCallback(&push_requests_, info.id, | |
| 1847 SERVICE_WORKER_ERROR_TIMEOUT); | |
| 1848 case REQUEST_CUSTOM: | 1796 case REQUEST_CUSTOM: |
| 1849 return RunIDMapCallback(&custom_requests_, info.id, | 1797 return RunIDMapCallback(&custom_requests_, info.id, |
| 1850 SERVICE_WORKER_ERROR_TIMEOUT); | 1798 SERVICE_WORKER_ERROR_TIMEOUT); |
| 1851 case NUM_REQUEST_TYPES: | 1799 case NUM_REQUEST_TYPES: |
| 1852 break; | 1800 break; |
| 1853 } | 1801 } |
| 1854 NOTREACHED() << "Got unexpected request type: " << info.type; | 1802 NOTREACHED() << "Got unexpected request type: " << info.type; |
| 1855 return false; | 1803 return false; |
| 1856 } | 1804 } |
| 1857 | 1805 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1957 // callbacks for events). | 1905 // callbacks for events). |
| 1958 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. | 1906 // TODO(kinuko): Consider if we want to add queue+resend mechanism here. |
| 1959 RunIDMapCallbacks(&activate_requests_, | 1907 RunIDMapCallbacks(&activate_requests_, |
| 1960 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); | 1908 SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED); |
| 1961 RunIDMapCallbacks(&install_requests_, | 1909 RunIDMapCallbacks(&install_requests_, |
| 1962 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); | 1910 SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED); |
| 1963 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, | 1911 RunIDMapCallbacks(&fetch_requests_, SERVICE_WORKER_ERROR_FAILED, |
| 1964 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, | 1912 SERVICE_WORKER_FETCH_EVENT_RESULT_FALLBACK, |
| 1965 ServiceWorkerResponse()); | 1913 ServiceWorkerResponse()); |
| 1966 RunIDMapCallbacks(¬ification_click_requests_, SERVICE_WORKER_ERROR_FAILED); | 1914 RunIDMapCallbacks(¬ification_click_requests_, SERVICE_WORKER_ERROR_FAILED); |
| 1967 RunIDMapCallbacks(&push_requests_, SERVICE_WORKER_ERROR_FAILED); | |
| 1968 RunIDMapCallbacks(&custom_requests_, SERVICE_WORKER_ERROR_FAILED); | 1915 RunIDMapCallbacks(&custom_requests_, SERVICE_WORKER_ERROR_FAILED); |
| 1969 | 1916 |
| 1970 // Close all mojo services. This will also fire and clear all callbacks | 1917 // Close all mojo services. This will also fire and clear all callbacks |
| 1971 // for messages that are still outstanding for those services. | 1918 // for messages that are still outstanding for those services. |
| 1972 mojo_services_.clear(); | 1919 mojo_services_.clear(); |
| 1973 | 1920 |
| 1974 // TODO(falken): Call SWURLRequestJob::ClearStream here? | 1921 // TODO(falken): Call SWURLRequestJob::ClearStream here? |
| 1975 streaming_url_request_jobs_.clear(); | 1922 streaming_url_request_jobs_.clear(); |
| 1976 | 1923 |
| 1977 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 1924 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1989 void ServiceWorkerVersion::OnBeginEvent() { | 1936 void ServiceWorkerVersion::OnBeginEvent() { |
| 1990 if (should_exclude_from_uma_ || running_status() != RUNNING || | 1937 if (should_exclude_from_uma_ || running_status() != RUNNING || |
| 1991 idle_time_.is_null()) { | 1938 idle_time_.is_null()) { |
| 1992 return; | 1939 return; |
| 1993 } | 1940 } |
| 1994 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1941 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 1995 idle_time_); | 1942 idle_time_); |
| 1996 } | 1943 } |
| 1997 | 1944 |
| 1998 } // namespace content | 1945 } // namespace content |
| OLD | NEW |