| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/cache_storage/cache_storage_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 void CacheStorageCache::Match( | 323 void CacheStorageCache::Match( |
| 324 std::unique_ptr<ServiceWorkerFetchRequest> request, | 324 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 325 const ResponseCallback& callback) { | 325 const ResponseCallback& callback) { |
| 326 if (backend_state_ == BACKEND_CLOSED) { | 326 if (backend_state_ == BACKEND_CLOSED) { |
| 327 callback.Run(CACHE_STORAGE_ERROR_STORAGE, | 327 callback.Run(CACHE_STORAGE_ERROR_STORAGE, |
| 328 std::unique_ptr<ServiceWorkerResponse>(), | 328 std::unique_ptr<ServiceWorkerResponse>(), |
| 329 std::unique_ptr<storage::BlobDataHandle>()); | 329 std::unique_ptr<storage::BlobDataHandle>()); |
| 330 return; | 330 return; |
| 331 } | 331 } |
| 332 | 332 |
| 333 ResponseCallback pending_callback = | |
| 334 base::Bind(&CacheStorageCache::PendingResponseCallback, | |
| 335 weak_ptr_factory_.GetWeakPtr(), callback); | |
| 336 scheduler_->ScheduleOperation( | 333 scheduler_->ScheduleOperation( |
| 337 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), | 334 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), |
| 338 base::Passed(std::move(request)), pending_callback)); | 335 base::Passed(std::move(request)), |
| 336 scheduler_->WrapCallbackToRunNext(callback))); |
| 339 } | 337 } |
| 340 | 338 |
| 341 void CacheStorageCache::MatchAll( | 339 void CacheStorageCache::MatchAll( |
| 342 std::unique_ptr<ServiceWorkerFetchRequest> request, | 340 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 343 const CacheStorageCacheQueryParams& match_params, | 341 const CacheStorageCacheQueryParams& match_params, |
| 344 const ResponsesCallback& callback) { | 342 const ResponsesCallback& callback) { |
| 345 if (backend_state_ == BACKEND_CLOSED) { | 343 if (backend_state_ == BACKEND_CLOSED) { |
| 346 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Responses>(), | 344 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Responses>(), |
| 347 std::unique_ptr<BlobDataHandles>()); | 345 std::unique_ptr<BlobDataHandles>()); |
| 348 return; | 346 return; |
| 349 } | 347 } |
| 350 | 348 |
| 351 ResponsesCallback pending_callback = | |
| 352 base::Bind(&CacheStorageCache::PendingResponsesCallback, | |
| 353 weak_ptr_factory_.GetWeakPtr(), callback); | |
| 354 | |
| 355 std::unique_ptr<MatchAllContext> context( | 349 std::unique_ptr<MatchAllContext> context( |
| 356 new MatchAllContext(std::move(request), match_params, pending_callback)); | 350 new MatchAllContext(std::move(request), match_params, |
| 351 scheduler_->WrapCallbackToRunNext(callback))); |
| 357 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, | 352 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, |
| 358 weak_ptr_factory_.GetWeakPtr(), | 353 weak_ptr_factory_.GetWeakPtr(), |
| 359 base::Passed(std::move(context)))); | 354 base::Passed(std::move(context)))); |
| 360 } | 355 } |
| 361 | 356 |
| 362 void CacheStorageCache::WriteSideData(const ErrorCallback& callback, | 357 void CacheStorageCache::WriteSideData(const ErrorCallback& callback, |
| 363 const GURL& url, | 358 const GURL& url, |
| 364 base::Time expected_response_time, | 359 base::Time expected_response_time, |
| 365 scoped_refptr<net::IOBuffer> buffer, | 360 scoped_refptr<net::IOBuffer> buffer, |
| 366 int buf_len) { | 361 int buf_len) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 return; | 476 return; |
| 482 callback->Run(CACHE_STORAGE_OK); | 477 callback->Run(CACHE_STORAGE_OK); |
| 483 } | 478 } |
| 484 | 479 |
| 485 void CacheStorageCache::Keys(const RequestsCallback& callback) { | 480 void CacheStorageCache::Keys(const RequestsCallback& callback) { |
| 486 if (backend_state_ == BACKEND_CLOSED) { | 481 if (backend_state_ == BACKEND_CLOSED) { |
| 487 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>()); | 482 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>()); |
| 488 return; | 483 return; |
| 489 } | 484 } |
| 490 | 485 |
| 491 RequestsCallback pending_callback = | 486 scheduler_->ScheduleOperation( |
| 492 base::Bind(&CacheStorageCache::PendingRequestsCallback, | 487 base::Bind(&CacheStorageCache::KeysImpl, weak_ptr_factory_.GetWeakPtr(), |
| 493 weak_ptr_factory_.GetWeakPtr(), callback); | 488 scheduler_->WrapCallbackToRunNext(callback))); |
| 494 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::KeysImpl, | |
| 495 weak_ptr_factory_.GetWeakPtr(), | |
| 496 pending_callback)); | |
| 497 } | 489 } |
| 498 | 490 |
| 499 void CacheStorageCache::Close(const base::Closure& callback) { | 491 void CacheStorageCache::Close(const base::Closure& callback) { |
| 500 DCHECK_NE(BACKEND_CLOSED, backend_state_) | 492 DCHECK_NE(BACKEND_CLOSED, backend_state_) |
| 501 << "Was CacheStorageCache::Close() called twice?"; | 493 << "Was CacheStorageCache::Close() called twice?"; |
| 502 | 494 |
| 503 base::Closure pending_callback = | 495 scheduler_->ScheduleOperation( |
| 504 base::Bind(&CacheStorageCache::PendingClosure, | 496 base::Bind(&CacheStorageCache::CloseImpl, weak_ptr_factory_.GetWeakPtr(), |
| 505 weak_ptr_factory_.GetWeakPtr(), callback); | 497 scheduler_->WrapCallbackToRunNext(callback))); |
| 506 | |
| 507 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::CloseImpl, | |
| 508 weak_ptr_factory_.GetWeakPtr(), | |
| 509 pending_callback)); | |
| 510 } | 498 } |
| 511 | 499 |
| 512 void CacheStorageCache::Size(const SizeCallback& callback) { | 500 void CacheStorageCache::Size(const SizeCallback& callback) { |
| 513 if (backend_state_ == BACKEND_CLOSED) { | 501 if (backend_state_ == BACKEND_CLOSED) { |
| 514 // TODO(jkarlin): Delete caches that can't be initialized. | 502 // TODO(jkarlin): Delete caches that can't be initialized. |
| 515 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 503 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 516 base::Bind(callback, 0)); | 504 base::Bind(callback, 0)); |
| 517 return; | 505 return; |
| 518 } | 506 } |
| 519 | 507 |
| 520 SizeCallback pending_callback = | 508 scheduler_->ScheduleOperation( |
| 521 base::Bind(&CacheStorageCache::PendingSizeCallback, | 509 base::Bind(&CacheStorageCache::SizeImpl, weak_ptr_factory_.GetWeakPtr(), |
| 522 weak_ptr_factory_.GetWeakPtr(), callback); | 510 scheduler_->WrapCallbackToRunNext(callback))); |
| 523 | |
| 524 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::SizeImpl, | |
| 525 weak_ptr_factory_.GetWeakPtr(), | |
| 526 pending_callback)); | |
| 527 } | 511 } |
| 528 | 512 |
| 529 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) { | 513 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) { |
| 530 if (backend_state_ == BACKEND_CLOSED) { | 514 if (backend_state_ == BACKEND_CLOSED) { |
| 531 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 515 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 532 base::Bind(callback, 0)); | 516 base::Bind(callback, 0)); |
| 533 return; | 517 return; |
| 534 } | 518 } |
| 535 | 519 |
| 536 SizeCallback pending_callback = | |
| 537 base::Bind(&CacheStorageCache::PendingSizeCallback, | |
| 538 weak_ptr_factory_.GetWeakPtr(), callback); | |
| 539 | |
| 540 scheduler_->ScheduleOperation( | 520 scheduler_->ScheduleOperation( |
| 541 base::Bind(&CacheStorageCache::SizeImpl, weak_ptr_factory_.GetWeakPtr(), | 521 base::Bind(&CacheStorageCache::SizeImpl, weak_ptr_factory_.GetWeakPtr(), |
| 542 base::Bind(&CacheStorageCache::GetSizeThenCloseDidGetSize, | 522 base::Bind(&CacheStorageCache::GetSizeThenCloseDidGetSize, |
| 543 weak_ptr_factory_.GetWeakPtr(), pending_callback))); | 523 weak_ptr_factory_.GetWeakPtr(), |
| 524 scheduler_->WrapCallbackToRunNext(callback)))); |
| 544 } | 525 } |
| 545 | 526 |
| 546 CacheStorageCache::~CacheStorageCache() { | 527 CacheStorageCache::~CacheStorageCache() { |
| 547 quota_manager_proxy_->NotifyOriginNoLongerInUse(origin_); | 528 quota_manager_proxy_->NotifyOriginNoLongerInUse(origin_); |
| 548 } | 529 } |
| 549 | 530 |
| 550 CacheStorageCache::CacheStorageCache( | 531 CacheStorageCache::CacheStorageCache( |
| 551 const GURL& origin, | 532 const GURL& origin, |
| 552 const std::string& cache_name, | 533 const std::string& cache_name, |
| 553 const base::FilePath& path, | 534 const base::FilePath& path, |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 int buf_len, | 807 int buf_len, |
| 827 storage::QuotaStatusCode status_code, | 808 storage::QuotaStatusCode status_code, |
| 828 int64_t usage, | 809 int64_t usage, |
| 829 int64_t quota) { | 810 int64_t quota) { |
| 830 if (status_code != storage::kQuotaStatusOk || (buf_len > quota - usage)) { | 811 if (status_code != storage::kQuotaStatusOk || (buf_len > quota - usage)) { |
| 831 base::ThreadTaskRunnerHandle::Get()->PostTask( | 812 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 832 FROM_HERE, base::Bind(callback, CACHE_STORAGE_ERROR_QUOTA_EXCEEDED)); | 813 FROM_HERE, base::Bind(callback, CACHE_STORAGE_ERROR_QUOTA_EXCEEDED)); |
| 833 return; | 814 return; |
| 834 } | 815 } |
| 835 | 816 |
| 836 ErrorCallback pending_callback = | |
| 837 base::Bind(&CacheStorageCache::PendingErrorCallback, | |
| 838 weak_ptr_factory_.GetWeakPtr(), callback); | |
| 839 | |
| 840 scheduler_->ScheduleOperation(base::Bind( | 817 scheduler_->ScheduleOperation(base::Bind( |
| 841 &CacheStorageCache::WriteSideDataImpl, weak_ptr_factory_.GetWeakPtr(), | 818 &CacheStorageCache::WriteSideDataImpl, weak_ptr_factory_.GetWeakPtr(), |
| 842 pending_callback, url, expected_response_time, buffer, buf_len)); | 819 scheduler_->WrapCallbackToRunNext(callback), url, expected_response_time, |
| 820 buffer, buf_len)); |
| 843 } | 821 } |
| 844 | 822 |
| 845 void CacheStorageCache::WriteSideDataImpl(const ErrorCallback& callback, | 823 void CacheStorageCache::WriteSideDataImpl(const ErrorCallback& callback, |
| 846 const GURL& url, | 824 const GURL& url, |
| 847 base::Time expected_response_time, | 825 base::Time expected_response_time, |
| 848 scoped_refptr<net::IOBuffer> buffer, | 826 scoped_refptr<net::IOBuffer> buffer, |
| 849 int buf_len) { | 827 int buf_len) { |
| 850 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 828 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
| 851 if (backend_state_ != BACKEND_OPEN) { | 829 if (backend_state_ != BACKEND_OPEN) { |
| 852 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 830 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 return; | 948 return; |
| 971 } | 949 } |
| 972 } | 950 } |
| 973 | 951 |
| 974 UMA_HISTOGRAM_ENUMERATION( | 952 UMA_HISTOGRAM_ENUMERATION( |
| 975 "ServiceWorkerCache.Cache.AllWritesResponseType", | 953 "ServiceWorkerCache.Cache.AllWritesResponseType", |
| 976 operation.response.response_type, | 954 operation.response.response_type, |
| 977 blink::WebServiceWorkerResponseType::WebServiceWorkerResponseTypeLast + | 955 blink::WebServiceWorkerResponseType::WebServiceWorkerResponseTypeLast + |
| 978 1); | 956 1); |
| 979 | 957 |
| 980 ErrorCallback pending_callback = | 958 std::unique_ptr<PutContext> put_context(new PutContext( |
| 981 base::Bind(&CacheStorageCache::PendingErrorCallback, | 959 std::move(request), std::move(response), std::move(blob_data_handle), |
| 982 weak_ptr_factory_.GetWeakPtr(), callback); | 960 scheduler_->WrapCallbackToRunNext(callback))); |
| 983 | |
| 984 std::unique_ptr<PutContext> put_context( | |
| 985 new PutContext(std::move(request), std::move(response), | |
| 986 std::move(blob_data_handle), pending_callback)); | |
| 987 | 961 |
| 988 scheduler_->ScheduleOperation( | 962 scheduler_->ScheduleOperation( |
| 989 base::Bind(&CacheStorageCache::PutImpl, weak_ptr_factory_.GetWeakPtr(), | 963 base::Bind(&CacheStorageCache::PutImpl, weak_ptr_factory_.GetWeakPtr(), |
| 990 base::Passed(std::move(put_context)))); | 964 base::Passed(std::move(put_context)))); |
| 991 } | 965 } |
| 992 | 966 |
| 993 void CacheStorageCache::PutImpl(std::unique_ptr<PutContext> put_context) { | 967 void CacheStorageCache::PutImpl(std::unique_ptr<PutContext> put_context) { |
| 994 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 968 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
| 995 if (backend_state_ != BACKEND_OPEN) { | 969 if (backend_state_ != BACKEND_OPEN) { |
| 996 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 970 put_context->callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); | 1164 DCHECK(BACKEND_OPEN == backend_state_ || initializing_); |
| 1191 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE, | 1165 DCHECK_EQ(CACHE_STORAGE_CACHE_OPERATION_TYPE_DELETE, |
| 1192 operation.operation_type); | 1166 operation.operation_type); |
| 1193 | 1167 |
| 1194 std::unique_ptr<ServiceWorkerFetchRequest> request( | 1168 std::unique_ptr<ServiceWorkerFetchRequest> request( |
| 1195 new ServiceWorkerFetchRequest( | 1169 new ServiceWorkerFetchRequest( |
| 1196 operation.request.url, operation.request.method, | 1170 operation.request.url, operation.request.method, |
| 1197 operation.request.headers, operation.request.referrer, | 1171 operation.request.headers, operation.request.referrer, |
| 1198 operation.request.is_reload)); | 1172 operation.request.is_reload)); |
| 1199 | 1173 |
| 1200 ErrorCallback pending_callback = | |
| 1201 base::Bind(&CacheStorageCache::PendingErrorCallback, | |
| 1202 weak_ptr_factory_.GetWeakPtr(), callback); | |
| 1203 scheduler_->ScheduleOperation( | 1174 scheduler_->ScheduleOperation( |
| 1204 base::Bind(&CacheStorageCache::DeleteImpl, weak_ptr_factory_.GetWeakPtr(), | 1175 base::Bind(&CacheStorageCache::DeleteImpl, weak_ptr_factory_.GetWeakPtr(), |
| 1205 base::Passed(std::move(request)), operation.match_params, | 1176 base::Passed(std::move(request)), operation.match_params, |
| 1206 pending_callback)); | 1177 scheduler_->WrapCallbackToRunNext(callback))); |
| 1207 } | 1178 } |
| 1208 | 1179 |
| 1209 void CacheStorageCache::DeleteImpl( | 1180 void CacheStorageCache::DeleteImpl( |
| 1210 std::unique_ptr<ServiceWorkerFetchRequest> request, | 1181 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 1211 const CacheStorageCacheQueryParams& match_params, | 1182 const CacheStorageCacheQueryParams& match_params, |
| 1212 const ErrorCallback& callback) { | 1183 const ErrorCallback& callback) { |
| 1213 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 1184 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
| 1214 if (backend_state_ != BACKEND_OPEN) { | 1185 if (backend_state_ != BACKEND_OPEN) { |
| 1215 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 1186 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| 1216 return; | 1187 return; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 backend_ = std::move(*backend_ptr); | 1394 backend_ = std::move(*backend_ptr); |
| 1424 callback.Run(CACHE_STORAGE_OK); | 1395 callback.Run(CACHE_STORAGE_OK); |
| 1425 } | 1396 } |
| 1426 | 1397 |
| 1427 void CacheStorageCache::InitBackend() { | 1398 void CacheStorageCache::InitBackend() { |
| 1428 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_); | 1399 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_); |
| 1429 DCHECK(!initializing_); | 1400 DCHECK(!initializing_); |
| 1430 DCHECK(!scheduler_->ScheduledOperations()); | 1401 DCHECK(!scheduler_->ScheduledOperations()); |
| 1431 initializing_ = true; | 1402 initializing_ = true; |
| 1432 | 1403 |
| 1433 base::Closure pending_callback = | |
| 1434 base::Bind(&CacheStorageCache::PendingClosure, | |
| 1435 weak_ptr_factory_.GetWeakPtr(), base::Bind(&base::DoNothing)); | |
| 1436 | |
| 1437 scheduler_->ScheduleOperation(base::Bind( | 1404 scheduler_->ScheduleOperation(base::Bind( |
| 1438 &CacheStorageCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(), | 1405 &CacheStorageCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(), |
| 1439 base::Bind(&CacheStorageCache::InitDidCreateBackend, | 1406 base::Bind( |
| 1440 weak_ptr_factory_.GetWeakPtr(), pending_callback))); | 1407 &CacheStorageCache::InitDidCreateBackend, |
| 1408 weak_ptr_factory_.GetWeakPtr(), |
| 1409 scheduler_->WrapCallbackToRunNext(base::Bind(&base::DoNothing))))); |
| 1441 } | 1410 } |
| 1442 | 1411 |
| 1443 void CacheStorageCache::InitDidCreateBackend( | 1412 void CacheStorageCache::InitDidCreateBackend( |
| 1444 const base::Closure& callback, | 1413 const base::Closure& callback, |
| 1445 CacheStorageError cache_create_error) { | 1414 CacheStorageError cache_create_error) { |
| 1446 if (cache_create_error != CACHE_STORAGE_OK) { | 1415 if (cache_create_error != CACHE_STORAGE_OK) { |
| 1447 InitGotCacheSize(callback, cache_create_error, 0); | 1416 InitGotCacheSize(callback, cache_create_error, 0); |
| 1448 return; | 1417 return; |
| 1449 } | 1418 } |
| 1450 | 1419 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1465 backend_state_ == BACKEND_UNINITIALIZED) | 1434 backend_state_ == BACKEND_UNINITIALIZED) |
| 1466 ? BACKEND_OPEN | 1435 ? BACKEND_OPEN |
| 1467 : BACKEND_CLOSED; | 1436 : BACKEND_CLOSED; |
| 1468 | 1437 |
| 1469 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", | 1438 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", |
| 1470 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1); | 1439 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1); |
| 1471 | 1440 |
| 1472 callback.Run(); | 1441 callback.Run(); |
| 1473 } | 1442 } |
| 1474 | 1443 |
| 1475 void CacheStorageCache::PendingClosure(const base::Closure& callback) { | |
| 1476 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | |
| 1477 | |
| 1478 callback.Run(); | |
| 1479 if (cache) | |
| 1480 scheduler_->CompleteOperationAndRunNext(); | |
| 1481 } | |
| 1482 | |
| 1483 void CacheStorageCache::PendingErrorCallback(const ErrorCallback& callback, | |
| 1484 CacheStorageError error) { | |
| 1485 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | |
| 1486 | |
| 1487 callback.Run(error); | |
| 1488 if (cache) | |
| 1489 scheduler_->CompleteOperationAndRunNext(); | |
| 1490 } | |
| 1491 | |
| 1492 void CacheStorageCache::PendingResponseCallback( | |
| 1493 const ResponseCallback& callback, | |
| 1494 CacheStorageError error, | |
| 1495 std::unique_ptr<ServiceWorkerResponse> response, | |
| 1496 std::unique_ptr<storage::BlobDataHandle> blob_data_handle) { | |
| 1497 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | |
| 1498 | |
| 1499 callback.Run(error, std::move(response), std::move(blob_data_handle)); | |
| 1500 if (cache) | |
| 1501 scheduler_->CompleteOperationAndRunNext(); | |
| 1502 } | |
| 1503 | |
| 1504 void CacheStorageCache::PendingResponsesCallback( | |
| 1505 const ResponsesCallback& callback, | |
| 1506 CacheStorageError error, | |
| 1507 std::unique_ptr<Responses> responses, | |
| 1508 std::unique_ptr<BlobDataHandles> blob_data_handles) { | |
| 1509 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | |
| 1510 | |
| 1511 callback.Run(error, std::move(responses), std::move(blob_data_handles)); | |
| 1512 if (cache) | |
| 1513 scheduler_->CompleteOperationAndRunNext(); | |
| 1514 } | |
| 1515 | |
| 1516 void CacheStorageCache::PendingRequestsCallback( | |
| 1517 const RequestsCallback& callback, | |
| 1518 CacheStorageError error, | |
| 1519 std::unique_ptr<Requests> requests) { | |
| 1520 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | |
| 1521 | |
| 1522 callback.Run(error, std::move(requests)); | |
| 1523 if (cache) | |
| 1524 scheduler_->CompleteOperationAndRunNext(); | |
| 1525 } | |
| 1526 | |
| 1527 void CacheStorageCache::PendingSizeCallback(const SizeCallback& callback, | |
| 1528 int64_t size) { | |
| 1529 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | |
| 1530 | |
| 1531 callback.Run(size); | |
| 1532 if (cache) | |
| 1533 scheduler_->CompleteOperationAndRunNext(); | |
| 1534 } | |
| 1535 | |
| 1536 void CacheStorageCache::PopulateResponseMetadata( | 1444 void CacheStorageCache::PopulateResponseMetadata( |
| 1537 const CacheMetadata& metadata, | 1445 const CacheMetadata& metadata, |
| 1538 ServiceWorkerResponse* response) { | 1446 ServiceWorkerResponse* response) { |
| 1539 *response = ServiceWorkerResponse( | 1447 *response = ServiceWorkerResponse( |
| 1540 GURL(metadata.response().url()), metadata.response().status_code(), | 1448 GURL(metadata.response().url()), metadata.response().status_code(), |
| 1541 metadata.response().status_text(), | 1449 metadata.response().status_text(), |
| 1542 ProtoResponseTypeToWebResponseType(metadata.response().response_type()), | 1450 ProtoResponseTypeToWebResponseType(metadata.response().response_type()), |
| 1543 ServiceWorkerHeaderMap(), "", 0, GURL(), | 1451 ServiceWorkerHeaderMap(), "", 0, GURL(), |
| 1544 blink::WebServiceWorkerResponseErrorUnknown, | 1452 blink::WebServiceWorkerResponseErrorUnknown, |
| 1545 base::Time::FromInternalValue(metadata.response().response_time()), | 1453 base::Time::FromInternalValue(metadata.response().response_time()), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1572 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); | 1480 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); |
| 1573 return blob_storage_context_->AddFinishedBlob(&blob_data); | 1481 return blob_storage_context_->AddFinishedBlob(&blob_data); |
| 1574 } | 1482 } |
| 1575 | 1483 |
| 1576 std::unique_ptr<CacheStorageCacheHandle> | 1484 std::unique_ptr<CacheStorageCacheHandle> |
| 1577 CacheStorageCache::CreateCacheHandle() { | 1485 CacheStorageCache::CreateCacheHandle() { |
| 1578 return cache_storage_->CreateCacheHandle(this); | 1486 return cache_storage_->CreateCacheHandle(this); |
| 1579 } | 1487 } |
| 1580 | 1488 |
| 1581 } // namespace content | 1489 } // namespace content |
| OLD | NEW |