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/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" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
15 #include "base/timer.h" | 15 #include "base/timer.h" |
16 #include "base/worker_pool.h" | 16 #include "base/worker_pool.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/disk_cache/cache_util.h" | 18 #include "net/disk_cache/cache_util.h" |
19 #include "net/disk_cache/entry_impl.h" | 19 #include "net/disk_cache/entry_impl.h" |
20 #include "net/disk_cache/errors.h" | 20 #include "net/disk_cache/errors.h" |
21 #include "net/disk_cache/hash.h" | 21 #include "net/disk_cache/hash.h" |
22 #include "net/disk_cache/file.h" | 22 #include "net/disk_cache/file.h" |
23 | 23 |
24 // This has to be defined before including histogram_macros.h from this file. | 24 // This has to be defined before including histogram_macros.h from this file. |
25 #define NET_DISK_CACHE_BACKEND_IMPL_CC_ | 25 #define NET_DISK_CACHE_BACKEND_IMPL_CC_ |
26 #include "net/disk_cache/histogram_macros.h" | 26 #include "net/disk_cache/histogram_macros.h" |
27 | 27 |
28 using base::Time; | 28 using base::Time; |
29 using base::TimeDelta; | 29 using base::TimeDelta; |
| 30 using base::TimeTicks; |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 const char* kIndexName = "index"; | 34 const char* kIndexName = "index"; |
34 const int kMaxOldFolders = 100; | 35 const int kMaxOldFolders = 100; |
35 | 36 |
36 // Seems like ~240 MB correspond to less than 50k entries for 99% of the people. | 37 // Seems like ~240 MB correspond to less than 50k entries for 99% of the people. |
37 const int k64kEntriesStore = 240 * 1000 * 1000; | 38 const int k64kEntriesStore = 240 * 1000 * 1000; |
38 const int kBaseTableLen = 64 * 1024; | 39 const int kBaseTableLen = 64 * 1024; |
39 const int kDefaultCacheSize = 80 * 1024 * 1024; | 40 const int kDefaultCacheSize = 80 * 1024 * 1024; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 not_deleted = 0; | 344 not_deleted = 0; |
344 } | 345 } |
345 | 346 |
346 return not_deleted; | 347 return not_deleted; |
347 } | 348 } |
348 | 349 |
349 bool BackendImpl::OpenEntry(const std::string& key, Entry** entry) { | 350 bool BackendImpl::OpenEntry(const std::string& key, Entry** entry) { |
350 if (disabled_) | 351 if (disabled_) |
351 return false; | 352 return false; |
352 | 353 |
353 Time start = Time::Now(); | 354 TimeTicks start = TimeTicks::Now(); |
354 uint32 hash = Hash(key); | 355 uint32 hash = Hash(key); |
355 | 356 |
356 EntryImpl* cache_entry = MatchEntry(key, hash, false); | 357 EntryImpl* cache_entry = MatchEntry(key, hash, false); |
357 if (!cache_entry) { | 358 if (!cache_entry) { |
358 stats_.OnEvent(Stats::OPEN_MISS); | 359 stats_.OnEvent(Stats::OPEN_MISS); |
359 return false; | 360 return false; |
360 } | 361 } |
361 | 362 |
362 if (ENTRY_NORMAL != cache_entry->entry()->Data()->state) { | 363 if (ENTRY_NORMAL != cache_entry->entry()->Data()->state) { |
363 // The entry was already evicted. | 364 // The entry was already evicted. |
(...skipping 19 matching lines...) Expand all Loading... |
383 return net::ERR_FAILED; | 384 return net::ERR_FAILED; |
384 } | 385 } |
385 | 386 |
386 bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) { | 387 bool BackendImpl::CreateEntry(const std::string& key, Entry** entry) { |
387 if (disabled_ || key.empty()) | 388 if (disabled_ || key.empty()) |
388 return false; | 389 return false; |
389 | 390 |
390 DCHECK(entry); | 391 DCHECK(entry); |
391 *entry = NULL; | 392 *entry = NULL; |
392 | 393 |
393 Time start = Time::Now(); | 394 TimeTicks start = TimeTicks::Now(); |
394 uint32 hash = Hash(key); | 395 uint32 hash = Hash(key); |
395 | 396 |
396 scoped_refptr<EntryImpl> parent; | 397 scoped_refptr<EntryImpl> parent; |
397 Addr entry_address(data_->table[hash & mask_]); | 398 Addr entry_address(data_->table[hash & mask_]); |
398 if (entry_address.is_initialized()) { | 399 if (entry_address.is_initialized()) { |
399 // We have an entry already. It could be the one we are looking for, or just | 400 // We have an entry already. It could be the one we are looking for, or just |
400 // a hash conflict. | 401 // a hash conflict. |
401 EntryImpl* old_entry = MatchEntry(key, hash, false); | 402 EntryImpl* old_entry = MatchEntry(key, hash, false); |
402 if (old_entry) | 403 if (old_entry) |
403 return ResurrectEntry(old_entry, entry); | 404 return ResurrectEntry(old_entry, entry); |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 scoped_refptr<EntryImpl> cache_entry(new EntryImpl(this, address)); | 1154 scoped_refptr<EntryImpl> cache_entry(new EntryImpl(this, address)); |
1154 IncreaseNumRefs(); | 1155 IncreaseNumRefs(); |
1155 *entry = NULL; | 1156 *entry = NULL; |
1156 | 1157 |
1157 if (!address.is_initialized() || address.is_separate_file() || | 1158 if (!address.is_initialized() || address.is_separate_file() || |
1158 address.file_type() != BLOCK_256) { | 1159 address.file_type() != BLOCK_256) { |
1159 LOG(WARNING) << "Wrong entry address."; | 1160 LOG(WARNING) << "Wrong entry address."; |
1160 return ERR_INVALID_ADDRESS; | 1161 return ERR_INVALID_ADDRESS; |
1161 } | 1162 } |
1162 | 1163 |
1163 Time start = Time::Now(); | 1164 TimeTicks start = TimeTicks::Now(); |
1164 if (!cache_entry->entry()->Load()) | 1165 if (!cache_entry->entry()->Load()) |
1165 return ERR_READ_FAILURE; | 1166 return ERR_READ_FAILURE; |
1166 | 1167 |
1167 if (IsLoaded()) { | 1168 if (IsLoaded()) { |
1168 CACHE_UMA(AGE_MS, "LoadTime", GetSizeGroup(), start); | 1169 CACHE_UMA(AGE_MS, "LoadTime", GetSizeGroup(), start); |
1169 } | 1170 } |
1170 | 1171 |
1171 if (!cache_entry->SanityCheck()) { | 1172 if (!cache_entry->SanityCheck()) { |
1172 LOG(WARNING) << "Messed up entry found."; | 1173 LOG(WARNING) << "Messed up entry found."; |
1173 return ERR_INVALID_ENTRY; | 1174 return ERR_INVALID_ENTRY; |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1677 | 1678 |
1678 return num_dirty; | 1679 return num_dirty; |
1679 } | 1680 } |
1680 | 1681 |
1681 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { | 1682 bool BackendImpl::CheckEntry(EntryImpl* cache_entry) { |
1682 RankingsNode* rankings = cache_entry->rankings()->Data(); | 1683 RankingsNode* rankings = cache_entry->rankings()->Data(); |
1683 return !rankings->dummy; | 1684 return !rankings->dummy; |
1684 } | 1685 } |
1685 | 1686 |
1686 } // namespace disk_cache | 1687 } // namespace disk_cache |
OLD | NEW |