| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 83 } |
| 84 | 84 |
| 85 // When an entry is deleted from the cache, we clean up all the data associated | 85 // When an entry is deleted from the cache, we clean up all the data associated |
| 86 // with it for two reasons: to simplify the reuse of the block (we know that any | 86 // with it for two reasons: to simplify the reuse of the block (we know that any |
| 87 // unused block is filled with zeros), and to simplify the handling of write / | 87 // unused block is filled with zeros), and to simplify the handling of write / |
| 88 // read partial information from an entry (don't have to worry about returning | 88 // read partial information from an entry (don't have to worry about returning |
| 89 // data related to a previous cache entry because the range was not fully | 89 // data related to a previous cache entry because the range was not fully |
| 90 // written before). | 90 // written before). |
| 91 EntryImpl::~EntryImpl() { | 91 EntryImpl::~EntryImpl() { |
| 92 if (doomed_) { | 92 if (doomed_) { |
| 93 UMA_HISTOGRAM_COUNTS(L"DiskCache.DeleteHeader", GetDataSize(0)); | 93 UMA_HISTOGRAM_COUNTS("DiskCache.DeleteHeader", GetDataSize(0)); |
| 94 UMA_HISTOGRAM_COUNTS(L"DiskCache.DeleteData", GetDataSize(1)); | 94 UMA_HISTOGRAM_COUNTS("DiskCache.DeleteData", GetDataSize(1)); |
| 95 for (int index = 0; index < NUM_STREAMS; index++) { | 95 for (int index = 0; index < NUM_STREAMS; index++) { |
| 96 Addr address(entry_.Data()->data_addr[index]); | 96 Addr address(entry_.Data()->data_addr[index]); |
| 97 if (address.is_initialized()) { | 97 if (address.is_initialized()) { |
| 98 DeleteData(address, index); | 98 DeleteData(address, index); |
| 99 backend_->ModifyStorageSize(entry_.Data()->data_size[index] - | 99 backend_->ModifyStorageSize(entry_.Data()->data_size[index] - |
| 100 unreported_size_[index], 0); | 100 unreported_size_[index], 0); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 Addr address(entry_.Data()->long_key); | 103 Addr address(entry_.Data()->long_key); |
| 104 DeleteData(address, kKeyFileIndex); | 104 DeleteData(address, kKeyFileIndex); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return net::ERR_INVALID_ARGUMENT; | 204 return net::ERR_INVALID_ARGUMENT; |
| 205 | 205 |
| 206 int entry_size = entry_.Data()->data_size[index]; | 206 int entry_size = entry_.Data()->data_size[index]; |
| 207 if (offset >= entry_size || offset < 0 || !buf_len) | 207 if (offset >= entry_size || offset < 0 || !buf_len) |
| 208 return 0; | 208 return 0; |
| 209 | 209 |
| 210 if (buf_len < 0) | 210 if (buf_len < 0) |
| 211 return net::ERR_INVALID_ARGUMENT; | 211 return net::ERR_INVALID_ARGUMENT; |
| 212 | 212 |
| 213 Time start = Time::Now(); | 213 Time start = Time::Now(); |
| 214 static Histogram stats(L"DiskCache.ReadTime", TimeDelta::FromMilliseconds(1), | 214 static Histogram stats("DiskCache.ReadTime", TimeDelta::FromMilliseconds(1), |
| 215 TimeDelta::FromSeconds(10), 50); | 215 TimeDelta::FromSeconds(10), 50); |
| 216 stats.SetFlags(kUmaTargetedHistogramFlag); | 216 stats.SetFlags(kUmaTargetedHistogramFlag); |
| 217 | 217 |
| 218 if (offset + buf_len > entry_size) | 218 if (offset + buf_len > entry_size) |
| 219 buf_len = entry_size - offset; | 219 buf_len = entry_size - offset; |
| 220 | 220 |
| 221 UpdateRank(false); | 221 UpdateRank(false); |
| 222 | 222 |
| 223 backend_->OnEvent(Stats::READ_DATA); | 223 backend_->OnEvent(Stats::READ_DATA); |
| 224 | 224 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 if (offset > max_file_size || buf_len > max_file_size || | 278 if (offset > max_file_size || buf_len > max_file_size || |
| 279 offset + buf_len > max_file_size) { | 279 offset + buf_len > max_file_size) { |
| 280 int size = offset + buf_len; | 280 int size = offset + buf_len; |
| 281 if (size <= max_file_size) | 281 if (size <= max_file_size) |
| 282 size = kint32max; | 282 size = kint32max; |
| 283 backend_->TooMuchStorageRequested(size); | 283 backend_->TooMuchStorageRequested(size); |
| 284 return net::ERR_FAILED; | 284 return net::ERR_FAILED; |
| 285 } | 285 } |
| 286 | 286 |
| 287 Time start = Time::Now(); | 287 Time start = Time::Now(); |
| 288 static Histogram stats(L"DiskCache.WriteTime", TimeDelta::FromMilliseconds(1), | 288 static Histogram stats("DiskCache.WriteTime", TimeDelta::FromMilliseconds(1), |
| 289 TimeDelta::FromSeconds(10), 50); | 289 TimeDelta::FromSeconds(10), 50); |
| 290 stats.SetFlags(kUmaTargetedHistogramFlag); | 290 stats.SetFlags(kUmaTargetedHistogramFlag); |
| 291 | 291 |
| 292 // Read the size at this point (it may change inside prepare). | 292 // Read the size at this point (it may change inside prepare). |
| 293 int entry_size = entry_.Data()->data_size[index]; | 293 int entry_size = entry_.Data()->data_size[index]; |
| 294 if (!PrepareTarget(index, offset, buf_len, truncate)) | 294 if (!PrepareTarget(index, offset, buf_len, truncate)) |
| 295 return net::ERR_FAILED; | 295 return net::ERR_FAILED; |
| 296 | 296 |
| 297 if (entry_size < offset + buf_len) { | 297 if (entry_size < offset + buf_len) { |
| 298 unreported_size_[index] += offset + buf_len - entry_size; | 298 unreported_size_[index] += offset + buf_len - entry_size; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 } | 550 } |
| 551 | 551 |
| 552 void EntryImpl::DeleteData(Addr address, int index) { | 552 void EntryImpl::DeleteData(Addr address, int index) { |
| 553 if (!address.is_initialized()) | 553 if (!address.is_initialized()) |
| 554 return; | 554 return; |
| 555 if (address.is_separate_file()) { | 555 if (address.is_separate_file()) { |
| 556 if (files_[index]) | 556 if (files_[index]) |
| 557 files_[index] = NULL; // Releases the object. | 557 files_[index] = NULL; // Releases the object. |
| 558 | 558 |
| 559 if (!DeleteCacheFile(backend_->GetFileName(address))) { | 559 if (!DeleteCacheFile(backend_->GetFileName(address))) { |
| 560 UMA_HISTOGRAM_COUNTS(L"DiskCache.DeleteFailed", 1); | 560 UMA_HISTOGRAM_COUNTS("DiskCache.DeleteFailed", 1); |
| 561 LOG(ERROR) << "Failed to delete " << backend_->GetFileName(address) << | 561 LOG(ERROR) << "Failed to delete " << backend_->GetFileName(address) << |
| 562 " from the cache."; | 562 " from the cache."; |
| 563 } | 563 } |
| 564 } else { | 564 } else { |
| 565 backend_->DeleteBlock(address, true); | 565 backend_->DeleteBlock(address, true); |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 | 568 |
| 569 void EntryImpl::UpdateRank(bool modified) { | 569 void EntryImpl::UpdateRank(bool modified) { |
| 570 if (!doomed_) { | 570 if (!doomed_) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), | 778 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), |
| 779 entry_.address().value(), node_.address().value()); | 779 entry_.address().value(), node_.address().value()); |
| 780 | 780 |
| 781 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], | 781 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], |
| 782 entry_.Data()->data_addr[1], entry_.Data()->long_key); | 782 entry_.Data()->data_addr[1], entry_.Data()->long_key); |
| 783 | 783 |
| 784 Trace(" doomed: %d 0x%p 0x%x", doomed_, pointer, dirty); | 784 Trace(" doomed: %d 0x%p 0x%x", doomed_, pointer, dirty); |
| 785 } | 785 } |
| 786 | 786 |
| 787 } // namespace disk_cache | 787 } // namespace disk_cache |
| 788 | |
| OLD | NEW |