| 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/backend_impl.h" |     5 #include "net/disk_cache/backend_impl.h" | 
|     6  |     6  | 
|     7 #include "base/file_util.h" |     7 #include "base/file_util.h" | 
|     8 #include "base/histogram.h" |     8 #include "base/histogram.h" | 
|     9 #include "base/message_loop.h" |     9 #include "base/message_loop.h" | 
|    10 #include "base/string_util.h" |    10 #include "base/string_util.h" | 
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   269   EntryImpl* cache_entry = MatchEntry(key, hash, false); |   269   EntryImpl* cache_entry = MatchEntry(key, hash, false); | 
|   270   if (!cache_entry) { |   270   if (!cache_entry) { | 
|   271     stats_.OnEvent(Stats::OPEN_MISS); |   271     stats_.OnEvent(Stats::OPEN_MISS); | 
|   272     return false; |   272     return false; | 
|   273   } |   273   } | 
|   274  |   274  | 
|   275   eviction_.OnOpenEntry(cache_entry); |   275   eviction_.OnOpenEntry(cache_entry); | 
|   276   DCHECK(entry); |   276   DCHECK(entry); | 
|   277   *entry = cache_entry; |   277   *entry = cache_entry; | 
|   278  |   278  | 
|   279   UMA_HISTOGRAM_TIMES(L"DiskCache.OpenTime", Time::Now() - start); |   279   UMA_HISTOGRAM_TIMES("DiskCache.OpenTime", Time::Now() - start); | 
|   280   stats_.OnEvent(Stats::OPEN_HIT); |   280   stats_.OnEvent(Stats::OPEN_HIT); | 
|   281   return true; |   281   return true; | 
|   282 } |   282 } | 
|   283  |   283  | 
|   284 bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) { |   284 bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) { | 
|   285   if (disabled_ || key.empty()) |   285   if (disabled_ || key.empty()) | 
|   286     return false; |   286     return false; | 
|   287  |   287  | 
|   288   Time start = Time::Now(); |   288   Time start = Time::Now(); | 
|   289   uint32 hash = Hash(key); |   289   uint32 hash = Hash(key); | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   342   data_->header.num_entries++; |   342   data_->header.num_entries++; | 
|   343   DCHECK(data_->header.num_entries > 0); |   343   DCHECK(data_->header.num_entries > 0); | 
|   344   eviction_.OnCreateEntry(cache_entry); |   344   eviction_.OnCreateEntry(cache_entry); | 
|   345   if (!parent.get()) |   345   if (!parent.get()) | 
|   346     data_->table[hash & mask_] = entry_address.value(); |   346     data_->table[hash & mask_] = entry_address.value(); | 
|   347  |   347  | 
|   348   DCHECK(entry); |   348   DCHECK(entry); | 
|   349   *entry = NULL; |   349   *entry = NULL; | 
|   350   cache_entry.swap(reinterpret_cast<EntryImpl**>(entry)); |   350   cache_entry.swap(reinterpret_cast<EntryImpl**>(entry)); | 
|   351  |   351  | 
|   352   UMA_HISTOGRAM_TIMES(L"DiskCache.CreateTime", Time::Now() - start); |   352   UMA_HISTOGRAM_TIMES("DiskCache.CreateTime", Time::Now() - start); | 
|   353   stats_.OnEvent(Stats::CREATE_HIT); |   353   stats_.OnEvent(Stats::CREATE_HIT); | 
|   354   Trace("create entry hit "); |   354   Trace("create entry hit "); | 
|   355   return true; |   355   return true; | 
|   356 } |   356 } | 
|   357  |   357  | 
|   358 bool BackendImpl::DoomEntry(const std::string& key) { |   358 bool BackendImpl::DoomEntry(const std::string& key) { | 
|   359   if (disabled_) |   359   if (disabled_) | 
|   360     return false; |   360     return false; | 
|   361  |   361  | 
|   362   Entry* entry; |   362   Entry* entry; | 
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   644   // Setting the index table length to an invalid value will force re-creation |   644   // Setting the index table length to an invalid value will force re-creation | 
|   645   // of the cache files. |   645   // of the cache files. | 
|   646   data_->header.table_len = 1; |   646   data_->header.table_len = 1; | 
|   647   disabled_ = true; |   647   disabled_ = true; | 
|   648  |   648  | 
|   649   if (!num_refs_) |   649   if (!num_refs_) | 
|   650     RestartCache(); |   650     RestartCache(); | 
|   651 } |   651 } | 
|   652  |   652  | 
|   653 void BackendImpl::ReportError(int error) { |   653 void BackendImpl::ReportError(int error) { | 
|   654   static LinearHistogram counter(L"DiskCache.Error", 0, 49, 50); |   654   static LinearHistogram counter("DiskCache.Error", 0, 49, 50); | 
|   655   counter.SetFlags(kUmaTargetedHistogramFlag); |   655   counter.SetFlags(kUmaTargetedHistogramFlag); | 
|   656  |   656  | 
|   657   // We transmit positive numbers, instead of direct error codes. |   657   // We transmit positive numbers, instead of direct error codes. | 
|   658   DCHECK(error <= 0); |   658   DCHECK(error <= 0); | 
|   659   counter.Add(error * -1); |   659   counter.Add(error * -1); | 
|   660 } |   660 } | 
|   661  |   661  | 
|   662 void BackendImpl::OnEvent(Stats::Counters an_event) { |   662 void BackendImpl::OnEvent(Stats::Counters an_event) { | 
|   663   stats_.OnEvent(an_event); |   663   stats_.OnEvent(an_event); | 
|   664 } |   664 } | 
|   665  |   665  | 
|   666 void BackendImpl::OnStatsTimer() { |   666 void BackendImpl::OnStatsTimer() { | 
|   667   stats_.OnEvent(Stats::TIMER); |   667   stats_.OnEvent(Stats::TIMER); | 
|   668   int64 current = stats_.GetCounter(Stats::OPEN_ENTRIES); |   668   int64 current = stats_.GetCounter(Stats::OPEN_ENTRIES); | 
|   669   int64 time = stats_.GetCounter(Stats::TIMER); |   669   int64 time = stats_.GetCounter(Stats::TIMER); | 
|   670  |   670  | 
|   671   current = current * (time - 1) + num_refs_; |   671   current = current * (time - 1) + num_refs_; | 
|   672   current /= time; |   672   current /= time; | 
|   673   stats_.SetCounter(Stats::OPEN_ENTRIES, current); |   673   stats_.SetCounter(Stats::OPEN_ENTRIES, current); | 
|   674   stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_); |   674   stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_); | 
|   675  |   675  | 
|   676   static bool first_time = true; |   676   static bool first_time = true; | 
|   677   if (!data_) |   677   if (!data_) | 
|   678     first_time = false; |   678     first_time = false; | 
|   679   if (first_time) { |   679   if (first_time) { | 
|   680     first_time = false; |   680     first_time = false; | 
|   681     int experiment = data_->header.experiment; |   681     int experiment = data_->header.experiment; | 
|   682     std::wstring entries(StringPrintf(L"DiskCache.Entries_%d", experiment)); |   682     std::string entries(StringPrintf("DiskCache.Entries_%d", experiment)); | 
|   683     std::wstring size(StringPrintf(L"DiskCache.Size_%d", experiment)); |   683     std::string size(StringPrintf("DiskCache.Size_%d", experiment)); | 
|   684     std::wstring max_size(StringPrintf(L"DiskCache.MaxSize_%d", experiment)); |   684     std::string max_size(StringPrintf("DiskCache.MaxSize_%d", experiment)); | 
|   685     UMA_HISTOGRAM_COUNTS(entries.c_str(), data_->header.num_entries); |   685     UMA_HISTOGRAM_COUNTS(entries.c_str(), data_->header.num_entries); | 
|   686     UMA_HISTOGRAM_COUNTS(size.c_str(), data_->header.num_bytes / (1024 * 1024)); |   686     UMA_HISTOGRAM_COUNTS(size.c_str(), data_->header.num_bytes / (1024 * 1024)); | 
|   687     UMA_HISTOGRAM_COUNTS(max_size.c_str(), max_size_ / (1024 * 1024)); |   687     UMA_HISTOGRAM_COUNTS(max_size.c_str(), max_size_ / (1024 * 1024)); | 
|   688   } |   688   } | 
|   689 } |   689 } | 
|   690  |   690  | 
|   691 void BackendImpl::IncrementIoCount() { |   691 void BackendImpl::IncrementIoCount() { | 
|   692   num_pending_io_++; |   692   num_pending_io_++; | 
|   693 } |   693 } | 
|   694  |   694  | 
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1153  |  1153  | 
|  1154   return num_dirty; |  1154   return num_dirty; | 
|  1155 } |  1155 } | 
|  1156  |  1156  | 
|  1157 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { |  1157 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { | 
|  1158   RankingsNode* rankings = cache_entry->rankings()->Data(); |  1158   RankingsNode* rankings = cache_entry->rankings()->Data(); | 
|  1159   return !rankings->pointer; |  1159   return !rankings->pointer; | 
|  1160 } |  1160 } | 
|  1161  |  1161  | 
|  1162 }  // namespace disk_cache |  1162 }  // namespace disk_cache | 
| OLD | NEW |