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

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

Issue 1957663004: [CacheStorage] Prioritize Size operations over other scheduled operations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Merge conflict fix Created 4 years, 7 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 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 436 }
437 437
438 void CacheStorageCache::Size(const SizeCallback& callback) { 438 void CacheStorageCache::Size(const SizeCallback& callback) {
439 if (!LazyInitialize()) { 439 if (!LazyInitialize()) {
440 // TODO(jkarlin): Delete caches that can't be initialized. 440 // TODO(jkarlin): Delete caches that can't be initialized.
441 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 441 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
442 base::Bind(callback, 0)); 442 base::Bind(callback, 0));
443 return; 443 return;
444 } 444 }
445 445
446 // If the cache isn't already initialized, wait for it.
447 if (initializing_) { 446 if (initializing_) {
448 SizeCallback pending_callback = 447 // Note that Size doesn't use the scheduler, see header comments for why.
449 base::Bind(&CacheStorageCache::PendingSizeCallback, 448 pending_size_callbacks_.push_back(callback);
450 weak_ptr_factory_.GetWeakPtr(), callback);
451 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::SizeImpl,
452 weak_ptr_factory_.GetWeakPtr(),
453 pending_callback));
454 return; 449 return;
455 } 450 }
456 451
457 // Run immediately so that we don't deadlock on 452 // Run immediately so that we don't deadlock on
458 // CacheStorageCache::PutDidDelete's call to 453 // CacheStorageCache::PutDidDelete's call to
459 // quota_manager_proxy_->GetUsageAndQuota. 454 // quota_manager_proxy_->GetUsageAndQuota.
460 SizeImpl(callback); 455 SizeImpl(callback);
461 } 456 }
462 457
463 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) { 458 void CacheStorageCache::GetSizeThenClose(const SizeCallback& callback) {
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 1284
1290 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error, 1285 void CacheStorageCache::InitGotCacheSize(CacheStorageError cache_create_error,
1291 int cache_size) { 1286 int cache_size) {
1292 cache_size_ = cache_size; 1287 cache_size_ = cache_size;
1293 initializing_ = false; 1288 initializing_ = false;
1294 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ && 1289 backend_state_ = (cache_create_error == CACHE_STORAGE_OK && backend_ &&
1295 backend_state_ == BACKEND_UNINITIALIZED) 1290 backend_state_ == BACKEND_UNINITIALIZED)
1296 ? BACKEND_OPEN 1291 ? BACKEND_OPEN
1297 : BACKEND_CLOSED; 1292 : BACKEND_CLOSED;
1298 1293
1294 for (const SizeCallback& callback : pending_size_callbacks_)
1295 SizeImpl(callback);
1296 pending_size_callbacks_.clear();
1297
1299 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult", 1298 UMA_HISTOGRAM_ENUMERATION("ServiceWorkerCache.InitBackendResult",
1300 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1); 1299 cache_create_error, CACHE_STORAGE_ERROR_LAST + 1);
1301 1300
1302 scheduler_->CompleteOperationAndRunNext(); 1301 scheduler_->CompleteOperationAndRunNext();
1303 } 1302 }
1304 1303
1305 void CacheStorageCache::PendingClosure(const base::Closure& callback) { 1304 void CacheStorageCache::PendingClosure(const base::Closure& callback) {
1306 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr(); 1305 base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
1307 1306
1308 callback.Run(); 1307 callback.Run();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 storage::BlobDataBuilder blob_data(response->blob_uuid); 1391 storage::BlobDataBuilder blob_data(response->blob_uuid);
1393 1392
1394 disk_cache::Entry* temp_entry = entry.get(); 1393 disk_cache::Entry* temp_entry = entry.get();
1395 blob_data.AppendDiskCacheEntry( 1394 blob_data.AppendDiskCacheEntry(
1396 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, 1395 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry,
1397 INDEX_RESPONSE_BODY); 1396 INDEX_RESPONSE_BODY);
1398 return blob_storage_context_->AddFinishedBlob(&blob_data); 1397 return blob_storage_context_->AddFinishedBlob(&blob_data);
1399 } 1398 }
1400 1399
1401 } // namespace content 1400 } // 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