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

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

Issue 1439333002: Service Worker: Add Clients.get(id) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary condition Created 4 years, 10 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_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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 source_identifier, 885 source_identifier,
886 message_level, 886 message_level,
887 message, 887 message,
888 line_number, 888 line_number,
889 source_url)); 889 source_url));
890 } 890 }
891 891
892 bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { 892 bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) {
893 bool handled = true; 893 bool handled = true;
894 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message) 894 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerVersion, message)
895 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClient, OnGetClient)
895 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients, 896 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClients,
896 OnGetClients) 897 OnGetClients)
897 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, 898 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow,
898 OnOpenWindow) 899 OnOpenWindow)
899 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, 900 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata,
900 OnSetCachedMetadata) 901 OnSetCachedMetadata)
901 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, 902 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata,
902 OnClearCachedMetadata) 903 OnClearCachedMetadata)
903 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, 904 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient,
904 OnPostMessageToClient) 905 OnPostMessageToClient)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 embedded_worker_->message_port_message_filter(); 938 embedded_worker_->message_port_message_filter();
938 std::vector<int> new_routing_ids; 939 std::vector<int> new_routing_ids;
939 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids); 940 filter->UpdateMessagePortsWithNewRoutes(sent_message_ports, &new_routing_ids);
940 941
941 DispatchSimpleEvent<ServiceWorkerHostMsg_ExtendableMessageEventFinished>( 942 DispatchSimpleEvent<ServiceWorkerHostMsg_ExtendableMessageEventFinished>(
942 request_id, 943 request_id,
943 ServiceWorkerMsg_ExtendableMessageEvent( 944 ServiceWorkerMsg_ExtendableMessageEvent(
944 request_id, message, sent_message_ports, new_routing_ids)); 945 request_id, message, sent_message_ports, new_routing_ids));
945 } 946 }
946 947
948 void ServiceWorkerVersion::OnGetClient(int request_id,
949 const std::string& client_uuid) {
950 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "ServiceWorkerVersion::OnGetClient",
951 request_id, "client_uuid", client_uuid);
952 service_worker_client_utils::GetClient(
953 weak_factory_.GetWeakPtr(), client_uuid, context_,
954 base::Bind(&ServiceWorkerVersion::OnGetClientFinished,
955 weak_factory_.GetWeakPtr(), request_id));
956 }
957
958 void ServiceWorkerVersion::OnGetClientFinished(
959 int request_id,
960 const ServiceWorkerClientInfo& client_info) {
961 DCHECK_CURRENTLY_ON(BrowserThread::IO);
962 TRACE_EVENT_ASYNC_END1("ServiceWorker", "ServiceWorkerVersion::OnGetClient",
963 request_id, "client_type", client_info.client_type);
964
965 // When Clients.get() is called on the script evaluation phase, the running
966 // status can be STARTING here.
967 if (running_status() != STARTING && running_status() != RUNNING)
968 return;
969
970 embedded_worker_->SendMessage(
971 ServiceWorkerMsg_DidGetClient(request_id, client_info));
972 }
973
947 void ServiceWorkerVersion::OnGetClients( 974 void ServiceWorkerVersion::OnGetClients(
948 int request_id, 975 int request_id,
949 const ServiceWorkerClientQueryOptions& options) { 976 const ServiceWorkerClientQueryOptions& options) {
950 TRACE_EVENT_ASYNC_BEGIN2( 977 TRACE_EVENT_ASYNC_BEGIN2(
951 "ServiceWorker", "ServiceWorkerVersion::OnGetClients", request_id, 978 "ServiceWorker", "ServiceWorkerVersion::OnGetClients", request_id,
952 "client_type", options.client_type, "include_uncontrolled", 979 "client_type", options.client_type, "include_uncontrolled",
953 options.include_uncontrolled); 980 options.include_uncontrolled);
954 service_worker_client_utils::GetClients( 981 service_worker_client_utils::GetClients(
955 weak_factory_.GetWeakPtr(), options, 982 weak_factory_.GetWeakPtr(), options,
956 base::Bind(&ServiceWorkerVersion::OnGetClientsFinished, 983 base::Bind(&ServiceWorkerVersion::OnGetClientsFinished,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 1048
1022 service_worker_client_utils::OpenWindow( 1049 service_worker_client_utils::OpenWindow(
1023 url, script_url_, embedded_worker_->process_id(), context_, 1050 url, script_url_, embedded_worker_->process_id(), context_,
1024 base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished, 1051 base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished,
1025 weak_factory_.GetWeakPtr(), request_id)); 1052 weak_factory_.GetWeakPtr(), request_id));
1026 } 1053 }
1027 1054
1028 void ServiceWorkerVersion::OnOpenWindowFinished( 1055 void ServiceWorkerVersion::OnOpenWindowFinished(
1029 int request_id, 1056 int request_id,
1030 ServiceWorkerStatusCode status, 1057 ServiceWorkerStatusCode status,
1031 const std::string& client_uuid,
1032 const ServiceWorkerClientInfo& client_info) { 1058 const ServiceWorkerClientInfo& client_info) {
1033 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1059 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1034 1060
1035 if (running_status() != RUNNING) 1061 if (running_status() != RUNNING)
1036 return; 1062 return;
1037 1063
1038 if (status != SERVICE_WORKER_OK) { 1064 if (status != SERVICE_WORKER_OK) {
1039 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError( 1065 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(
1040 request_id, "Something went wrong while trying to open the window.")); 1066 request_id, "Something went wrong while trying to open the window."));
1041 return; 1067 return;
1042 } 1068 }
1043 1069
1044 ServiceWorkerClientInfo client(client_info); 1070 embedded_worker_->SendMessage(
1045 1071 ServiceWorkerMsg_OpenWindowResponse(request_id, client_info));
1046 // If the |client_info| is empty, it means that the opened window wasn't
1047 // controlled but the action still succeeded. The renderer process is
1048 // expecting an empty client in such case.
1049 if (!client.IsEmpty())
1050 client.client_uuid = client_uuid;
1051
1052 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowResponse(
1053 request_id, client));
1054 } 1072 }
1055 1073
1056 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url, 1074 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url,
1057 const std::vector<char>& data) { 1075 const std::vector<char>& data) {
1058 int64_t callback_id = base::TimeTicks::Now().ToInternalValue(); 1076 int64_t callback_id = base::TimeTicks::Now().ToInternalValue();
1059 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", 1077 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
1060 "ServiceWorkerVersion::OnSetCachedMetadata", 1078 "ServiceWorkerVersion::OnSetCachedMetadata",
1061 callback_id, "URL", url.spec()); 1079 callback_id, "URL", url.spec());
1062 script_cache_map_.WriteMetadata( 1080 script_cache_map_.WriteMetadata(
1063 url, data, base::Bind(&ServiceWorkerVersion::OnSetCachedMetadataFinished, 1081 url, data, base::Bind(&ServiceWorkerVersion::OnSetCachedMetadataFinished,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 if (!provider_host) { 1144 if (!provider_host) {
1127 // The client may already have been closed, just ignore. 1145 // The client may already have been closed, just ignore.
1128 return; 1146 return;
1129 } 1147 }
1130 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) { 1148 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) {
1131 // The client does not belong to the same origin as this ServiceWorker, 1149 // The client does not belong to the same origin as this ServiceWorker,
1132 // possibly due to timing issue or bad message. 1150 // possibly due to timing issue or bad message.
1133 return; 1151 return;
1134 } 1152 }
1135 provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished, 1153 provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished,
1136 weak_factory_.GetWeakPtr(), request_id, 1154 weak_factory_.GetWeakPtr(), request_id));
1137 client_uuid));
1138 } 1155 }
1139 1156
1140 void ServiceWorkerVersion::OnFocusClientFinished( 1157 void ServiceWorkerVersion::OnFocusClientFinished(
1141 int request_id, 1158 int request_id,
1142 const std::string& client_uuid, 1159 const ServiceWorkerClientInfo& client_info) {
1143 const ServiceWorkerClientInfo& client) {
1144 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1160 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1145 1161
1146 if (running_status() != RUNNING) 1162 if (running_status() != RUNNING)
1147 return; 1163 return;
1148 1164
1149 ServiceWorkerClientInfo client_info(client); 1165 embedded_worker_->SendMessage(
1150 client_info.client_uuid = client_uuid; 1166 ServiceWorkerMsg_FocusClientResponse(request_id, client_info));
1151
1152 embedded_worker_->SendMessage(ServiceWorkerMsg_FocusClientResponse(
1153 request_id, client_info));
1154 } 1167 }
1155 1168
1156 void ServiceWorkerVersion::OnNavigateClient(int request_id, 1169 void ServiceWorkerVersion::OnNavigateClient(int request_id,
1157 const std::string& client_uuid, 1170 const std::string& client_uuid,
1158 const GURL& url) { 1171 const GURL& url) {
1159 if (!context_) 1172 if (!context_)
1160 return; 1173 return;
1161 1174
1162 TRACE_EVENT2("ServiceWorker", "ServiceWorkerVersion::OnNavigateClient", 1175 TRACE_EVENT2("ServiceWorker", "ServiceWorkerVersion::OnNavigateClient",
1163 "Request id", request_id, "Client id", client_uuid); 1176 "Request id", request_id, "Client id", client_uuid);
(...skipping 28 matching lines...) Expand all
1192 1205
1193 service_worker_client_utils::NavigateClient( 1206 service_worker_client_utils::NavigateClient(
1194 url, script_url_, provider_host->process_id(), provider_host->frame_id(), 1207 url, script_url_, provider_host->process_id(), provider_host->frame_id(),
1195 context_, base::Bind(&ServiceWorkerVersion::OnNavigateClientFinished, 1208 context_, base::Bind(&ServiceWorkerVersion::OnNavigateClientFinished,
1196 weak_factory_.GetWeakPtr(), request_id)); 1209 weak_factory_.GetWeakPtr(), request_id));
1197 } 1210 }
1198 1211
1199 void ServiceWorkerVersion::OnNavigateClientFinished( 1212 void ServiceWorkerVersion::OnNavigateClientFinished(
1200 int request_id, 1213 int request_id,
1201 ServiceWorkerStatusCode status, 1214 ServiceWorkerStatusCode status,
1202 const std::string& client_uuid,
1203 const ServiceWorkerClientInfo& client_info) { 1215 const ServiceWorkerClientInfo& client_info) {
1204 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1216 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1205 1217
1206 if (running_status() != RUNNING) 1218 if (running_status() != RUNNING)
1207 return; 1219 return;
1208 1220
1209 if (status != SERVICE_WORKER_OK) { 1221 if (status != SERVICE_WORKER_OK) {
1210 embedded_worker_->SendMessage( 1222 embedded_worker_->SendMessage(
1211 ServiceWorkerMsg_NavigateClientError(request_id, GURL())); 1223 ServiceWorkerMsg_NavigateClientError(request_id, GURL()));
1212 return; 1224 return;
1213 } 1225 }
1214 1226
1215 ServiceWorkerClientInfo client(client_info);
1216
1217 // If the |client_info| is empty, it means that the navigated client wasn't
1218 // controlled but the action still succeeded. The renderer process is
1219 // expecting an empty client in such case.
1220 if (!client.IsEmpty())
1221 client.client_uuid = client_uuid;
1222
1223 embedded_worker_->SendMessage( 1227 embedded_worker_->SendMessage(
1224 ServiceWorkerMsg_NavigateClientResponse(request_id, client)); 1228 ServiceWorkerMsg_NavigateClientResponse(request_id, client_info));
1225 } 1229 }
1226 1230
1227 void ServiceWorkerVersion::OnSkipWaiting(int request_id) { 1231 void ServiceWorkerVersion::OnSkipWaiting(int request_id) {
1228 skip_waiting_ = true; 1232 skip_waiting_ = true;
1229 if (status_ != INSTALLED) 1233 if (status_ != INSTALLED)
1230 return DidSkipWaiting(request_id); 1234 return DidSkipWaiting(request_id);
1231 1235
1232 if (!context_) 1236 if (!context_)
1233 return; 1237 return;
1234 ServiceWorkerRegistration* registration = 1238 ServiceWorkerRegistration* registration =
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 void ServiceWorkerVersion::OnBeginEvent() { 1769 void ServiceWorkerVersion::OnBeginEvent() {
1766 if (should_exclude_from_uma_ || running_status() != RUNNING || 1770 if (should_exclude_from_uma_ || running_status() != RUNNING ||
1767 idle_time_.is_null()) { 1771 idle_time_.is_null()) {
1768 return; 1772 return;
1769 } 1773 }
1770 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - 1774 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() -
1771 idle_time_); 1775 idle_time_);
1772 } 1776 }
1773 1777
1774 } // namespace content 1778 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/common/service_worker/service_worker_client_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698