OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/simple/simple_synchronous_entry.h" | 5 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <functional> | 9 #include <functional> |
10 #include <limits> | 10 #include <limits> |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 return false; | 513 return false; |
514 } | 514 } |
515 } | 515 } |
516 | 516 |
517 have_open_files_ = true; | 517 have_open_files_ = true; |
518 if (create) { | 518 if (create) { |
519 out_entry_stat->last_modified = out_entry_stat->last_used = Time::Now(); | 519 out_entry_stat->last_modified = out_entry_stat->last_used = Time::Now(); |
520 for (int i = 0; i < kSimpleEntryFileCount; ++i) | 520 for (int i = 0; i < kSimpleEntryFileCount; ++i) |
521 out_entry_stat->data_size[i] = 0; | 521 out_entry_stat->data_size[i] = 0; |
522 } else { | 522 } else { |
| 523 base::TimeDelta entry_age = base::Time::Now() - base::Time::UnixEpoch(); |
523 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 524 for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
524 PlatformFileInfo file_info; | 525 PlatformFileInfo file_info; |
525 bool success = GetPlatformFileInfo(files_[i], &file_info); | 526 bool success = GetPlatformFileInfo(files_[i], &file_info); |
526 base::Time file_last_modified; | 527 base::Time file_last_modified; |
527 if (!success) { | 528 if (!success) { |
528 DLOG(WARNING) << "Could not get platform file info."; | 529 DLOG(WARNING) << "Could not get platform file info."; |
529 continue; | 530 continue; |
530 } | 531 } |
531 out_entry_stat->last_used = file_info.last_accessed; | 532 out_entry_stat->last_used = file_info.last_accessed; |
532 if (simple_util::GetMTime(path_, &file_last_modified)) | 533 if (simple_util::GetMTime(path_, &file_last_modified)) |
533 out_entry_stat->last_modified = file_last_modified; | 534 out_entry_stat->last_modified = file_last_modified; |
534 else | 535 else |
535 out_entry_stat->last_modified = file_info.last_modified; | 536 out_entry_stat->last_modified = file_info.last_modified; |
536 | 537 |
537 base::TimeDelta entry_age = | 538 base::TimeDelta stream_age = |
538 base::Time::Now() - out_entry_stat->last_modified; | 539 base::Time::Now() - out_entry_stat->last_modified; |
539 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, | 540 if (stream_age < entry_age) |
540 "SyncOpenEntryAge", cache_type_, | 541 entry_age = stream_age; |
541 entry_age.InHours(), 1, 1000, 50); | |
542 | 542 |
543 // Keep the file size in |data size_| briefly until the key is initialized | 543 // Keep the file size in |data size_| briefly until the key is initialized |
544 // properly. | 544 // properly. |
545 out_entry_stat->data_size[i] = file_info.size; | 545 out_entry_stat->data_size[i] = file_info.size; |
546 } | 546 } |
| 547 SIMPLE_CACHE_UMA(CUSTOM_COUNTS, |
| 548 "SyncOpenEntryAge", cache_type_, |
| 549 entry_age.InHours(), 1, 1000, 50); |
547 } | 550 } |
548 | 551 |
549 return true; | 552 return true; |
550 } | 553 } |
551 | 554 |
552 void SimpleSynchronousEntry::CloseFiles() { | 555 void SimpleSynchronousEntry::CloseFiles() { |
553 for (int i = 0; i < kSimpleEntryFileCount; ++i) { | 556 for (int i = 0; i < kSimpleEntryFileCount; ++i) { |
554 DCHECK_NE(kInvalidPlatformFileValue, files_[i]); | 557 DCHECK_NE(kInvalidPlatformFileValue, files_[i]); |
555 bool did_close = ClosePlatformFile(files_[i]); | 558 bool did_close = ClosePlatformFile(files_[i]); |
556 DCHECK(did_close); | 559 DCHECK(did_close); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 initialized_ = true; | 658 initialized_ = true; |
656 return net::OK; | 659 return net::OK; |
657 } | 660 } |
658 | 661 |
659 void SimpleSynchronousEntry::Doom() const { | 662 void SimpleSynchronousEntry::Doom() const { |
660 // TODO(gavinp): Consider if we should guard against redundant Doom() calls. | 663 // TODO(gavinp): Consider if we should guard against redundant Doom() calls. |
661 DeleteFilesForEntryHash(path_, entry_hash_); | 664 DeleteFilesForEntryHash(path_, entry_hash_); |
662 } | 665 } |
663 | 666 |
664 } // namespace disk_cache | 667 } // namespace disk_cache |
OLD | NEW |