Chromium Code Reviews| 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/blockfile/backend_impl_v3.h" | 5 #include "net/disk_cache/blockfile/backend_impl_v3.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/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 int BackendImplV3::Init(const CompletionCallback& callback) { | 83 int BackendImplV3::Init(const CompletionCallback& callback) { |
| 84 DCHECK(!init_); | 84 DCHECK(!init_); |
| 85 if (init_) | 85 if (init_) |
| 86 return net::ERR_FAILED; | 86 return net::ERR_FAILED; |
| 87 | 87 |
| 88 return net::ERR_IO_PENDING; | 88 return net::ERR_IO_PENDING; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // ------------------------------------------------------------------------ | 91 // ------------------------------------------------------------------------ |
| 92 | 92 |
| 93 #if defined(V3_NOT_JUST_YET_READY) | |
| 94 int BackendImplV3::OpenPrevEntry(void** iter, Entry** prev_entry, | |
| 95 const CompletionCallback& callback) { | |
| 96 DCHECK(!callback.is_null()); | |
| 97 return OpenFollowingEntry(true, iter, prev_entry, callback); | |
| 98 } | |
| 99 #endif // defined(V3_NOT_JUST_YET_READY). | |
| 100 | |
| 101 bool BackendImplV3::SetMaxSize(int max_bytes) { | 93 bool BackendImplV3::SetMaxSize(int max_bytes) { |
| 102 COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model); | 94 COMPILE_ASSERT(sizeof(max_bytes) == sizeof(max_size_), unsupported_int_model); |
| 103 if (max_bytes < 0) | 95 if (max_bytes < 0) |
| 104 return false; | 96 return false; |
| 105 | 97 |
| 106 // Zero size means use the default. | 98 // Zero size means use the default. |
| 107 if (!max_bytes) | 99 if (!max_bytes) |
| 108 return true; | 100 return true; |
| 109 | 101 |
| 110 // Avoid a DCHECK later on. | 102 // Avoid a DCHECK later on. |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 address.value()); | 947 address.value()); |
| 956 } | 948 } |
| 957 | 949 |
| 958 open_entries_[address.value()] = cache_entry.get(); | 950 open_entries_[address.value()] = cache_entry.get(); |
| 959 | 951 |
| 960 cache_entry->BeginLogging(net_log_, false); | 952 cache_entry->BeginLogging(net_log_, false); |
| 961 cache_entry.swap(entry); | 953 cache_entry.swap(entry); |
| 962 return 0; | 954 return 0; |
| 963 } | 955 } |
| 964 | 956 |
| 965 // This is the actual implementation for OpenNextEntry and OpenPrevEntry. | |
| 966 int BackendImplV3::OpenFollowingEntry(bool forward, void** iter, | |
|
clamy
2014/09/05 14:47:40
I am a bit confused about this function. The comme
| |
| 967 Entry** next_entry, | |
| 968 const CompletionCallback& callback) { | |
| 969 if (disabled_) | |
| 970 return net::ERR_FAILED; | |
| 971 | |
| 972 DCHECK(iter); | |
| 973 | |
| 974 const int kListsToSearch = 3; | |
| 975 scoped_refptr<EntryImpl> entries[kListsToSearch]; | |
| 976 scoped_ptr<Rankings::Iterator> iterator( | |
| 977 reinterpret_cast<Rankings::Iterator*>(*iter)); | |
| 978 *iter = NULL; | |
| 979 | |
| 980 if (!iterator.get()) { | |
| 981 iterator.reset(new Rankings::Iterator(&rankings_)); | |
| 982 bool ret = false; | |
| 983 | |
| 984 // Get an entry from each list. | |
| 985 for (int i = 0; i < kListsToSearch; i++) { | |
| 986 EntryImpl* temp = NULL; | |
| 987 ret |= OpenFollowingEntryFromList(forward, static_cast<Rankings::List>(i), | |
| 988 &iterator->nodes[i], &temp); | |
| 989 entries[i].swap(&temp); // The entry was already addref'd. | |
| 990 } | |
| 991 if (!ret) | |
| 992 return NULL; | |
| 993 } else { | |
| 994 // Get the next entry from the last list, and the actual entries for the | |
| 995 // elements on the other lists. | |
| 996 for (int i = 0; i < kListsToSearch; i++) { | |
| 997 EntryImpl* temp = NULL; | |
| 998 if (iterator->list == i) { | |
| 999 OpenFollowingEntryFromList(forward, iterator->list, | |
| 1000 &iterator->nodes[i], &temp); | |
| 1001 } else { | |
| 1002 temp = GetEnumeratedEntry(iterator->nodes[i], | |
| 1003 static_cast<Rankings::List>(i)); | |
| 1004 } | |
| 1005 | |
| 1006 entries[i].swap(&temp); // The entry was already addref'd. | |
| 1007 } | |
| 1008 } | |
| 1009 | |
| 1010 int newest = -1; | |
| 1011 int oldest = -1; | |
| 1012 Time access_times[kListsToSearch]; | |
| 1013 for (int i = 0; i < kListsToSearch; i++) { | |
| 1014 if (entries[i].get()) { | |
| 1015 access_times[i] = entries[i]->GetLastUsed(); | |
| 1016 if (newest < 0) { | |
| 1017 DCHECK_LT(oldest, 0); | |
| 1018 newest = oldest = i; | |
| 1019 continue; | |
| 1020 } | |
| 1021 if (access_times[i] > access_times[newest]) | |
| 1022 newest = i; | |
| 1023 if (access_times[i] < access_times[oldest]) | |
| 1024 oldest = i; | |
| 1025 } | |
| 1026 } | |
| 1027 | |
| 1028 if (newest < 0 || oldest < 0) | |
| 1029 return NULL; | |
| 1030 | |
| 1031 EntryImpl* next_entry; | |
| 1032 if (forward) { | |
| 1033 next_entry = entries[newest].get(); | |
| 1034 iterator->list = static_cast<Rankings::List>(newest); | |
| 1035 } else { | |
| 1036 next_entry = entries[oldest].get(); | |
| 1037 iterator->list = static_cast<Rankings::List>(oldest); | |
| 1038 } | |
| 1039 | |
| 1040 *iter = iterator.release(); | |
| 1041 next_entry->AddRef(); | |
| 1042 return next_entry; | |
| 1043 } | |
| 1044 | |
| 1045 void BackendImplV3::AddStorageSize(int32 bytes) { | 957 void BackendImplV3::AddStorageSize(int32 bytes) { |
| 1046 data_->header.num_bytes += bytes; | 958 data_->header.num_bytes += bytes; |
| 1047 DCHECK_GE(data_->header.num_bytes, 0); | 959 DCHECK_GE(data_->header.num_bytes, 0); |
| 1048 } | 960 } |
| 1049 | 961 |
| 1050 void BackendImplV3::SubstractStorageSize(int32 bytes) { | 962 void BackendImplV3::SubstractStorageSize(int32 bytes) { |
| 1051 data_->header.num_bytes -= bytes; | 963 data_->header.num_bytes -= bytes; |
| 1052 DCHECK_GE(data_->header.num_bytes, 0); | 964 DCHECK_GE(data_->header.num_bytes, 0); |
| 1053 } | 965 } |
| 1054 | 966 |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1599 } | 1511 } |
| 1600 | 1512 |
| 1601 void BackendImplV3::OnExternalCacheHit(const std::string& key) { | 1513 void BackendImplV3::OnExternalCacheHit(const std::string& key) { |
| 1602 NOTIMPLEMENTED(); | 1514 NOTIMPLEMENTED(); |
| 1603 } | 1515 } |
| 1604 | 1516 |
| 1605 void BackendImplV3::CleanupCache() { | 1517 void BackendImplV3::CleanupCache() { |
| 1606 } | 1518 } |
| 1607 | 1519 |
| 1608 } // namespace disk_cache | 1520 } // namespace disk_cache |
| OLD | NEW |