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

Side by Side Diff: net/disk_cache/backend_impl.cc

Issue 12224017: Create a new disk_cache type, SHADER_CACHE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better fix for OnExternalCacheHit Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « net/base/cache_type.h ('k') | net/disk_cache/backend_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/disk_cache/backend_impl.h" 5 #include "net/disk_cache/backend_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 bool previous_crash = (data_->header.crash != 0); 471 bool previous_crash = (data_->header.crash != 0);
472 data_->header.crash = 1; 472 data_->header.crash = 1;
473 473
474 if (!block_files_.Init(create_files)) 474 if (!block_files_.Init(create_files))
475 return net::ERR_FAILED; 475 return net::ERR_FAILED;
476 476
477 // We want to minimize the changes to cache for an AppCache. 477 // We want to minimize the changes to cache for an AppCache.
478 if (cache_type() == net::APP_CACHE) { 478 if (cache_type() == net::APP_CACHE) {
479 DCHECK(!new_eviction_); 479 DCHECK(!new_eviction_);
480 read_only_ = true; 480 read_only_ = true;
481 } else if (cache_type() == net::SHADER_CACHE) {
482 DCHECK(!new_eviction_);
481 } 483 }
482 484
483 eviction_.Init(this); 485 eviction_.Init(this);
484 486
485 // stats_ and rankings_ may end up calling back to us so we better be enabled. 487 // stats_ and rankings_ may end up calling back to us so we better be enabled.
486 disabled_ = false; 488 disabled_ = false;
487 if (!stats_.Init(this, &data_->header.stats)) 489 if (!stats_.Init(this, &data_->header.stats))
488 return net::ERR_FAILED; 490 return net::ERR_FAILED;
489 491
490 disabled_ = !rankings_.Init(this, new_eviction_); 492 disabled_ = !rankings_.Init(this, new_eviction_);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 665
664 void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { 666 void BackendImpl::SyncOnExternalCacheHit(const std::string& key) {
665 if (disabled_) 667 if (disabled_)
666 return; 668 return;
667 669
668 uint32 hash = base::Hash(key); 670 uint32 hash = base::Hash(key);
669 bool error; 671 bool error;
670 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); 672 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error);
671 if (cache_entry) { 673 if (cache_entry) {
672 if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) { 674 if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) {
673 UpdateRank(cache_entry, false); 675 UpdateRank(cache_entry, cache_type() == net::SHADER_CACHE);
674 } 676 }
675 cache_entry->Release(); 677 cache_entry->Release();
676 } 678 }
677 } 679 }
678 680
679 EntryImpl* BackendImpl::OpenEntryImpl(const std::string& key) { 681 EntryImpl* BackendImpl::OpenEntryImpl(const std::string& key) {
680 if (disabled_) 682 if (disabled_)
681 return NULL; 683 return NULL;
682 684
683 TimeTicks start = TimeTicks::Now(); 685 TimeTicks start = TimeTicks::Now();
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 917
916 void BackendImpl::DeleteBlock(Addr block_address, bool deep) { 918 void BackendImpl::DeleteBlock(Addr block_address, bool deep) {
917 block_files_.DeleteBlock(block_address, deep); 919 block_files_.DeleteBlock(block_address, deep);
918 } 920 }
919 921
920 LruData* BackendImpl::GetLruData() { 922 LruData* BackendImpl::GetLruData() {
921 return &data_->header.lru; 923 return &data_->header.lru;
922 } 924 }
923 925
924 void BackendImpl::UpdateRank(EntryImpl* entry, bool modified) { 926 void BackendImpl::UpdateRank(EntryImpl* entry, bool modified) {
925 if (!read_only_) { 927 if (read_only_ || (!modified && cache_type() == net::SHADER_CACHE))
926 eviction_.UpdateRank(entry, modified); 928 return;
927 } 929 eviction_.UpdateRank(entry, modified);
928 } 930 }
929 931
930 void BackendImpl::RecoveredEntry(CacheRankingsBlock* rankings) { 932 void BackendImpl::RecoveredEntry(CacheRankingsBlock* rankings) {
931 Addr address(rankings->Data()->contents); 933 Addr address(rankings->Data()->contents);
932 EntryImpl* cache_entry = NULL; 934 EntryImpl* cache_entry = NULL;
933 if (NewEntry(address, &cache_entry)) { 935 if (NewEntry(address, &cache_entry)) {
934 STRESS_NOTREACHED(); 936 STRESS_NOTREACHED();
935 return; 937 return;
936 } 938 }
937 939
(...skipping 1301 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2241 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2240 total_memory = kMaxBuffersSize; 2242 total_memory = kMaxBuffersSize;
2241 2243
2242 done = true; 2244 done = true;
2243 } 2245 }
2244 2246
2245 return static_cast<int>(total_memory); 2247 return static_cast<int>(total_memory);
2246 } 2248 }
2247 2249
2248 } // namespace disk_cache 2250 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/base/cache_type.h ('k') | net/disk_cache/backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698