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.h" | 5 #include "net/disk_cache/blockfile/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/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Seems like ~240 MB correspond to less than 50k entries for 99% of the people. | 46 // Seems like ~240 MB correspond to less than 50k entries for 99% of the people. |
47 // Note that the actual target is to keep the index table load factor under 55% | 47 // Note that the actual target is to keep the index table load factor under 55% |
48 // for most users. | 48 // for most users. |
49 const int k64kEntriesStore = 240 * 1000 * 1000; | 49 const int k64kEntriesStore = 240 * 1000 * 1000; |
50 const int kBaseTableLen = 64 * 1024; | 50 const int kBaseTableLen = 64 * 1024; |
51 | 51 |
52 // Avoid trimming the cache for the first 5 minutes (10 timer ticks). | 52 // Avoid trimming the cache for the first 5 minutes (10 timer ticks). |
53 const int kTrimDelay = 10; | 53 const int kTrimDelay = 10; |
54 | 54 |
| 55 class BackendEnumerationState : public disk_cache::Backend::EnumerationState { |
| 56 public: |
| 57 explicit BackendEnumerationState( |
| 58 base::WeakPtr<disk_cache::InFlightBackendIO> background_queue) |
| 59 : background_queue_(background_queue), |
| 60 data_(NULL) {} |
| 61 |
| 62 virtual ~BackendEnumerationState() { |
| 63 if (background_queue_) |
| 64 background_queue_->EndEnumeration(*data()); |
| 65 } |
| 66 |
| 67 void** data() { return &data_; } |
| 68 |
| 69 private: |
| 70 base::WeakPtr<disk_cache::InFlightBackendIO> background_queue_; |
| 71 void* data_; |
| 72 }; |
| 73 |
55 int DesiredIndexTableLen(int32 storage_size) { | 74 int DesiredIndexTableLen(int32 storage_size) { |
56 if (storage_size <= k64kEntriesStore) | 75 if (storage_size <= k64kEntriesStore) |
57 return kBaseTableLen; | 76 return kBaseTableLen; |
58 if (storage_size <= k64kEntriesStore * 2) | 77 if (storage_size <= k64kEntriesStore * 2) |
59 return kBaseTableLen * 2; | 78 return kBaseTableLen * 2; |
60 if (storage_size <= k64kEntriesStore * 4) | 79 if (storage_size <= k64kEntriesStore * 4) |
61 return kBaseTableLen * 4; | 80 return kBaseTableLen * 4; |
62 if (storage_size <= k64kEntriesStore * 8) | 81 if (storage_size <= k64kEntriesStore * 8) |
63 return kBaseTableLen * 8; | 82 return kBaseTableLen * 8; |
64 | 83 |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 } | 340 } |
322 block_files_.CloseFiles(); | 341 block_files_.CloseFiles(); |
323 FlushIndex(); | 342 FlushIndex(); |
324 index_ = NULL; | 343 index_ = NULL; |
325 ptr_factory_.InvalidateWeakPtrs(); | 344 ptr_factory_.InvalidateWeakPtrs(); |
326 done_.Signal(); | 345 done_.Signal(); |
327 } | 346 } |
328 | 347 |
329 // ------------------------------------------------------------------------ | 348 // ------------------------------------------------------------------------ |
330 | 349 |
331 int BackendImpl::OpenPrevEntry(void** iter, Entry** prev_entry, | 350 int BackendImpl::OpenPrevEntry(Iterator* iter, Entry** prev_entry, |
332 const CompletionCallback& callback) { | 351 const CompletionCallback& callback) { |
333 DCHECK(!callback.is_null()); | 352 DCHECK(!callback.is_null()); |
334 background_queue_.OpenPrevEntry(iter, prev_entry, callback); | 353 if (!*iter) |
| 354 iter->reset(new BackendEnumerationState(GetBackgroundQueue())); |
| 355 BackendEnumerationState* state = |
| 356 static_cast<BackendEnumerationState*>(iter->get()); |
| 357 |
| 358 background_queue_.OpenPrevEntry(state->data(), prev_entry, callback); |
335 return net::ERR_IO_PENDING; | 359 return net::ERR_IO_PENDING; |
336 } | 360 } |
337 | 361 |
338 int BackendImpl::SyncOpenEntry(const std::string& key, Entry** entry) { | 362 int BackendImpl::SyncOpenEntry(const std::string& key, Entry** entry) { |
339 DCHECK(entry); | 363 DCHECK(entry); |
340 *entry = OpenEntryImpl(key); | 364 *entry = OpenEntryImpl(key); |
341 return (*entry) ? net::OK : net::ERR_FAILED; | 365 return (*entry) ? net::OK : net::ERR_FAILED; |
342 } | 366 } |
343 | 367 |
344 int BackendImpl::SyncCreateEntry(const std::string& key, Entry** entry) { | 368 int BackendImpl::SyncCreateEntry(const std::string& key, Entry** entry) { |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 return net::ERR_IO_PENDING; | 1216 return net::ERR_IO_PENDING; |
1193 } | 1217 } |
1194 | 1218 |
1195 int BackendImpl::DoomEntriesSince(const base::Time initial_time, | 1219 int BackendImpl::DoomEntriesSince(const base::Time initial_time, |
1196 const CompletionCallback& callback) { | 1220 const CompletionCallback& callback) { |
1197 DCHECK(!callback.is_null()); | 1221 DCHECK(!callback.is_null()); |
1198 background_queue_.DoomEntriesSince(initial_time, callback); | 1222 background_queue_.DoomEntriesSince(initial_time, callback); |
1199 return net::ERR_IO_PENDING; | 1223 return net::ERR_IO_PENDING; |
1200 } | 1224 } |
1201 | 1225 |
1202 int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry, | 1226 int BackendImpl::OpenNextEntry(Iterator* iter, Entry** next_entry, |
1203 const CompletionCallback& callback) { | 1227 const CompletionCallback& callback) { |
| 1228 // TODO(gavinp): Remove all void** iter from cache. |
1204 DCHECK(!callback.is_null()); | 1229 DCHECK(!callback.is_null()); |
1205 background_queue_.OpenNextEntry(iter, next_entry, callback); | 1230 if (!*iter) |
| 1231 iter->reset(new BackendEnumerationState(GetBackgroundQueue())); |
| 1232 BackendEnumerationState* state = |
| 1233 static_cast<BackendEnumerationState*>(iter->get()); |
| 1234 |
| 1235 background_queue_.OpenNextEntry(state->data(), next_entry, callback); |
1206 return net::ERR_IO_PENDING; | 1236 return net::ERR_IO_PENDING; |
1207 } | 1237 } |
1208 | 1238 |
1209 void BackendImpl::EndEnumeration(void** iter) { | |
1210 background_queue_.EndEnumeration(*iter); | |
1211 *iter = NULL; | |
1212 } | |
1213 | |
1214 void BackendImpl::GetStats(StatsItems* stats) { | 1239 void BackendImpl::GetStats(StatsItems* stats) { |
1215 if (disabled_) | 1240 if (disabled_) |
1216 return; | 1241 return; |
1217 | 1242 |
1218 std::pair<std::string, std::string> item; | 1243 std::pair<std::string, std::string> item; |
1219 | 1244 |
1220 item.first = "Entries"; | 1245 item.first = "Entries"; |
1221 item.second = base::StringPrintf("%d", data_->header.num_entries); | 1246 item.second = base::StringPrintf("%d", data_->header.num_entries); |
1222 stats->push_back(item); | 1247 stats->push_back(item); |
1223 | 1248 |
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2120 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
2096 total_memory = kMaxBuffersSize; | 2121 total_memory = kMaxBuffersSize; |
2097 | 2122 |
2098 done = true; | 2123 done = true; |
2099 } | 2124 } |
2100 | 2125 |
2101 return static_cast<int>(total_memory); | 2126 return static_cast<int>(total_memory); |
2102 } | 2127 } |
2103 | 2128 |
2104 } // namespace disk_cache | 2129 } // namespace disk_cache |
OLD | NEW |