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

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

Issue 17507006: Disk cache v3 ref2 Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Incl IndexTable cl Created 7 years, 1 month 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/disk_cache/addr.cc ('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_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // the id cannot be zero, because that value is used as "not dirty". 277 // the id cannot be zero, because that value is used as "not dirty".
278 // Increasing the value once per second gives us many years before we start 278 // Increasing the value once per second gives us many years before we start
279 // having collisions. 279 // having collisions.
280 data_->header.this_id++; 280 data_->header.this_id++;
281 if (!data_->header.this_id) 281 if (!data_->header.this_id)
282 data_->header.this_id++; 282 data_->header.this_id++;
283 283
284 bool previous_crash = (data_->header.crash != 0); 284 bool previous_crash = (data_->header.crash != 0);
285 data_->header.crash = 1; 285 data_->header.crash = 1;
286 286
287 if (!block_files_.Init(create_files)) 287 if (!block_files_.Init(create_files, kFirstAdditionalBlockFile))
288 return net::ERR_FAILED; 288 return net::ERR_FAILED;
289 289
290 // We want to minimize the changes to cache for an AppCache. 290 // We want to minimize the changes to cache for an AppCache.
291 if (cache_type() == net::APP_CACHE) { 291 if (cache_type() == net::APP_CACHE) {
292 DCHECK(!new_eviction_); 292 DCHECK(!new_eviction_);
293 read_only_ = true; 293 read_only_ = true;
294 } else if (cache_type() == net::SHADER_CACHE) { 294 } else if (cache_type() == net::SHADER_CACHE) {
295 DCHECK(!new_eviction_); 295 DCHECK(!new_eviction_);
296 } 296 }
297 297
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 LOG(ERROR) << "Number of entries mismatch"; 1137 LOG(ERROR) << "Number of entries mismatch";
1138 #if !defined(NET_BUILD_STRESS_CACHE) 1138 #if !defined(NET_BUILD_STRESS_CACHE)
1139 return ERR_NUM_ENTRIES_MISMATCH; 1139 return ERR_NUM_ENTRIES_MISMATCH;
1140 #endif 1140 #endif
1141 } 1141 }
1142 1142
1143 return CheckAllEntries(); 1143 return CheckAllEntries();
1144 } 1144 }
1145 1145
1146 void BackendImpl::FlushIndex() { 1146 void BackendImpl::FlushIndex() {
1147 if (index_.get() && !disabled_) 1147 if (index_ && !disabled_)
1148 index_->Flush(); 1148 index_->Flush();
1149 } 1149 }
1150 1150
1151 // ------------------------------------------------------------------------ 1151 // ------------------------------------------------------------------------
1152 1152
1153 net::CacheType BackendImpl::GetCacheType() const { 1153 net::CacheType BackendImpl::GetCacheType() const {
1154 return cache_type_; 1154 return cache_type_;
1155 } 1155 }
1156 1156
1157 int32 BackendImpl::GetEntryCount() const { 1157 int32 BackendImpl::GetEntryCount() const {
1158 if (!index_.get() || disabled_) 1158 if (!index_ || disabled_)
1159 return 0; 1159 return 0;
1160 // num_entries includes entries already evicted. 1160 // num_entries includes entries already evicted.
1161 int32 not_deleted = data_->header.num_entries - 1161 int32 not_deleted = data_->header.num_entries -
1162 data_->header.lru.sizes[Rankings::DELETED]; 1162 data_->header.lru.sizes[Rankings::DELETED];
1163 1163
1164 if (not_deleted < 0) { 1164 if (not_deleted < 0) {
1165 NOTREACHED(); 1165 NOTREACHED();
1166 not_deleted = 0; 1166 not_deleted = 0;
1167 } 1167 }
1168 1168
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
1567 int error = NewEntry(address, &tmp); 1567 int error = NewEntry(address, &tmp);
1568 cache_entry.swap(&tmp); 1568 cache_entry.swap(&tmp);
1569 1569
1570 if (error || cache_entry->dirty()) { 1570 if (error || cache_entry->dirty()) {
1571 // This entry is dirty on disk (it was not properly closed): we cannot 1571 // This entry is dirty on disk (it was not properly closed): we cannot
1572 // trust it. 1572 // trust it.
1573 Addr child(0); 1573 Addr child(0);
1574 if (!error) 1574 if (!error)
1575 child.set_value(cache_entry->GetNextAddress()); 1575 child.set_value(cache_entry->GetNextAddress());
1576 1576
1577 if (parent_entry.get()) { 1577 if (parent_entry) {
1578 parent_entry->SetNextAddress(child); 1578 parent_entry->SetNextAddress(child);
1579 parent_entry = NULL; 1579 parent_entry = NULL;
1580 } else { 1580 } else {
1581 data_->table[hash & mask_] = child.value(); 1581 data_->table[hash & mask_] = child.value();
1582 } 1582 }
1583 1583
1584 Trace("MatchEntry dirty %d 0x%x 0x%x", find_parent, entry_addr.value(), 1584 Trace("MatchEntry dirty %d 0x%x 0x%x", find_parent, entry_addr.value(),
1585 address.value()); 1585 address.value());
1586 1586
1587 if (!error) { 1587 if (!error) {
(...skipping 20 matching lines...) Expand all
1608 Trace("Entry not on the index 0x%x", address.value()); 1608 Trace("Entry not on the index 0x%x", address.value());
1609 *match_error = true; 1609 *match_error = true;
1610 parent_entry = NULL; 1610 parent_entry = NULL;
1611 } 1611 }
1612 break; 1612 break;
1613 } 1613 }
1614 if (!cache_entry->Update()) 1614 if (!cache_entry->Update())
1615 cache_entry = NULL; 1615 cache_entry = NULL;
1616 parent_entry = cache_entry; 1616 parent_entry = cache_entry;
1617 cache_entry = NULL; 1617 cache_entry = NULL;
1618 if (!parent_entry.get()) 1618 if (!parent_entry)
1619 break; 1619 break;
1620 1620
1621 address.set_value(parent_entry->GetNextAddress()); 1621 address.set_value(parent_entry->GetNextAddress());
1622 } 1622 }
1623 1623
1624 if (parent_entry.get() && (!find_parent || !found)) 1624 if (parent_entry && (!find_parent || !found))
1625 parent_entry = NULL; 1625 parent_entry = NULL;
1626 1626
1627 if (find_parent && entry_addr.is_initialized() && !cache_entry.get()) { 1627 if (find_parent && entry_addr.is_initialized() && !cache_entry) {
1628 *match_error = true; 1628 *match_error = true;
1629 parent_entry = NULL; 1629 parent_entry = NULL;
1630 } 1630 }
1631 1631
1632 if (cache_entry.get() && (find_parent || !found)) 1632 if (cache_entry && (find_parent || !found))
1633 cache_entry = NULL; 1633 cache_entry = NULL;
1634 1634
1635 find_parent ? parent_entry.swap(&tmp) : cache_entry.swap(&tmp); 1635 find_parent ? parent_entry.swap(&tmp) : cache_entry.swap(&tmp);
1636 FlushIndex(); 1636 FlushIndex();
1637 return tmp; 1637 return tmp;
1638 } 1638 }
1639 1639
1640 // This is the actual implementation for OpenNextEntry and OpenPrevEntry. 1640 // This is the actual implementation for OpenNextEntry and OpenPrevEntry.
1641 EntryImpl* BackendImpl::OpenFollowingEntry(bool forward, void** iter) { 1641 EntryImpl* BackendImpl::OpenFollowingEntry(bool forward, void** iter) {
1642 if (disabled_) 1642 if (disabled_)
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 if (total_memory > kMaxBuffersSize || total_memory <= 0) 2112 if (total_memory > kMaxBuffersSize || total_memory <= 0)
2113 total_memory = kMaxBuffersSize; 2113 total_memory = kMaxBuffersSize;
2114 2114
2115 done = true; 2115 done = true;
2116 } 2116 }
2117 2117
2118 return static_cast<int>(total_memory); 2118 return static_cast<int>(total_memory);
2119 } 2119 }
2120 2120
2121 } // namespace disk_cache 2121 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/addr.cc ('k') | net/disk_cache/backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698