OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 CleanupCache(); | 428 CleanupCache(); |
429 } else { | 429 } else { |
430 background_queue_.background_thread()->PostTask(FROM_HERE, | 430 background_queue_.background_thread()->PostTask(FROM_HERE, |
431 new FinalCleanup(this)); | 431 new FinalCleanup(this)); |
432 done_.Wait(); | 432 done_.Wait(); |
433 } | 433 } |
434 } | 434 } |
435 | 435 |
436 // ------------------------------------------------------------------------ | 436 // ------------------------------------------------------------------------ |
437 | 437 |
438 int32 BackendImpl::GetEntryCount() const { | |
439 if (!index_ || disabled_) | |
440 return 0; | |
441 // num_entries includes entries already evicted. | |
442 int32 not_deleted = data_->header.num_entries - | |
443 data_->header.lru.sizes[Rankings::DELETED]; | |
444 | |
445 if (not_deleted < 0) { | |
446 NOTREACHED(); | |
447 not_deleted = 0; | |
448 } | |
449 | |
450 return not_deleted; | |
451 } | |
452 | |
453 int BackendImpl::OpenEntry(const std::string& key, Entry** entry, | |
454 CompletionCallback* callback) { | |
455 DCHECK(callback); | |
456 background_queue_.OpenEntry(key, entry, callback); | |
457 return net::ERR_IO_PENDING; | |
458 } | |
459 | |
460 int BackendImpl::CreateEntry(const std::string& key, Entry** entry, | |
461 CompletionCallback* callback) { | |
462 DCHECK(callback); | |
463 background_queue_.CreateEntry(key, entry, callback); | |
464 return net::ERR_IO_PENDING; | |
465 } | |
466 | |
467 int BackendImpl::DoomEntry(const std::string& key, | |
468 CompletionCallback* callback) { | |
469 DCHECK(callback); | |
470 background_queue_.DoomEntry(key, callback); | |
471 return net::ERR_IO_PENDING; | |
472 } | |
473 | |
474 int BackendImpl::DoomAllEntries(CompletionCallback* callback) { | |
475 DCHECK(callback); | |
476 background_queue_.DoomAllEntries(callback); | |
477 return net::ERR_IO_PENDING; | |
478 } | |
479 | |
480 int BackendImpl::DoomEntriesBetween(const base::Time initial_time, | |
481 const base::Time end_time, | |
482 CompletionCallback* callback) { | |
483 DCHECK(callback); | |
484 background_queue_.DoomEntriesBetween(initial_time, end_time, callback); | |
485 return net::ERR_IO_PENDING; | |
486 } | |
487 | |
488 int BackendImpl::DoomEntriesSince(const base::Time initial_time, | |
489 CompletionCallback* callback) { | |
490 DCHECK(callback); | |
491 background_queue_.DoomEntriesSince(initial_time, callback); | |
492 return net::ERR_IO_PENDING; | |
493 } | |
494 | |
495 int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry, | |
496 CompletionCallback* callback) { | |
497 DCHECK(callback); | |
498 background_queue_.OpenNextEntry(iter, next_entry, callback); | |
499 return net::ERR_IO_PENDING; | |
500 } | |
501 | |
502 void BackendImpl::EndEnumeration(void** iter) { | |
503 background_queue_.EndEnumeration(*iter); | |
504 *iter = NULL; | |
505 } | |
506 | |
507 void BackendImpl::GetStats(StatsItems* stats) { | |
508 if (disabled_) | |
509 return; | |
510 | |
511 std::pair<std::string, std::string> item; | |
512 | |
513 item.first = "Entries"; | |
514 item.second = base::StringPrintf("%d", data_->header.num_entries); | |
515 stats->push_back(item); | |
516 | |
517 item.first = "Pending IO"; | |
518 item.second = base::StringPrintf("%d", num_pending_io_); | |
519 stats->push_back(item); | |
520 | |
521 item.first = "Max size"; | |
522 item.second = base::StringPrintf("%d", max_size_); | |
523 stats->push_back(item); | |
524 | |
525 item.first = "Current size"; | |
526 item.second = base::StringPrintf("%d", data_->header.num_bytes); | |
527 stats->push_back(item); | |
528 | |
529 stats_.GetItems(stats); | |
530 } | |
531 | |
532 // ------------------------------------------------------------------------ | |
533 | |
534 int BackendImpl::SyncInit() { | 438 int BackendImpl::SyncInit() { |
535 DCHECK(!init_); | 439 DCHECK(!init_); |
536 if (init_) | 440 if (init_) |
537 return net::ERR_FAILED; | 441 return net::ERR_FAILED; |
538 | 442 |
539 bool create_files = false; | 443 bool create_files = false; |
540 if (!InitBackingStore(&create_files)) { | 444 if (!InitBackingStore(&create_files)) { |
541 ReportError(ERR_STORAGE_ERROR); | 445 ReportError(ERR_STORAGE_ERROR); |
542 return net::ERR_FAILED; | 446 return net::ERR_FAILED; |
543 } | 447 } |
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 if (num_entries != data_->header.num_entries) { | 1252 if (num_entries != data_->header.num_entries) { |
1349 LOG(ERROR) << "Number of entries mismatch"; | 1253 LOG(ERROR) << "Number of entries mismatch"; |
1350 return ERR_NUM_ENTRIES_MISMATCH; | 1254 return ERR_NUM_ENTRIES_MISMATCH; |
1351 } | 1255 } |
1352 | 1256 |
1353 return CheckAllEntries(); | 1257 return CheckAllEntries(); |
1354 } | 1258 } |
1355 | 1259 |
1356 // ------------------------------------------------------------------------ | 1260 // ------------------------------------------------------------------------ |
1357 | 1261 |
| 1262 int32 BackendImpl::GetEntryCount() const { |
| 1263 if (!index_ || disabled_) |
| 1264 return 0; |
| 1265 // num_entries includes entries already evicted. |
| 1266 int32 not_deleted = data_->header.num_entries - |
| 1267 data_->header.lru.sizes[Rankings::DELETED]; |
| 1268 |
| 1269 if (not_deleted < 0) { |
| 1270 NOTREACHED(); |
| 1271 not_deleted = 0; |
| 1272 } |
| 1273 |
| 1274 return not_deleted; |
| 1275 } |
| 1276 |
| 1277 int BackendImpl::OpenEntry(const std::string& key, Entry** entry, |
| 1278 CompletionCallback* callback) { |
| 1279 DCHECK(callback); |
| 1280 background_queue_.OpenEntry(key, entry, callback); |
| 1281 return net::ERR_IO_PENDING; |
| 1282 } |
| 1283 |
| 1284 int BackendImpl::CreateEntry(const std::string& key, Entry** entry, |
| 1285 CompletionCallback* callback) { |
| 1286 DCHECK(callback); |
| 1287 background_queue_.CreateEntry(key, entry, callback); |
| 1288 return net::ERR_IO_PENDING; |
| 1289 } |
| 1290 |
| 1291 int BackendImpl::DoomEntry(const std::string& key, |
| 1292 CompletionCallback* callback) { |
| 1293 DCHECK(callback); |
| 1294 background_queue_.DoomEntry(key, callback); |
| 1295 return net::ERR_IO_PENDING; |
| 1296 } |
| 1297 |
| 1298 int BackendImpl::DoomAllEntries(CompletionCallback* callback) { |
| 1299 DCHECK(callback); |
| 1300 background_queue_.DoomAllEntries(callback); |
| 1301 return net::ERR_IO_PENDING; |
| 1302 } |
| 1303 |
| 1304 int BackendImpl::DoomEntriesBetween(const base::Time initial_time, |
| 1305 const base::Time end_time, |
| 1306 CompletionCallback* callback) { |
| 1307 DCHECK(callback); |
| 1308 background_queue_.DoomEntriesBetween(initial_time, end_time, callback); |
| 1309 return net::ERR_IO_PENDING; |
| 1310 } |
| 1311 |
| 1312 int BackendImpl::DoomEntriesSince(const base::Time initial_time, |
| 1313 CompletionCallback* callback) { |
| 1314 DCHECK(callback); |
| 1315 background_queue_.DoomEntriesSince(initial_time, callback); |
| 1316 return net::ERR_IO_PENDING; |
| 1317 } |
| 1318 |
| 1319 int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry, |
| 1320 CompletionCallback* callback) { |
| 1321 DCHECK(callback); |
| 1322 background_queue_.OpenNextEntry(iter, next_entry, callback); |
| 1323 return net::ERR_IO_PENDING; |
| 1324 } |
| 1325 |
| 1326 void BackendImpl::EndEnumeration(void** iter) { |
| 1327 background_queue_.EndEnumeration(*iter); |
| 1328 *iter = NULL; |
| 1329 } |
| 1330 |
| 1331 void BackendImpl::GetStats(StatsItems* stats) { |
| 1332 if (disabled_) |
| 1333 return; |
| 1334 |
| 1335 std::pair<std::string, std::string> item; |
| 1336 |
| 1337 item.first = "Entries"; |
| 1338 item.second = base::StringPrintf("%d", data_->header.num_entries); |
| 1339 stats->push_back(item); |
| 1340 |
| 1341 item.first = "Pending IO"; |
| 1342 item.second = base::StringPrintf("%d", num_pending_io_); |
| 1343 stats->push_back(item); |
| 1344 |
| 1345 item.first = "Max size"; |
| 1346 item.second = base::StringPrintf("%d", max_size_); |
| 1347 stats->push_back(item); |
| 1348 |
| 1349 item.first = "Current size"; |
| 1350 item.second = base::StringPrintf("%d", data_->header.num_bytes); |
| 1351 stats->push_back(item); |
| 1352 |
| 1353 stats_.GetItems(stats); |
| 1354 } |
| 1355 |
| 1356 // ------------------------------------------------------------------------ |
| 1357 |
1358 // We just created a new file so we're going to write the header and set the | 1358 // We just created a new file so we're going to write the header and set the |
1359 // file length to include the hash table (zero filled). | 1359 // file length to include the hash table (zero filled). |
1360 bool BackendImpl::CreateBackingStore(disk_cache::File* file) { | 1360 bool BackendImpl::CreateBackingStore(disk_cache::File* file) { |
1361 AdjustMaxCacheSize(0); | 1361 AdjustMaxCacheSize(0); |
1362 | 1362 |
1363 IndexHeader header; | 1363 IndexHeader header; |
1364 header.table_len = DesiredIndexTableLen(max_size_); | 1364 header.table_len = DesiredIndexTableLen(max_size_); |
1365 | 1365 |
1366 // We need file version 2.1 for the new eviction algorithm. | 1366 // We need file version 2.1 for the new eviction algorithm. |
1367 if (new_eviction_) | 1367 if (new_eviction_) |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 if (total_memory > kMaxBuffersSize || total_memory <= 0) | 2095 if (total_memory > kMaxBuffersSize || total_memory <= 0) |
2096 total_memory = kMaxBuffersSize; | 2096 total_memory = kMaxBuffersSize; |
2097 | 2097 |
2098 done = true; | 2098 done = true; |
2099 } | 2099 } |
2100 | 2100 |
2101 return static_cast<int>(total_memory); | 2101 return static_cast<int>(total_memory); |
2102 } | 2102 } |
2103 | 2103 |
2104 } // namespace disk_cache | 2104 } // namespace disk_cache |
OLD | NEW |