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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/time/time.h" |
12 #include "content/browser/message_port_message_filter.h" | 13 #include "content/browser/message_port_message_filter.h" |
13 #include "content/browser/message_port_service.h" | 14 #include "content/browser/message_port_service.h" |
14 #include "content/browser/service_worker/embedded_worker_instance.h" | 15 #include "content/browser/service_worker/embedded_worker_instance.h" |
15 #include "content/browser/service_worker/embedded_worker_registry.h" | 16 #include "content/browser/service_worker/embedded_worker_registry.h" |
16 #include "content/browser/service_worker/service_worker_context_core.h" | 17 #include "content/browser/service_worker/service_worker_context_core.h" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/browser/service_worker/service_worker_registration.h" | 19 #include "content/browser/service_worker/service_worker_registration.h" |
19 #include "content/browser/service_worker/service_worker_utils.h" | 20 #include "content/browser/service_worker/service_worker_utils.h" |
20 #include "content/browser/storage_partition_impl.h" | 21 #include "content/browser/storage_partition_impl.h" |
21 #include "content/common/service_worker/service_worker_messages.h" | 22 #include "content/common/service_worker/service_worker_messages.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 265 |
265 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { | 266 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { |
266 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 267 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
267 | 268 |
268 RenderProcessHost* render_process_host = | 269 RenderProcessHost* render_process_host = |
269 RenderProcessHost::FromID(process_id); | 270 RenderProcessHost::FromID(process_id); |
270 if (render_process_host->GetHandle() != base::kNullProcessHandle) | 271 if (render_process_host->GetHandle() != base::kNullProcessHandle) |
271 render_process_host->ReceivedBadMessage(); | 272 render_process_host->ReceivedBadMessage(); |
272 } | 273 } |
273 | 274 |
| 275 void DidSetCachedMetadata(int64 callback_id, int result) { |
| 276 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 277 "ServiceWorkerVersion::OnSetCachedMetadata", |
| 278 callback_id, "result", result); |
| 279 } |
| 280 |
| 281 void DidClearCachedMetadata(int64 callback_id, int result) { |
| 282 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 283 "ServiceWorkerVersion::OnClearCachedMetadata", |
| 284 callback_id, "result", result); |
| 285 } |
| 286 |
274 } // namespace | 287 } // namespace |
275 | 288 |
276 ServiceWorkerVersion::ServiceWorkerVersion( | 289 ServiceWorkerVersion::ServiceWorkerVersion( |
277 ServiceWorkerRegistration* registration, | 290 ServiceWorkerRegistration* registration, |
278 const GURL& script_url, | 291 const GURL& script_url, |
279 int64 version_id, | 292 int64 version_id, |
280 base::WeakPtr<ServiceWorkerContextCore> context) | 293 base::WeakPtr<ServiceWorkerContextCore> context) |
281 : version_id_(version_id), | 294 : version_id_(version_id), |
282 registration_id_(kInvalidServiceWorkerVersionId), | 295 registration_id_(kInvalidServiceWorkerVersionId), |
283 script_url_(script_url), | 296 script_url_(script_url), |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, | 935 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NotificationClickEventFinished, |
923 OnNotificationClickEventFinished) | 936 OnNotificationClickEventFinished) |
924 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, | 937 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PushEventFinished, |
925 OnPushEventFinished) | 938 OnPushEventFinished) |
926 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, | 939 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GeofencingEventFinished, |
927 OnGeofencingEventFinished) | 940 OnGeofencingEventFinished) |
928 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, | 941 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_CrossOriginConnectEventFinished, |
929 OnCrossOriginConnectEventFinished) | 942 OnCrossOriginConnectEventFinished) |
930 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 943 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
931 OnOpenWindow) | 944 OnOpenWindow) |
| 945 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, |
| 946 OnSetCachedMetadata) |
| 947 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, |
| 948 OnClearCachedMetadata) |
932 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument, | 949 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument, |
933 OnPostMessageToDocument) | 950 OnPostMessageToDocument) |
934 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, | 951 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, |
935 OnFocusClient) | 952 OnFocusClient) |
936 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, | 953 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, |
937 OnSkipWaiting) | 954 OnSkipWaiting) |
938 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, | 955 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, |
939 OnClaimClients) | 956 OnClaimClients) |
940 IPC_MESSAGE_UNHANDLED(handled = false) | 957 IPC_MESSAGE_UNHANDLED(handled = false) |
941 IPC_END_MESSAGE_MAP() | 958 IPC_END_MESSAGE_MAP() |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 // If the |client_info| is empty, it means that the opened window wasn't | 1244 // If the |client_info| is empty, it means that the opened window wasn't |
1228 // controlled but the action still succeeded. The renderer process is | 1245 // controlled but the action still succeeded. The renderer process is |
1229 // expecting an empty client in such case. | 1246 // expecting an empty client in such case. |
1230 if (!client.IsEmpty()) | 1247 if (!client.IsEmpty()) |
1231 client.client_id = client_id; | 1248 client.client_id = client_id; |
1232 | 1249 |
1233 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowResponse( | 1250 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowResponse( |
1234 request_id, client)); | 1251 request_id, client)); |
1235 } | 1252 } |
1236 | 1253 |
| 1254 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url, |
| 1255 const std::vector<char>& data) { |
| 1256 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); |
| 1257 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 1258 "ServiceWorkerVersion::OnSetCachedMetadata", |
| 1259 callback_id, "URL", url.spec()); |
| 1260 script_cache_map_.WriteMetadata( |
| 1261 url, data, base::Bind(&DidSetCachedMetadata, callback_id)); |
| 1262 } |
| 1263 |
| 1264 void ServiceWorkerVersion::OnClearCachedMetadata(const GURL& url) { |
| 1265 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); |
| 1266 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 1267 "ServiceWorkerVersion::OnClearCachedMetadata", |
| 1268 callback_id, "URL", url.spec()); |
| 1269 script_cache_map_.ClearMetadata( |
| 1270 url, base::Bind(&DidClearCachedMetadata, callback_id)); |
| 1271 } |
| 1272 |
1237 void ServiceWorkerVersion::OnPostMessageToDocument( | 1273 void ServiceWorkerVersion::OnPostMessageToDocument( |
1238 int client_id, | 1274 int client_id, |
1239 const base::string16& message, | 1275 const base::string16& message, |
1240 const std::vector<int>& sent_message_port_ids) { | 1276 const std::vector<int>& sent_message_port_ids) { |
1241 TRACE_EVENT1("ServiceWorker", | 1277 TRACE_EVENT1("ServiceWorker", |
1242 "ServiceWorkerVersion::OnPostMessageToDocument", | 1278 "ServiceWorkerVersion::OnPostMessageToDocument", |
1243 "Client id", client_id); | 1279 "Client id", client_id); |
1244 ServiceWorkerProviderHost* provider_host = | 1280 ServiceWorkerProviderHost* provider_host = |
1245 controllee_by_id_.Lookup(client_id); | 1281 controllee_by_id_.Lookup(client_id); |
1246 if (!provider_host) { | 1282 if (!provider_host) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 int request_id) { | 1458 int request_id) { |
1423 callbacks->Remove(request_id); | 1459 callbacks->Remove(request_id); |
1424 if (is_doomed_) { | 1460 if (is_doomed_) { |
1425 // The stop should be already scheduled, but try to stop immediately, in | 1461 // The stop should be already scheduled, but try to stop immediately, in |
1426 // order to release worker resources soon. | 1462 // order to release worker resources soon. |
1427 StopWorkerIfIdle(); | 1463 StopWorkerIfIdle(); |
1428 } | 1464 } |
1429 } | 1465 } |
1430 | 1466 |
1431 } // namespace content | 1467 } // namespace content |
OLD | NEW |