OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 // When an entry is deleted from the cache, we clean up all the data associated | 87 // When an entry is deleted from the cache, we clean up all the data associated |
88 // with it for two reasons: to simplify the reuse of the block (we know that any | 88 // with it for two reasons: to simplify the reuse of the block (we know that any |
89 // unused block is filled with zeros), and to simplify the handling of write / | 89 // unused block is filled with zeros), and to simplify the handling of write / |
90 // read partial information from an entry (don't have to worry about returning | 90 // read partial information from an entry (don't have to worry about returning |
91 // data related to a previous cache entry because the range was not fully | 91 // data related to a previous cache entry because the range was not fully |
92 // written before). | 92 // written before). |
93 EntryImpl::~EntryImpl() { | 93 EntryImpl::~EntryImpl() { |
94 if (doomed_) { | 94 if (doomed_) { |
95 UMA_HISTOGRAM_COUNTS("DiskCache.DeleteHeader", GetDataSize(0)); | 95 DeleteEntryData(true); |
96 UMA_HISTOGRAM_COUNTS("DiskCache.DeleteData", GetDataSize(1)); | |
97 for (int index = 0; index < NUM_STREAMS; index++) { | |
98 Addr address(entry_.Data()->data_addr[index]); | |
99 if (address.is_initialized()) { | |
100 DeleteData(address, index); | |
101 backend_->ModifyStorageSize(entry_.Data()->data_size[index] - | |
102 unreported_size_[index], 0); | |
103 } | |
104 } | |
105 Addr address(entry_.Data()->long_key); | |
106 DeleteData(address, kKeyFileIndex); | |
107 backend_->ModifyStorageSize(entry_.Data()->key_len, 0); | |
108 | |
109 memset(node_.buffer(), 0, node_.size()); | |
110 memset(entry_.buffer(), 0, entry_.size()); | |
111 node_.Store(); | |
112 entry_.Store(); | |
113 | |
114 backend_->DeleteBlock(node_.address(), false); | |
115 backend_->DeleteBlock(entry_.address(), false); | |
116 } else { | 96 } else { |
117 bool ret = true; | 97 bool ret = true; |
118 for (int index = 0; index < NUM_STREAMS; index++) { | 98 for (int index = 0; index < NUM_STREAMS; index++) { |
119 if (user_buffers_[index].get()) { | 99 if (user_buffers_[index].get()) { |
120 if (!(ret = Flush(index, entry_.Data()->data_size[index], false))) | 100 if (!(ret = Flush(index, entry_.Data()->data_size[index], false))) |
121 LOG(ERROR) << "Failed to save user data"; | 101 LOG(ERROR) << "Failed to save user data"; |
122 } else if (unreported_size_[index]) { | 102 } else if (unreported_size_[index]) { |
123 backend_->ModifyStorageSize( | 103 backend_->ModifyStorageSize( |
124 entry_.Data()->data_size[index] - unreported_size_[index], | 104 entry_.Data()->data_size[index] - unreported_size_[index], |
125 entry_.Data()->data_size[index]); | 105 entry_.Data()->data_size[index]); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 | 447 |
468 void EntryImpl::InternalDoom() { | 448 void EntryImpl::InternalDoom() { |
469 DCHECK(node_.HasData()); | 449 DCHECK(node_.HasData()); |
470 if (!node_.Data()->dirty) { | 450 if (!node_.Data()->dirty) { |
471 node_.Data()->dirty = backend_->GetCurrentEntryId(); | 451 node_.Data()->dirty = backend_->GetCurrentEntryId(); |
472 node_.Store(); | 452 node_.Store(); |
473 } | 453 } |
474 doomed_ = true; | 454 doomed_ = true; |
475 } | 455 } |
476 | 456 |
| 457 void EntryImpl::DeleteEntryData(bool everything) { |
| 458 DCHECK(doomed_ || !everything); |
| 459 |
| 460 UMA_HISTOGRAM_COUNTS("DiskCache.DeleteHeader", GetDataSize(0)); |
| 461 UMA_HISTOGRAM_COUNTS("DiskCache.DeleteData", GetDataSize(1)); |
| 462 for (int index = 0; index < NUM_STREAMS; index++) { |
| 463 Addr address(entry_.Data()->data_addr[index]); |
| 464 if (address.is_initialized()) { |
| 465 DeleteData(address, index); |
| 466 backend_->ModifyStorageSize(entry_.Data()->data_size[index] - |
| 467 unreported_size_[index], 0); |
| 468 } |
| 469 } |
| 470 |
| 471 if (!everything) |
| 472 return; |
| 473 |
| 474 // Remove all traces of this entry. |
| 475 backend_->RemoveEntry(this); |
| 476 |
| 477 Addr address(entry_.Data()->long_key); |
| 478 DeleteData(address, kKeyFileIndex); |
| 479 backend_->ModifyStorageSize(entry_.Data()->key_len, 0); |
| 480 |
| 481 memset(node_.buffer(), 0, node_.size()); |
| 482 memset(entry_.buffer(), 0, entry_.size()); |
| 483 node_.Store(); |
| 484 entry_.Store(); |
| 485 |
| 486 backend_->DeleteBlock(node_.address(), false); |
| 487 backend_->DeleteBlock(entry_.address(), false); |
| 488 } |
| 489 |
477 CacheAddr EntryImpl::GetNextAddress() { | 490 CacheAddr EntryImpl::GetNextAddress() { |
478 return entry_.Data()->next; | 491 return entry_.Data()->next; |
479 } | 492 } |
480 | 493 |
481 void EntryImpl::SetNextAddress(Addr address) { | 494 void EntryImpl::SetNextAddress(Addr address) { |
482 entry_.Data()->next = address.value(); | 495 entry_.Data()->next = address.value(); |
483 bool success = entry_.Store(); | 496 bool success = entry_.Store(); |
484 DCHECK(success); | 497 DCHECK(success); |
485 } | 498 } |
486 | 499 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), | 842 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), |
830 entry_.address().value(), node_.address().value()); | 843 entry_.address().value(), node_.address().value()); |
831 | 844 |
832 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], | 845 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], |
833 entry_.Data()->data_addr[1], entry_.Data()->long_key); | 846 entry_.Data()->data_addr[1], entry_.Data()->long_key); |
834 | 847 |
835 Trace(" doomed: %d 0x%p 0x%x", doomed_, pointer, dirty); | 848 Trace(" doomed: %d 0x%p 0x%x", doomed_, pointer, dirty); |
836 } | 849 } |
837 | 850 |
838 } // namespace disk_cache | 851 } // namespace disk_cache |
OLD | NEW |