| 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" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { | 272 void KillEmbeddedWorkerProcess(int process_id, ResultCode code) { |
| 273 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 273 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 274 | 274 |
| 275 RenderProcessHost* render_process_host = | 275 RenderProcessHost* render_process_host = |
| 276 RenderProcessHost::FromID(process_id); | 276 RenderProcessHost::FromID(process_id); |
| 277 if (render_process_host->GetHandle() != base::kNullProcessHandle) | 277 if (render_process_host->GetHandle() != base::kNullProcessHandle) |
| 278 render_process_host->ReceivedBadMessage(); | 278 render_process_host->ReceivedBadMessage(); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void DidSetCachedMetadata(int64 callback_id, int result) { | |
| 282 TRACE_EVENT_ASYNC_END1("ServiceWorker", | |
| 283 "ServiceWorkerVersion::OnSetCachedMetadata", | |
| 284 callback_id, "result", result); | |
| 285 } | |
| 286 | |
| 287 void DidClearCachedMetadata(int64 callback_id, int result) { | |
| 288 TRACE_EVENT_ASYNC_END1("ServiceWorker", | |
| 289 "ServiceWorkerVersion::OnClearCachedMetadata", | |
| 290 callback_id, "result", result); | |
| 291 } | |
| 292 | |
| 293 } // namespace | 281 } // namespace |
| 294 | 282 |
| 295 ServiceWorkerVersion::ServiceWorkerVersion( | 283 ServiceWorkerVersion::ServiceWorkerVersion( |
| 296 ServiceWorkerRegistration* registration, | 284 ServiceWorkerRegistration* registration, |
| 297 const GURL& script_url, | 285 const GURL& script_url, |
| 298 int64 version_id, | 286 int64 version_id, |
| 299 base::WeakPtr<ServiceWorkerContextCore> context) | 287 base::WeakPtr<ServiceWorkerContextCore> context) |
| 300 : version_id_(version_id), | 288 : version_id_(version_id), |
| 301 registration_id_(kInvalidServiceWorkerVersionId), | 289 registration_id_(kInvalidServiceWorkerVersionId), |
| 302 script_url_(script_url), | 290 script_url_(script_url), |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 request_id, client)); | 1245 request_id, client)); |
| 1258 } | 1246 } |
| 1259 | 1247 |
| 1260 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url, | 1248 void ServiceWorkerVersion::OnSetCachedMetadata(const GURL& url, |
| 1261 const std::vector<char>& data) { | 1249 const std::vector<char>& data) { |
| 1262 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); | 1250 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); |
| 1263 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 1251 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 1264 "ServiceWorkerVersion::OnSetCachedMetadata", | 1252 "ServiceWorkerVersion::OnSetCachedMetadata", |
| 1265 callback_id, "URL", url.spec()); | 1253 callback_id, "URL", url.spec()); |
| 1266 script_cache_map_.WriteMetadata( | 1254 script_cache_map_.WriteMetadata( |
| 1267 url, data, base::Bind(&DidSetCachedMetadata, callback_id)); | 1255 url, data, base::Bind(&ServiceWorkerVersion::OnSetCachedMetadataFinished, |
| 1256 weak_factory_.GetWeakPtr(), callback_id)); |
| 1257 } |
| 1258 |
| 1259 void ServiceWorkerVersion::OnSetCachedMetadataFinished(int64 callback_id, |
| 1260 int result) { |
| 1261 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 1262 "ServiceWorkerVersion::OnSetCachedMetadata", |
| 1263 callback_id, "result", result); |
| 1264 FOR_EACH_OBSERVER(Listener, listeners_, OnCachedMetadataUpdated(this)); |
| 1268 } | 1265 } |
| 1269 | 1266 |
| 1270 void ServiceWorkerVersion::OnClearCachedMetadata(const GURL& url) { | 1267 void ServiceWorkerVersion::OnClearCachedMetadata(const GURL& url) { |
| 1271 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); | 1268 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); |
| 1272 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 1269 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 1273 "ServiceWorkerVersion::OnClearCachedMetadata", | 1270 "ServiceWorkerVersion::OnClearCachedMetadata", |
| 1274 callback_id, "URL", url.spec()); | 1271 callback_id, "URL", url.spec()); |
| 1275 script_cache_map_.ClearMetadata( | 1272 script_cache_map_.ClearMetadata( |
| 1276 url, base::Bind(&DidClearCachedMetadata, callback_id)); | 1273 url, base::Bind(&ServiceWorkerVersion::OnClearCachedMetadataFinished, |
| 1274 weak_factory_.GetWeakPtr(), callback_id)); |
| 1275 } |
| 1276 |
| 1277 void ServiceWorkerVersion::OnClearCachedMetadataFinished(int64 callback_id, |
| 1278 int result) { |
| 1279 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 1280 "ServiceWorkerVersion::OnClearCachedMetadata", |
| 1281 callback_id, "result", result); |
| 1282 FOR_EACH_OBSERVER(Listener, listeners_, OnCachedMetadataUpdated(this)); |
| 1277 } | 1283 } |
| 1278 | 1284 |
| 1279 void ServiceWorkerVersion::OnPostMessageToDocument( | 1285 void ServiceWorkerVersion::OnPostMessageToDocument( |
| 1280 int client_id, | 1286 int client_id, |
| 1281 const base::string16& message, | 1287 const base::string16& message, |
| 1282 const std::vector<int>& sent_message_port_ids) { | 1288 const std::vector<int>& sent_message_port_ids) { |
| 1283 TRACE_EVENT1("ServiceWorker", | 1289 TRACE_EVENT1("ServiceWorker", |
| 1284 "ServiceWorkerVersion::OnPostMessageToDocument", | 1290 "ServiceWorkerVersion::OnPostMessageToDocument", |
| 1285 "Client id", client_id); | 1291 "Client id", client_id); |
| 1286 ServiceWorkerProviderHost* provider_host = | 1292 ServiceWorkerProviderHost* provider_host = |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 int request_id) { | 1517 int request_id) { |
| 1512 callbacks->Remove(request_id); | 1518 callbacks->Remove(request_id); |
| 1513 if (is_doomed_) { | 1519 if (is_doomed_) { |
| 1514 // The stop should be already scheduled, but try to stop immediately, in | 1520 // The stop should be already scheduled, but try to stop immediately, in |
| 1515 // order to release worker resources soon. | 1521 // order to release worker resources soon. |
| 1516 StopWorkerIfIdle(); | 1522 StopWorkerIfIdle(); |
| 1517 } | 1523 } |
| 1518 } | 1524 } |
| 1519 | 1525 |
| 1520 } // namespace content | 1526 } // namespace content |
| OLD | NEW |