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

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

Issue 149306: Disk cache: Add explicit support for eviction / deletion... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 5 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/disk_cache/entry_impl.h ('k') | net/disk_cache/entry_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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/entry_impl.h" 5 #include "net/disk_cache/entry_impl.h"
6 6
7 #include "base/histogram.h" 7 #include "base/histogram.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 if (!node_.Data()->dirty) { 446 if (!node_.Data()->dirty) {
447 node_.Data()->dirty = backend_->GetCurrentEntryId(); 447 node_.Data()->dirty = backend_->GetCurrentEntryId();
448 node_.Store(); 448 node_.Store();
449 } 449 }
450 doomed_ = true; 450 doomed_ = true;
451 } 451 }
452 452
453 void EntryImpl::DeleteEntryData(bool everything) { 453 void EntryImpl::DeleteEntryData(bool everything) {
454 DCHECK(doomed_ || !everything); 454 DCHECK(doomed_ || !everything);
455 455
456 if (GetEntryFlags() & PARENT_ENTRY) {
457 // We have some child entries that must go away.
458 SparseControl::DeleteChildren(this);
459 }
460
456 if (GetDataSize(0)) 461 if (GetDataSize(0))
457 CACHE_UMA(COUNTS, "DeleteHeader", 0, GetDataSize(0)); 462 CACHE_UMA(COUNTS, "DeleteHeader", 0, GetDataSize(0));
458 if (GetDataSize(1)) 463 if (GetDataSize(1))
459 CACHE_UMA(COUNTS, "DeleteData", 0, GetDataSize(1)); 464 CACHE_UMA(COUNTS, "DeleteData", 0, GetDataSize(1));
460 for (int index = 0; index < kNumStreams; index++) { 465 for (int index = 0; index < kNumStreams; index++) {
461 Addr address(entry_.Data()->data_addr[index]); 466 Addr address(entry_.Data()->data_addr[index]);
462 if (address.is_initialized()) { 467 if (address.is_initialized()) {
463 DeleteData(address, index); 468 DeleteData(address, index);
464 backend_->ModifyStorageSize(entry_.Data()->data_size[index] - 469 backend_->ModifyStorageSize(entry_.Data()->data_size[index] -
465 unreported_size_[index], 0); 470 unreported_size_[index], 0);
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 if (sparse_.get()) 832 if (sparse_.get())
828 return net::OK; 833 return net::OK;
829 834
830 sparse_.reset(new SparseControl(this)); 835 sparse_.reset(new SparseControl(this));
831 int result = sparse_->Init(); 836 int result = sparse_->Init();
832 if (net::OK != result) 837 if (net::OK != result)
833 sparse_.reset(); 838 sparse_.reset();
834 return result; 839 return result;
835 } 840 }
836 841
842 void EntryImpl::SetEntryFlags(uint32 flags) {
843 entry_.Data()->flags |= flags;
844 entry_.set_modified();
845 }
846
847 uint32 EntryImpl::GetEntryFlags() {
848 return entry_.Data()->flags;
849 }
850
851 void EntryImpl::GetData(int index, char** buffer, Addr* address) {
852 if (user_buffers_[index].get()) {
853 // The data is already in memory, just copy it an we're done.
854 int data_len = entry_.Data()->data_size[index];
855 DCHECK(data_len <= kMaxBlockSize);
856 *buffer = new char[data_len];
857 memcpy(*buffer, user_buffers_[index].get(), data_len);
858 return;
859 }
860
861 // Bad news: we'd have to read the info from disk so instead we'll just tell
862 // the caller where to read from.
863 *buffer = NULL;
864 address->set_value(entry_.Data()->data_addr[index]);
865 if (address->is_initialized()) {
866 // Prevent us from deleting the block from the backing store.
867 backend_->ModifyStorageSize(entry_.Data()->data_size[index] -
868 unreported_size_[index], 0);
869 entry_.Data()->data_addr[index] = 0;
870 entry_.Data()->data_size[index] = 0;
871 }
872 }
873
837 void EntryImpl::ReportIOTime(Operation op, const base::Time& start) { 874 void EntryImpl::ReportIOTime(Operation op, const base::Time& start) {
838 int group = backend_->GetSizeGroup(); 875 int group = backend_->GetSizeGroup();
839 switch (op) { 876 switch (op) {
840 case kRead: 877 case kRead:
841 CACHE_UMA(AGE_MS, "ReadTime", group, start); 878 CACHE_UMA(AGE_MS, "ReadTime", group, start);
842 break; 879 break;
843 case kWrite: 880 case kWrite:
844 CACHE_UMA(AGE_MS, "WriteTime", group, start); 881 CACHE_UMA(AGE_MS, "WriteTime", group, start);
845 break; 882 break;
846 case kSparseRead: 883 case kSparseRead:
(...skipping 18 matching lines...) Expand all
865 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), 902 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this),
866 entry_.address().value(), node_.address().value()); 903 entry_.address().value(), node_.address().value());
867 904
868 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], 905 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0],
869 entry_.Data()->data_addr[1], entry_.Data()->long_key); 906 entry_.Data()->data_addr[1], entry_.Data()->long_key);
870 907
871 Trace(" doomed: %d 0x%p 0x%x", doomed_, pointer, dirty); 908 Trace(" doomed: %d 0x%p 0x%x", doomed_, pointer, dirty);
872 } 909 }
873 910
874 } // namespace disk_cache 911 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/entry_impl.h ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698