Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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/field_trial.h" | 7 #include "base/field_trial.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 bool create_files = false; | 458 bool create_files = false; |
| 459 if (!InitBackingStore(&create_files)) { | 459 if (!InitBackingStore(&create_files)) { |
| 460 ReportError(ERR_STORAGE_ERROR); | 460 ReportError(ERR_STORAGE_ERROR); |
| 461 return net::ERR_FAILED; | 461 return net::ERR_FAILED; |
| 462 } | 462 } |
| 463 | 463 |
| 464 num_refs_ = num_pending_io_ = max_refs_ = 0; | 464 num_refs_ = num_pending_io_ = max_refs_ = 0; |
| 465 entry_count_ = byte_count_ = 0; | 465 entry_count_ = byte_count_ = 0; |
| 466 | 466 |
| 467 if (!restarted_) { | 467 if (!restarted_) { |
| 468 buffer_bytes_ = 0; | |
| 468 trace_object_ = TraceObject::GetTraceObject(); | 469 trace_object_ = TraceObject::GetTraceObject(); |
| 469 // Create a recurrent timer of 30 secs. | 470 // Create a recurrent timer of 30 secs. |
| 470 int timer_delay = unit_test_ ? 1000 : 30000; | 471 int timer_delay = unit_test_ ? 1000 : 30000; |
| 471 timer_.Start(TimeDelta::FromMilliseconds(timer_delay), this, | 472 timer_.Start(TimeDelta::FromMilliseconds(timer_delay), this, |
| 472 &BackendImpl::OnStatsTimer); | 473 &BackendImpl::OnStatsTimer); |
| 473 } | 474 } |
| 474 | 475 |
| 475 init_ = true; | 476 init_ = true; |
| 476 | 477 |
| 477 if (data_->header.experiment != 0 && cache_type_ != net::DISK_CACHE) { | 478 if (data_->header.experiment != 0 && cache_type_ != net::DISK_CACHE) { |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 AddStorageSize(new_size - old_size); | 962 AddStorageSize(new_size - old_size); |
| 962 | 963 |
| 963 // Update the usage statistics. | 964 // Update the usage statistics. |
| 964 stats_.ModifyStorageStats(old_size, new_size); | 965 stats_.ModifyStorageStats(old_size, new_size); |
| 965 } | 966 } |
| 966 | 967 |
| 967 void BackendImpl::TooMuchStorageRequested(int32 size) { | 968 void BackendImpl::TooMuchStorageRequested(int32 size) { |
| 968 stats_.ModifyStorageStats(0, size); | 969 stats_.ModifyStorageStats(0, size); |
| 969 } | 970 } |
| 970 | 971 |
| 972 bool BackendImpl::IsAllocAllowed(int current_size, int new_size) { | |
| 973 DCHECK_GT(new_size, current_size); | |
| 974 int to_add = new_size - current_size; | |
| 975 if (buffer_bytes_ + to_add > MaxBuffersSize()) | |
| 976 return false; | |
| 977 | |
| 978 buffer_bytes_ += to_add; | |
| 979 HISTOGRAM_COUNTS("DiskCache.BufferBytes", buffer_bytes_ / 10); | |
| 980 return true; | |
| 981 } | |
| 982 | |
| 983 void BackendImpl::BufferDeleted(int size) { | |
| 984 buffer_bytes_ -= size; | |
| 985 DCHECK_GE(size, 0); | |
| 986 } | |
| 987 | |
| 971 bool BackendImpl::IsLoaded() const { | 988 bool BackendImpl::IsLoaded() const { |
| 972 CACHE_UMA(COUNTS, "PendingIO", GetSizeGroup(), num_pending_io_); | 989 CACHE_UMA(COUNTS, "PendingIO", GetSizeGroup(), num_pending_io_); |
| 973 if (user_flags_ & kNoLoadProtection) | 990 if (user_flags_ & kNoLoadProtection) |
| 974 return false; | 991 return false; |
| 975 | 992 |
| 976 return num_pending_io_ > 5; | 993 return num_pending_io_ > 5; |
| 977 } | 994 } |
| 978 | 995 |
| 979 std::string BackendImpl::HistogramName(const char* name, int experiment) const { | 996 std::string BackendImpl::HistogramName(const char* name, int experiment) const { |
| 980 if (!experiment) | 997 if (!experiment) |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1858 } | 1875 } |
| 1859 | 1876 |
| 1860 return num_dirty; | 1877 return num_dirty; |
| 1861 } | 1878 } |
| 1862 | 1879 |
| 1863 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { | 1880 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { |
| 1864 RankingsNode* rankings = cache_entry->rankings()->Data(); | 1881 RankingsNode* rankings = cache_entry->rankings()->Data(); |
| 1865 return !rankings->dummy; | 1882 return !rankings->dummy; |
| 1866 } | 1883 } |
| 1867 | 1884 |
| 1885 int BackendImpl::MaxBuffersSize() { | |
| 1886 static int64 total_memory = base::SysInfo::AmountOfPhysicalMemory(); | |
| 1887 static bool done = false; | |
| 1888 | |
| 1889 if (!done) { | |
| 1890 const int kMaxBuffersSize = 30 * 1024 * 1024; | |
| 1891 | |
| 1892 // We want to use up to 2% of the computer's memory. | |
| 1893 total_memory = total_memory * 2 / 100; | |
|
gavinp
2010/08/19 18:17:22
How did you arrive at 2%?
rvargas (doing something else)
2010/08/20 18:22:21
From nowhere?. That seems like a reasonable number
| |
| 1894 if (total_memory > kMaxBuffersSize || total_memory <= 0) | |
| 1895 total_memory = kMaxBuffersSize; | |
| 1896 | |
| 1897 done = true; | |
| 1898 } | |
| 1899 | |
| 1900 return static_cast<int>(total_memory); | |
| 1901 } | |
| 1902 | |
| 1868 } // namespace disk_cache | 1903 } // namespace disk_cache |
| OLD | NEW |