| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/hash.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/metrics/stats_counters.h" | 15 #include "base/metrics/stats_counters.h" |
| 15 #include "base/rand_util.h" | 16 #include "base/rand_util.h" |
| 16 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 17 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
| 18 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
| 19 #include "base/threading/worker_pool.h" | 20 #include "base/threading/worker_pool.h" |
| 20 #include "base/threading/thread_restrictions.h" | 21 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/time.h" | 22 #include "base/time.h" |
| 22 #include "base/timer.h" | 23 #include "base/timer.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "net/disk_cache/cache_util.h" | 25 #include "net/disk_cache/cache_util.h" |
| 25 #include "net/disk_cache/entry_impl.h" | 26 #include "net/disk_cache/entry_impl.h" |
| 26 #include "net/disk_cache/errors.h" | 27 #include "net/disk_cache/errors.h" |
| 27 #include "net/disk_cache/experiments.h" | 28 #include "net/disk_cache/experiments.h" |
| 28 #include "net/disk_cache/file.h" | 29 #include "net/disk_cache/file.h" |
| 29 #include "net/disk_cache/hash.h" | |
| 30 #include "net/disk_cache/mem_backend_impl.h" | 30 #include "net/disk_cache/mem_backend_impl.h" |
| 31 | 31 |
| 32 // This has to be defined before including histogram_macros.h from this file. | 32 // This has to be defined before including histogram_macros.h from this file. |
| 33 #define NET_DISK_CACHE_BACKEND_IMPL_CC_ | 33 #define NET_DISK_CACHE_BACKEND_IMPL_CC_ |
| 34 #include "net/disk_cache/histogram_macros.h" | 34 #include "net/disk_cache/histogram_macros.h" |
| 35 | 35 |
| 36 using base::Time; | 36 using base::Time; |
| 37 using base::TimeDelta; | 37 using base::TimeDelta; |
| 38 using base::TimeTicks; | 38 using base::TimeTicks; |
| 39 | 39 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 | 658 |
| 659 void BackendImpl::SyncEndEnumeration(void* iter) { | 659 void BackendImpl::SyncEndEnumeration(void* iter) { |
| 660 scoped_ptr<Rankings::Iterator> iterator( | 660 scoped_ptr<Rankings::Iterator> iterator( |
| 661 reinterpret_cast<Rankings::Iterator*>(iter)); | 661 reinterpret_cast<Rankings::Iterator*>(iter)); |
| 662 } | 662 } |
| 663 | 663 |
| 664 void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { | 664 void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { |
| 665 if (disabled_) | 665 if (disabled_) |
| 666 return; | 666 return; |
| 667 | 667 |
| 668 uint32 hash = Hash(key); | 668 uint32 hash = base::Hash(key); |
| 669 bool error; | 669 bool error; |
| 670 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); | 670 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); |
| 671 if (cache_entry) { | 671 if (cache_entry) { |
| 672 if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) { | 672 if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) { |
| 673 UpdateRank(cache_entry, false); | 673 UpdateRank(cache_entry, false); |
| 674 } | 674 } |
| 675 cache_entry->Release(); | 675 cache_entry->Release(); |
| 676 } | 676 } |
| 677 } | 677 } |
| 678 | 678 |
| 679 EntryImpl* BackendImpl::OpenEntryImpl(const std::string& key) { | 679 EntryImpl* BackendImpl::OpenEntryImpl(const std::string& key) { |
| 680 if (disabled_) | 680 if (disabled_) |
| 681 return NULL; | 681 return NULL; |
| 682 | 682 |
| 683 TimeTicks start = TimeTicks::Now(); | 683 TimeTicks start = TimeTicks::Now(); |
| 684 uint32 hash = Hash(key); | 684 uint32 hash = base::Hash(key); |
| 685 Trace("Open hash 0x%x", hash); | 685 Trace("Open hash 0x%x", hash); |
| 686 | 686 |
| 687 bool error; | 687 bool error; |
| 688 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); | 688 EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); |
| 689 if (!cache_entry) { | 689 if (!cache_entry) { |
| 690 stats_.OnEvent(Stats::OPEN_MISS); | 690 stats_.OnEvent(Stats::OPEN_MISS); |
| 691 return NULL; | 691 return NULL; |
| 692 } | 692 } |
| 693 | 693 |
| 694 if (ENTRY_NORMAL != cache_entry->entry()->Data()->state) { | 694 if (ENTRY_NORMAL != cache_entry->entry()->Data()->state) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 707 stats_.OnEvent(Stats::OPEN_HIT); | 707 stats_.OnEvent(Stats::OPEN_HIT); |
| 708 SIMPLE_STATS_COUNTER("disk_cache.hit"); | 708 SIMPLE_STATS_COUNTER("disk_cache.hit"); |
| 709 return cache_entry; | 709 return cache_entry; |
| 710 } | 710 } |
| 711 | 711 |
| 712 EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) { | 712 EntryImpl* BackendImpl::CreateEntryImpl(const std::string& key) { |
| 713 if (disabled_ || key.empty()) | 713 if (disabled_ || key.empty()) |
| 714 return NULL; | 714 return NULL; |
| 715 | 715 |
| 716 TimeTicks start = TimeTicks::Now(); | 716 TimeTicks start = TimeTicks::Now(); |
| 717 uint32 hash = Hash(key); | 717 uint32 hash = base::Hash(key); |
| 718 Trace("Create hash 0x%x", hash); | 718 Trace("Create hash 0x%x", hash); |
| 719 | 719 |
| 720 scoped_refptr<EntryImpl> parent; | 720 scoped_refptr<EntryImpl> parent; |
| 721 Addr entry_address(data_->table[hash & mask_]); | 721 Addr entry_address(data_->table[hash & mask_]); |
| 722 if (entry_address.is_initialized()) { | 722 if (entry_address.is_initialized()) { |
| 723 // We have an entry already. It could be the one we are looking for, or just | 723 // We have an entry already. It could be the one we are looking for, or just |
| 724 // a hash conflict. | 724 // a hash conflict. |
| 725 bool error; | 725 bool error; |
| 726 EntryImpl* old_entry = MatchEntry(key, hash, false, Addr(), &error); | 726 EntryImpl* old_entry = MatchEntry(key, hash, false, Addr(), &error); |
| 727 if (old_entry) | 727 if (old_entry) |
| (...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2211 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2211 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
| 2212 total_memory = kMaxBuffersSize; | 2212 total_memory = kMaxBuffersSize; |
| 2213 | 2213 |
| 2214 done = true; | 2214 done = true; |
| 2215 } | 2215 } |
| 2216 | 2216 |
| 2217 return static_cast<int>(total_memory); | 2217 return static_cast<int>(total_memory); |
| 2218 } | 2218 } |
| 2219 | 2219 |
| 2220 } // namespace disk_cache | 2220 } // namespace disk_cache |
| OLD | NEW |