| 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 |
| 11 #include "base/barrier_closure.h" | 11 #include "base/barrier_closure.h" |
| 12 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/guid.h" | 14 #include "base/guid.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" |
| 15 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "content/browser/cache_storage/cache_storage.pb.h" | 21 #include "content/browser/cache_storage/cache_storage.pb.h" |
| 20 #include "content/browser/cache_storage/cache_storage_blob_to_disk_cache.h" | 22 #include "content/browser/cache_storage/cache_storage_blob_to_disk_cache.h" |
| 21 #include "content/browser/cache_storage/cache_storage_cache_handle.h" | 23 #include "content/browser/cache_storage/cache_storage_cache_handle.h" |
| 22 #include "content/browser/cache_storage/cache_storage_scheduler.h" | 24 #include "content/browser/cache_storage/cache_storage_scheduler.h" |
| 23 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/common/referrer.h" | 26 #include "content/public/common/referrer.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 }; | 284 }; |
| 283 | 285 |
| 284 // static | 286 // static |
| 285 std::unique_ptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache( | 287 std::unique_ptr<CacheStorageCache> CacheStorageCache::CreateMemoryCache( |
| 286 const GURL& origin, | 288 const GURL& origin, |
| 287 const std::string& cache_name, | 289 const std::string& cache_name, |
| 288 CacheStorage* cache_storage, | 290 CacheStorage* cache_storage, |
| 289 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 291 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 290 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 292 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 291 base::WeakPtr<storage::BlobStorageContext> blob_context) { | 293 base::WeakPtr<storage::BlobStorageContext> blob_context) { |
| 292 return std::unique_ptr<CacheStorageCache>( | 294 CacheStorageCache* cache = |
| 293 new CacheStorageCache(origin, cache_name, base::FilePath(), cache_storage, | 295 new CacheStorageCache(origin, cache_name, base::FilePath(), cache_storage, |
| 294 std::move(request_context_getter), | 296 std::move(request_context_getter), |
| 295 std::move(quota_manager_proxy), blob_context)); | 297 std::move(quota_manager_proxy), blob_context); |
| 298 cache->InitBackend(); |
| 299 return base::WrapUnique(cache); |
| 296 } | 300 } |
| 297 | 301 |
| 298 // static | 302 // static |
| 299 std::unique_ptr<CacheStorageCache> CacheStorageCache::CreatePersistentCache( | 303 std::unique_ptr<CacheStorageCache> CacheStorageCache::CreatePersistentCache( |
| 300 const GURL& origin, | 304 const GURL& origin, |
| 301 const std::string& cache_name, | 305 const std::string& cache_name, |
| 302 CacheStorage* cache_storage, | 306 CacheStorage* cache_storage, |
| 303 const base::FilePath& path, | 307 const base::FilePath& path, |
| 304 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 308 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 305 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, | 309 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy, |
| 306 base::WeakPtr<storage::BlobStorageContext> blob_context) { | 310 base::WeakPtr<storage::BlobStorageContext> blob_context) { |
| 307 return std::unique_ptr<CacheStorageCache>( | 311 CacheStorageCache* cache = |
| 308 new CacheStorageCache(origin, cache_name, path, cache_storage, | 312 new CacheStorageCache(origin, cache_name, path, cache_storage, |
| 309 std::move(request_context_getter), | 313 std::move(request_context_getter), |
| 310 std::move(quota_manager_proxy), blob_context)); | 314 std::move(quota_manager_proxy), blob_context); |
| 315 cache->InitBackend(); |
| 316 return base::WrapUnique(cache); |
| 311 } | 317 } |
| 312 | 318 |
| 313 base::WeakPtr<CacheStorageCache> CacheStorageCache::AsWeakPtr() { | 319 base::WeakPtr<CacheStorageCache> CacheStorageCache::AsWeakPtr() { |
| 314 return weak_ptr_factory_.GetWeakPtr(); | 320 return weak_ptr_factory_.GetWeakPtr(); |
| 315 } | 321 } |
| 316 | 322 |
| 317 void CacheStorageCache::Match( | 323 void CacheStorageCache::Match( |
| 318 std::unique_ptr<ServiceWorkerFetchRequest> request, | 324 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 319 const ResponseCallback& callback) { | 325 const ResponseCallback& callback) { |
| 320 if (!LazyInitialize()) { | 326 if (backend_state_ == BACKEND_CLOSED) { |
| 321 callback.Run(CACHE_STORAGE_ERROR_STORAGE, | 327 callback.Run(CACHE_STORAGE_ERROR_STORAGE, |
| 322 std::unique_ptr<ServiceWorkerResponse>(), | 328 std::unique_ptr<ServiceWorkerResponse>(), |
| 323 std::unique_ptr<storage::BlobDataHandle>()); | 329 std::unique_ptr<storage::BlobDataHandle>()); |
| 324 return; | 330 return; |
| 325 } | 331 } |
| 326 | 332 |
| 327 ResponseCallback pending_callback = | 333 ResponseCallback pending_callback = |
| 328 base::Bind(&CacheStorageCache::PendingResponseCallback, | 334 base::Bind(&CacheStorageCache::PendingResponseCallback, |
| 329 weak_ptr_factory_.GetWeakPtr(), callback); | 335 weak_ptr_factory_.GetWeakPtr(), callback); |
| 330 scheduler_->ScheduleOperation( | 336 scheduler_->ScheduleOperation( |
| 331 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), | 337 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), |
| 332 base::Passed(std::move(request)), pending_callback)); | 338 base::Passed(std::move(request)), pending_callback)); |
| 333 } | 339 } |
| 334 | 340 |
| 335 void CacheStorageCache::MatchAll( | 341 void CacheStorageCache::MatchAll( |
| 336 std::unique_ptr<ServiceWorkerFetchRequest> request, | 342 std::unique_ptr<ServiceWorkerFetchRequest> request, |
| 337 const CacheStorageCacheQueryParams& match_params, | 343 const CacheStorageCacheQueryParams& match_params, |
| 338 const ResponsesCallback& callback) { | 344 const ResponsesCallback& callback) { |
| 339 if (!LazyInitialize()) { | 345 if (backend_state_ == BACKEND_CLOSED) { |
| 340 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Responses>(), | 346 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Responses>(), |
| 341 std::unique_ptr<BlobDataHandles>()); | 347 std::unique_ptr<BlobDataHandles>()); |
| 342 return; | 348 return; |
| 343 } | 349 } |
| 344 | 350 |
| 345 ResponsesCallback pending_callback = | 351 ResponsesCallback pending_callback = |
| 346 base::Bind(&CacheStorageCache::PendingResponsesCallback, | 352 base::Bind(&CacheStorageCache::PendingResponsesCallback, |
| 347 weak_ptr_factory_.GetWeakPtr(), callback); | 353 weak_ptr_factory_.GetWeakPtr(), callback); |
| 348 | 354 |
| 349 std::unique_ptr<MatchAllContext> context( | 355 std::unique_ptr<MatchAllContext> context( |
| 350 new MatchAllContext(std::move(request), match_params, pending_callback)); | 356 new MatchAllContext(std::move(request), match_params, pending_callback)); |
| 351 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, | 357 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, |
| 352 weak_ptr_factory_.GetWeakPtr(), | 358 weak_ptr_factory_.GetWeakPtr(), |
| 353 base::Passed(std::move(context)))); | 359 base::Passed(std::move(context)))); |
| 354 } | 360 } |
| 355 | 361 |
| 356 void CacheStorageCache::WriteSideData(const ErrorCallback& callback, | 362 void CacheStorageCache::WriteSideData(const ErrorCallback& callback, |
| 357 const GURL& url, | 363 const GURL& url, |
| 358 base::Time expected_response_time, | 364 base::Time expected_response_time, |
| 359 scoped_refptr<net::IOBuffer> buffer, | 365 scoped_refptr<net::IOBuffer> buffer, |
| 360 int buf_len) { | 366 int buf_len) { |
| 361 if (!LazyInitialize()) { | 367 if (backend_state_ == BACKEND_CLOSED) { |
| 362 base::ThreadTaskRunnerHandle::Get()->PostTask( | 368 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 363 FROM_HERE, base::Bind(callback, CACHE_STORAGE_ERROR_STORAGE)); | 369 FROM_HERE, base::Bind(callback, CACHE_STORAGE_ERROR_STORAGE)); |
| 364 return; | 370 return; |
| 365 } | 371 } |
| 366 | 372 |
| 367 // GetUsageAndQuota is called before entering a scheduled operation since it | 373 // GetUsageAndQuota is called before entering a scheduled operation since it |
| 368 // can call Size, another scheduled operation. | 374 // can call Size, another scheduled operation. |
| 369 quota_manager_proxy_->GetUsageAndQuota( | 375 quota_manager_proxy_->GetUsageAndQuota( |
| 370 base::ThreadTaskRunnerHandle::Get().get(), origin_, | 376 base::ThreadTaskRunnerHandle::Get().get(), origin_, |
| 371 storage::kStorageTypeTemporary, | 377 storage::kStorageTypeTemporary, |
| 372 base::Bind(&CacheStorageCache::WriteSideDataDidGetQuota, | 378 base::Bind(&CacheStorageCache::WriteSideDataDidGetQuota, |
| 373 weak_ptr_factory_.GetWeakPtr(), callback, url, | 379 weak_ptr_factory_.GetWeakPtr(), callback, url, |
| 374 expected_response_time, buffer, buf_len)); | 380 expected_response_time, buffer, buf_len)); |
| 375 } | 381 } |
| 376 | 382 |
| 377 void CacheStorageCache::BatchOperation( | 383 void CacheStorageCache::BatchOperation( |
| 378 const std::vector<CacheStorageBatchOperation>& operations, | 384 const std::vector<CacheStorageBatchOperation>& operations, |
| 379 const ErrorCallback& callback) { | 385 const ErrorCallback& callback) { |
| 380 if (!LazyInitialize()) { | 386 if (backend_state_ == BACKEND_CLOSED) { |
| 381 base::ThreadTaskRunnerHandle::Get()->PostTask( | 387 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 382 FROM_HERE, base::Bind(callback, CACHE_STORAGE_ERROR_STORAGE)); | 388 FROM_HERE, base::Bind(callback, CACHE_STORAGE_ERROR_STORAGE)); |
| 383 return; | 389 return; |
| 384 } | 390 } |
| 385 | 391 |
| 386 // Estimate the required size of the put operations. The size of the deletes | 392 // Estimate the required size of the put operations. The size of the deletes |
| 387 // is unknown and not considered. | 393 // is unknown and not considered. |
| 388 int64_t space_required = 0; | 394 int64_t space_required = 0; |
| 389 for (const auto& operation : operations) { | 395 for (const auto& operation : operations) { |
| 390 if (operation.operation_type == CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT) { | 396 if (operation.operation_type == CACHE_STORAGE_CACHE_OPERATION_TYPE_PUT) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 } | 476 } |
| 471 | 477 |
| 472 void CacheStorageCache::BatchDidAllOperations( | 478 void CacheStorageCache::BatchDidAllOperations( |
| 473 std::unique_ptr<ErrorCallback> callback) { | 479 std::unique_ptr<ErrorCallback> callback) { |
| 474 if (callback->is_null()) | 480 if (callback->is_null()) |
| 475 return; | 481 return; |
| 476 callback->Run(CACHE_STORAGE_OK); | 482 callback->Run(CACHE_STORAGE_OK); |
| 477 } | 483 } |
| 478 | 484 |
| 479 void CacheStorageCache::Keys(const RequestsCallback& callback) { | 485 void CacheStorageCache::Keys(const RequestsCallback& callback) { |
| 480 if (!LazyInitialize()) { | 486 if (backend_state_ == BACKEND_CLOSED) { |
| 481 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>()); | 487 callback.Run(CACHE_STORAGE_ERROR_STORAGE, std::unique_ptr<Requests>()); |
| 482 return; | 488 return; |
| 483 } | 489 } |
| 484 | 490 |
| 485 RequestsCallback pending_callback = | 491 RequestsCallback pending_callback = |
| 486 base::Bind(&CacheStorageCache::PendingRequestsCallback, | 492 base::Bind(&CacheStorageCache::PendingRequestsCallback, |
| 487 weak_ptr_factory_.GetWeakPtr(), callback); | 493 weak_ptr_factory_.GetWeakPtr(), callback); |
| 488 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::KeysImpl, | 494 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::KeysImpl, |
| 489 weak_ptr_factory_.GetWeakPtr(), | 495 weak_ptr_factory_.GetWeakPtr(), |
| 490 pending_callback)); | 496 pending_callback)); |
| 491 } | 497 } |
| 492 | 498 |
| 493 void CacheStorageCache::Close(const base::Closure& callback) { | 499 void CacheStorageCache::Close(const base::Closure& callback) { |
| 494 DCHECK_NE(BACKEND_CLOSED, backend_state_) | 500 DCHECK_NE(BACKEND_CLOSED, backend_state_) |
| 495 << "Was CacheStorageCache::Close() called twice?"; | 501 << "Was CacheStorageCache::Close() called twice?"; |
| 496 | 502 |
| 497 base::Closure pending_callback = | 503 base::Closure pending_callback = |
| 498 base::Bind(&CacheStorageCache::PendingClosure, | 504 base::Bind(&CacheStorageCache::PendingClosure, |
| 499 weak_ptr_factory_.GetWeakPtr(), callback); | 505 weak_ptr_factory_.GetWeakPtr(), callback); |
| 500 | 506 |
| 501 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::CloseImpl, | 507 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::CloseImpl, |
| 502 weak_ptr_factory_.GetWeakPtr(), | 508 weak_ptr_factory_.GetWeakPtr(), |
| 503 pending_callback)); | 509 pending_callback)); |
| 504 } | 510 } |
| 505 | 511 |
| 506 void CacheStorageCache::Size(const SizeCallback& callback) { | 512 void CacheStorageCache::Size(const SizeCallback& callback) { |
| 507 if (!LazyInitialize()) { | 513 if (backend_state_ == BACKEND_CLOSED) { |
| 508 // TODO(jkarlin): Delete caches that can't be initialized. | 514 // TODO(jkarlin): Delete caches that can't be initialized. |
| 509 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 515 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 510 base::Bind(callback, 0)); | 516 base::Bind(callback, 0)); |
| 511 return; | 517 return; |
| 512 } | 518 } |
| 513 | 519 |
| 514 SizeCallback pending_callback = | 520 SizeCallback pending_callback = |
| 515 base::Bind(&CacheStorageCache::PendingSizeCallback, | 521 base::Bind(&CacheStorageCache::PendingSizeCallback, |
| 516 weak_ptr_factory_.GetWeakPtr(), callback); | 522 weak_ptr_factory_.GetWeakPtr(), callback); |
| 517 | 523 |
| 518 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::SizeImpl, | 524 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::SizeImpl, |
| 519 weak_ptr_factory_.GetWeakPtr(), | 525 weak_ptr_factory_.GetWeakPtr(), |
| 520 pending_callback)); | 526 pending_callback)); |
| 521 } | 527 } |
| 522 | 528 |
| 523 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) { | 529 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) { |
| 524 if (!LazyInitialize()) { | 530 if (backend_state_ == BACKEND_CLOSED) { |
| 525 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 531 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 526 base::Bind(callback, 0)); | 532 base::Bind(callback, 0)); |
| 527 return; | 533 return; |
| 528 } | 534 } |
| 529 | 535 |
| 530 SizeCallback pending_callback = | 536 SizeCallback pending_callback = |
| 531 base::Bind(&CacheStorageCache::PendingSizeCallback, | 537 base::Bind(&CacheStorageCache::PendingSizeCallback, |
| 532 weak_ptr_factory_.GetWeakPtr(), callback); | 538 weak_ptr_factory_.GetWeakPtr(), callback); |
| 533 | 539 |
| 534 scheduler_->ScheduleOperation( | 540 scheduler_->ScheduleOperation( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 558 blob_storage_context_(blob_context), | 564 blob_storage_context_(blob_context), |
| 559 scheduler_(new CacheStorageScheduler()), | 565 scheduler_(new CacheStorageScheduler()), |
| 560 memory_only_(path.empty()), | 566 memory_only_(path.empty()), |
| 561 weak_ptr_factory_(this) { | 567 weak_ptr_factory_(this) { |
| 562 DCHECK(!origin_.is_empty()); | 568 DCHECK(!origin_.is_empty()); |
| 563 DCHECK(quota_manager_proxy_.get()); | 569 DCHECK(quota_manager_proxy_.get()); |
| 564 | 570 |
| 565 quota_manager_proxy_->NotifyOriginInUse(origin_); | 571 quota_manager_proxy_->NotifyOriginInUse(origin_); |
| 566 } | 572 } |
| 567 | 573 |
| 568 bool CacheStorageCache::LazyInitialize() { | |
| 569 switch (backend_state_) { | |
| 570 case BACKEND_UNINITIALIZED: | |
| 571 InitBackend(); | |
| 572 return true; | |
| 573 case BACKEND_CLOSED: | |
| 574 return false; | |
| 575 case BACKEND_OPEN: | |
| 576 DCHECK(backend_); | |
| 577 return true; | |
| 578 } | |
| 579 NOTREACHED(); | |
| 580 return false; | |
| 581 } | |
| 582 | |
| 583 void CacheStorageCache::OpenAllEntries(const OpenAllEntriesCallback& callback) { | 574 void CacheStorageCache::OpenAllEntries(const OpenAllEntriesCallback& callback) { |
| 584 std::unique_ptr<OpenAllEntriesContext> entries_context( | 575 std::unique_ptr<OpenAllEntriesContext> entries_context( |
| 585 new OpenAllEntriesContext); | 576 new OpenAllEntriesContext); |
| 586 entries_context->backend_iterator = backend_->CreateIterator(); | 577 entries_context->backend_iterator = backend_->CreateIterator(); |
| 587 disk_cache::Backend::Iterator& iterator = *entries_context->backend_iterator; | 578 disk_cache::Backend::Iterator& iterator = *entries_context->backend_iterator; |
| 588 disk_cache::Entry** enumerated_entry = &entries_context->enumerated_entry; | 579 disk_cache::Entry** enumerated_entry = &entries_context->enumerated_entry; |
| 589 | 580 |
| 590 net::CompletionCallback open_entry_callback = base::Bind( | 581 net::CompletionCallback open_entry_callback = base::Bind( |
| 591 &CacheStorageCache::DidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(), | 582 &CacheStorageCache::DidOpenNextEntry, weak_ptr_factory_.GetWeakPtr(), |
| 592 base::Passed(std::move(entries_context)), callback); | 583 base::Passed(std::move(entries_context)), callback); |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 1419 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
| 1429 return; | 1420 return; |
| 1430 } | 1421 } |
| 1431 | 1422 |
| 1432 backend_ = std::move(*backend_ptr); | 1423 backend_ = std::move(*backend_ptr); |
| 1433 callback.Run(CACHE_STORAGE_OK); | 1424 callback.Run(CACHE_STORAGE_OK); |
| 1434 } | 1425 } |
| 1435 | 1426 |
| 1436 void CacheStorageCache::InitBackend() { | 1427 void CacheStorageCache::InitBackend() { |
| 1437 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_); | 1428 DCHECK_EQ(BACKEND_UNINITIALIZED, backend_state_); |
| 1438 | 1429 DCHECK(!initializing_); |
| 1439 if (initializing_) | |
| 1440 return; | |
| 1441 | |
| 1442 DCHECK(!scheduler_->ScheduledOperations()); | 1430 DCHECK(!scheduler_->ScheduledOperations()); |
| 1443 initializing_ = true; | 1431 initializing_ = true; |
| 1444 | 1432 |
| 1433 base::Closure pending_callback = |
| 1434 base::Bind(&CacheStorageCache::PendingClosure, |
| 1435 weak_ptr_factory_.GetWeakPtr(), base::Bind(&base::DoNothing)); |
| 1436 |
| 1445 scheduler_->ScheduleOperation(base::Bind( | 1437 scheduler_->ScheduleOperation(base::Bind( |
| 1446 &CacheStorageCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(), | 1438 &CacheStorageCache::CreateBackend, weak_ptr_factory_.GetWeakPtr(), |
| 1447 base::Bind(&CacheStorageCache::InitDidCreateBackend, | 1439 base::Bind(&CacheStorageCache::InitDidCreateBackend, |
| 1448 weak_ptr_factory_.GetWeakPtr()))); | 1440 weak_ptr_factory_.GetWeakPtr(), pending_callback))); |
| 1449 } | 1441 } |
| 1450 | 1442 |
| 1451 void CacheStorageCache::InitDidCreateBackend( | 1443 void CacheStorageCache::InitDidCreateBackend( |
| 1444 const base::Closure& callback, |
| 1452 CacheStorageError cache_create_error) { | 1445 CacheStorageError cache_create_error) { |
| 1453 if (cache_create_error != CACHE_STORAGE_OK) { | 1446 if (cache_create_error != CACHE_STORAGE_OK) { |
| 1454 InitGotCacheSize(cache_create_error, 0); | 1447 InitGotCacheSize(callback, cache_create_error, 0); |
| 1455 return; | 1448 return; |
| 1456 } | 1449 } |
| 1457 | 1450 |
| 1458 int rv = backend_->CalculateSizeOfAllEntries( | 1451 int rv = backend_->CalculateSizeOfAllEntries( |
| 1459 base::Bind(&CacheStorageCache::InitGotCacheSize, | 1452 base::Bind(&CacheStorageCache::InitGotCacheSize, |
| 1460 weak_ptr_factory_.GetWeakPtr(), cache_create_error)); | 1453 weak_ptr_factory_.GetWeakPtr(), callback, cache_create_error)); |
| 1461 | 1454 |
| 1462 if (rv != net::ERR_IO_PENDING) | 1455 if (rv != net::ERR_IO_PENDING) |
| 1463 InitGotCacheSize(cache_create_error, rv); | 1456 InitGotCacheSize(callback, cache_create_error, rv); |
| 1464 } | 1457 } |
| 1465 | 1458 |
| 1466 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error, | 1459 void CacheStorageCache::InitGotCacheSize(const base::Closure& callback, |
| 1460 CacheStorageError cache_create_error, |
| 1467 int cache_size) { | 1461 int cache_size) { |
| 1468 cache_size_ = cache_size; | 1462 cache_size_ = cache_size; |
| 1469 initializing_ = false; | 1463 initializing_ = false; |
| 1470 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ && | 1464 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ && |
| 1471 backend_state_ == BACKEND_UNINITIALIZED) | 1465 backend_state_ == BACKEND_UNINITIALIZED) |
| 1472 ? BACKEND_OPEN | 1466 ? BACKEND_OPEN |
| 1473 : BACKEND_CLOSED; | 1467 : BACKEND_CLOSED; |
| 1474 | 1468 |
| 1475 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", | 1469 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", |
| 1476 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1); | 1470 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1); |
| 1477 | 1471 |
| 1478 scheduler_->CompleteOperationAndRunNext(); | 1472 callback.Run(); |
| 1479 } | 1473 } |
| 1480 | 1474 |
| 1481 void CacheStorageCache::PendingClosure(const base::Closure& callback) { | 1475 void CacheStorageCache::PendingClosure(const base::Closure& callback) { |
| 1482 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); | 1476 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); |
| 1483 | 1477 |
| 1484 callback.Run(); | 1478 callback.Run(); |
| 1485 if (cache) | 1479 if (cache) |
| 1486 scheduler_->CompleteOperationAndRunNext(); | 1480 scheduler_->CompleteOperationAndRunNext(); |
| 1487 } | 1481 } |
| 1488 | 1482 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); | 1572 temp_entry, INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); |
| 1579 return blob_storage_context_->AddFinishedBlob(&blob_data); | 1573 return blob_storage_context_->AddFinishedBlob(&blob_data); |
| 1580 } | 1574 } |
| 1581 | 1575 |
| 1582 std::unique_ptr<CacheStorageCacheHandle> | 1576 std::unique_ptr<CacheStorageCacheHandle> |
| 1583 CacheStorageCache::CreateCacheHandle() { | 1577 CacheStorageCache::CreateCacheHandle() { |
| 1584 return cache_storage_->CreateCacheHandle(this); | 1578 return cache_storage_->CreateCacheHandle(this); |
| 1585 } | 1579 } |
| 1586 | 1580 |
| 1587 } // namespace content | 1581 } // namespace content |
| OLD | NEW |