Chromium Code Reviews| 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_index.h" | 5 #include "net/disk_cache/simple/simple_index.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/files/file_enumerator.h" | 14 #include "base/files/file_enumerator.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 18 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
| 19 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 20 #include "base/pickle.h" | 20 #include "base/pickle.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_tokenizer.h" | 22 #include "base/strings/string_tokenizer.h" |
| 23 #include "base/task_runner.h" | 23 #include "base/task_runner.h" |
| 24 #include "base/threading/worker_pool.h" | 24 #include "base/threading/worker_pool.h" |
| 25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "base/trace_event/memory_usage_estimator.h" | |
| 26 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 27 #include "net/disk_cache/simple/simple_entry_format.h" | 28 #include "net/disk_cache/simple/simple_entry_format.h" |
| 28 #include "net/disk_cache/simple/simple_histogram_macros.h" | 29 #include "net/disk_cache/simple/simple_histogram_macros.h" |
| 29 #include "net/disk_cache/simple/simple_index_delegate.h" | 30 #include "net/disk_cache/simple/simple_index_delegate.h" |
| 30 #include "net/disk_cache/simple/simple_index_file.h" | 31 #include "net/disk_cache/simple/simple_index_file.h" |
| 31 #include "net/disk_cache/simple/simple_synchronous_entry.h" | 32 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
| 32 #include "net/disk_cache/simple/simple_util.h" | 33 #include "net/disk_cache/simple/simple_util.h" |
| 33 | 34 |
| 34 #if defined(OS_POSIX) | 35 #if defined(OS_POSIX) |
| 35 #include <sys/stat.h> | 36 #include <sys/stat.h> |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 int64_t tmp_last_used_time; | 133 int64_t tmp_last_used_time; |
| 133 uint64_t tmp_entry_size; | 134 uint64_t tmp_entry_size; |
| 134 if (!it->ReadInt64(&tmp_last_used_time) || !it->ReadUInt64(&tmp_entry_size) || | 135 if (!it->ReadInt64(&tmp_last_used_time) || !it->ReadUInt64(&tmp_entry_size) || |
| 135 tmp_entry_size > std::numeric_limits<decltype(entry_size_)>::max()) | 136 tmp_entry_size > std::numeric_limits<decltype(entry_size_)>::max()) |
| 136 return false; | 137 return false; |
| 137 SetLastUsedTime(base::Time::FromInternalValue(tmp_last_used_time)); | 138 SetLastUsedTime(base::Time::FromInternalValue(tmp_last_used_time)); |
| 138 entry_size_ = static_cast<uint32_t>(tmp_entry_size); | 139 entry_size_ = static_cast<uint32_t>(tmp_entry_size); |
| 139 return true; | 140 return true; |
| 140 } | 141 } |
| 141 | 142 |
| 143 size_t EntryMetadata::EstimateMemoryUsage() const { | |
| 144 return 0; | |
| 145 } | |
| 146 | |
| 142 SimpleIndex::SimpleIndex( | 147 SimpleIndex::SimpleIndex( |
| 143 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, | 148 const scoped_refptr<base::SingleThreadTaskRunner>& io_thread, |
| 144 SimpleIndexDelegate* delegate, | 149 SimpleIndexDelegate* delegate, |
| 145 net::CacheType cache_type, | 150 net::CacheType cache_type, |
| 146 std::unique_ptr<SimpleIndexFile> index_file) | 151 std::unique_ptr<SimpleIndexFile> index_file) |
| 147 : delegate_(delegate), | 152 : delegate_(delegate), |
| 148 cache_type_(cache_type), | 153 cache_type_(cache_type), |
| 149 cache_size_(0), | 154 cache_size_(0), |
| 150 max_size_(0), | 155 max_size_(0), |
| 151 high_watermark_(0), | 156 high_watermark_(0), |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 uint64_t size = 0; | 266 uint64_t size = 0; |
| 262 for (const auto& entry : entries_set_) { | 267 for (const auto& entry : entries_set_) { |
| 263 const EntryMetadata& metadata = entry.second; | 268 const EntryMetadata& metadata = entry.second; |
| 264 base::Time entry_time = metadata.GetLastUsedTime(); | 269 base::Time entry_time = metadata.GetLastUsedTime(); |
| 265 if (initial_time <= entry_time && entry_time < end_time) | 270 if (initial_time <= entry_time && entry_time < end_time) |
| 266 size += metadata.GetEntrySize(); | 271 size += metadata.GetEntrySize(); |
| 267 } | 272 } |
| 268 return size; | 273 return size; |
| 269 } | 274 } |
| 270 | 275 |
| 276 size_t SimpleIndex::EstimateMemoryUsage() const { | |
| 277 return base::trace_event::EstimateMemoryUsage(entries_set_); | |
|
ssid
2017/01/31 22:24:19
Do we need a todo here for other objects here, lik
xunjieli
2017/02/01 01:15:52
I added |removed_entries_|. SimpleIndexFile doesn'
| |
| 278 } | |
| 279 | |
| 271 void SimpleIndex::Insert(uint64_t entry_hash) { | 280 void SimpleIndex::Insert(uint64_t entry_hash) { |
| 272 DCHECK(io_thread_checker_.CalledOnValidThread()); | 281 DCHECK(io_thread_checker_.CalledOnValidThread()); |
| 273 // Upon insert we don't know yet the size of the entry. | 282 // Upon insert we don't know yet the size of the entry. |
| 274 // It will be updated later when the SimpleEntryImpl finishes opening or | 283 // It will be updated later when the SimpleEntryImpl finishes opening or |
| 275 // creating the new entry, and then UpdateEntrySize will be called. | 284 // creating the new entry, and then UpdateEntrySize will be called. |
| 276 InsertInEntrySet(entry_hash, EntryMetadata(base::Time::Now(), 0u), | 285 InsertInEntrySet(entry_hash, EntryMetadata(base::Time::Now(), 0u), |
| 277 &entries_set_); | 286 &entries_set_); |
| 278 if (!initialized_) | 287 if (!initialized_) |
| 279 removed_entries_.erase(entry_hash); | 288 removed_entries_.erase(entry_hash); |
| 280 PostponeWritingToDisk(); | 289 PostponeWritingToDisk(); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 start - last_write_to_disk_); | 527 start - last_write_to_disk_); |
| 519 } | 528 } |
| 520 } | 529 } |
| 521 last_write_to_disk_ = start; | 530 last_write_to_disk_ = start; |
| 522 | 531 |
| 523 index_file_->WriteToDisk(reason, entries_set_, cache_size_, start, | 532 index_file_->WriteToDisk(reason, entries_set_, cache_size_, start, |
| 524 app_on_background_, base::Closure()); | 533 app_on_background_, base::Closure()); |
| 525 } | 534 } |
| 526 | 535 |
| 527 } // namespace disk_cache | 536 } // namespace disk_cache |
| OLD | NEW |