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

Side by Side Diff: content/browser/cache_storage/cache_storage_cache.cc

Issue 1916473002: [CacheStorage] Prioritize Size operations over other scheduled operations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 456 }
457 457
458 void CacheStorageCache::Size(const SizeCallback& callback) { 458 void CacheStorageCache::Size(const SizeCallback& callback) {
459 if (!LazyInitialize()) { 459 if (!LazyInitialize()) {
460 // TODO(jkarlin): Delete caches that can't be initialized. 460 // TODO(jkarlin): Delete caches that can't be initialized.
461 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 461 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
462 base::Bind(callback, 0)); 462 base::Bind(callback, 0));
463 return; 463 return;
464 } 464 }
465 465
466 // If the cache isn't already initialized, wait for it.
467 if (initializing_) { 466 if (initializing_) {
468 SizeCallback pending_callback = 467 // Note that Size doesn't use the scheduler, see header comments for why.
469 base::Bind(&CacheStorageCache::PendingSizeCallback, 468 pending_size_callbacks_.push_back(callback);
470 weak_ptr_factory_.GetWeakPtr(), callback);
471 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::SizeImpl,
472 weak_ptr_factory_.GetWeakPtr(),
473 pending_callback));
474 return; 469 return;
475 } 470 }
476 471
477 // Run immediately so that we don't deadlock on 472 // Run immediately so that we don't deadlock on
478 // CacheStorageCache::PutDidDelete's call to 473 // CacheStorageCache::PutDidDelete's call to
479 // quota_manager_proxy_->GetUsageAndQuota. 474 // quota_manager_proxy_->GetUsageAndQuota.
480 SizeImpl(callback); 475 SizeImpl(callback);
481 } 476 }
482 477
483 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) { 478 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) {
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
1434 1429
1435 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error, 1430 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error,
1436 int cache_size) { 1431 int cache_size) {
1437 cache_size_ = cache_size; 1432 cache_size_ = cache_size;
1438 initializing_ = false; 1433 initializing_ = false;
1439 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ && 1434 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ &&
1440 backend_state_ == BACKEND_UNINITIALIZED) 1435 backend_state_ == BACKEND_UNINITIALIZED)
1441 ? BACKEND_OPEN 1436 ? BACKEND_OPEN
1442 : BACKEND_CLOSED; 1437 : BACKEND_CLOSED;
1443 1438
1439 for (const SizeCallback& callback : pending_size_callbacks_)
1440 SizeImpl(callback);
1441 pending_size_callbacks_.clear();
1442
1444 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", 1443 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult",
1445 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1); 1444 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1);
1446 1445
1447 scheduler_->CompleteOperationAndRunNext(); 1446 scheduler_->CompleteOperationAndRunNext();
1448 } 1447 }
1449 1448
1450 void CacheStorageCache::PendingClosure(const base::Closure& callback) { 1449 void CacheStorageCache::PendingClosure(const base::Closure& callback) {
1451 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); 1450 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1452 1451
1453 callback.Run(); 1452 callback.Run();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 storage::BlobDataBuilder blob_data(response->blob_uuid); 1538 storage::BlobDataBuilder blob_data(response->blob_uuid);
1540 1539
1541 disk_cache::Entry* temp_entry = entry.get(); 1540 disk_cache::Entry* temp_entry = entry.get();
1542 blob_data.AppendDiskCacheEntryWithSideData( 1541 blob_data.AppendDiskCacheEntryWithSideData(
1543 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, 1542 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry,
1544 INDEX_RESPONSE_BODY, INDEX_SIDE_DATA); 1543 INDEX_RESPONSE_BODY, INDEX_SIDE_DATA);
1545 return blob_storage_context_->AddFinishedBlob(&blob_data); 1544 return blob_storage_context_->AddFinishedBlob(&blob_data);
1546 } 1545 }
1547 1546
1548 } // namespace content 1547 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/cache_storage/cache_storage_cache.h ('k') | content/browser/cache_storage/cache_storage_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698