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_backend_impl.h" | 5 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 #include <functional> | 9 #include <functional> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "base/macros.h" | 23 #include "base/macros.h" |
| 24 #include "base/metrics/field_trial.h" | 24 #include "base/metrics/field_trial.h" |
| 25 #include "base/metrics/histogram_macros.h" | 25 #include "base/metrics/histogram_macros.h" |
| 26 #include "base/metrics/sparse_histogram.h" | 26 #include "base/metrics/sparse_histogram.h" |
| 27 #include "base/single_thread_task_runner.h" | 27 #include "base/single_thread_task_runner.h" |
| 28 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
| 29 #include "base/task_runner_util.h" | 29 #include "base/task_runner_util.h" |
| 30 #include "base/threading/sequenced_worker_pool.h" | 30 #include "base/threading/sequenced_worker_pool.h" |
| 31 #include "base/threading/thread_task_runner_handle.h" | 31 #include "base/threading/thread_task_runner_handle.h" |
| 32 #include "base/time/time.h" | 32 #include "base/time/time.h" |
| 33 #include "base/trace_event/memory_usage_estimator.h" | |
| 33 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 34 #include "net/disk_cache/cache_util.h" | 35 #include "net/disk_cache/cache_util.h" |
| 35 #include "net/disk_cache/simple/simple_entry_format.h" | 36 #include "net/disk_cache/simple/simple_entry_format.h" |
| 36 #include "net/disk_cache/simple/simple_entry_impl.h" | 37 #include "net/disk_cache/simple/simple_entry_impl.h" |
| 37 #include "net/disk_cache/simple/simple_experiment.h" | 38 #include "net/disk_cache/simple/simple_experiment.h" |
| 38 #include "net/disk_cache/simple/simple_histogram_macros.h" | 39 #include "net/disk_cache/simple/simple_histogram_macros.h" |
| 39 #include "net/disk_cache/simple/simple_index.h" | 40 #include "net/disk_cache/simple/simple_index.h" |
| 40 #include "net/disk_cache/simple/simple_index_file.h" | 41 #include "net/disk_cache/simple/simple_index_file.h" |
| 41 #include "net/disk_cache/simple/simple_synchronous_entry.h" | 42 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
| 42 #include "net/disk_cache/simple/simple_util.h" | 43 #include "net/disk_cache/simple/simple_util.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 if (result == net::OK) { | 198 if (result == net::OK) { |
| 198 SIMPLE_CACHE_UMA(TIMES, "CreationToIndex", cache_type, creation_to_index); | 199 SIMPLE_CACHE_UMA(TIMES, "CreationToIndex", cache_type, creation_to_index); |
| 199 } else { | 200 } else { |
| 200 SIMPLE_CACHE_UMA(TIMES, | 201 SIMPLE_CACHE_UMA(TIMES, |
| 201 "CreationToIndexFail", cache_type, creation_to_index); | 202 "CreationToIndexFail", cache_type, creation_to_index); |
| 202 } | 203 } |
| 203 } | 204 } |
| 204 | 205 |
| 205 } // namespace | 206 } // namespace |
| 206 | 207 |
| 208 // Static function which is called by base::trace_event::EstimateMemoryUsage() | |
| 209 // to estimate the memory of SimpleEntryImpl* type. | |
| 210 // This needs to be in disk_cache namespace. | |
| 211 size_t EstimateMemoryUsage(const SimpleEntryImpl* const& entry_impl) { | |
|
jkarlin
2017/02/24 18:38:09
Have you verified that this actually gets called?
xunjieli
2017/02/24 18:42:17
I verified manually that this is called. (build ch
| |
| 212 return sizeof(SimpleEntryImpl) + entry_impl->EstimateMemoryUsage(); | |
| 213 } | |
| 214 | |
| 207 class SimpleBackendImpl::ActiveEntryProxy | 215 class SimpleBackendImpl::ActiveEntryProxy |
| 208 : public SimpleEntryImpl::ActiveEntryProxy { | 216 : public SimpleEntryImpl::ActiveEntryProxy { |
| 209 public: | 217 public: |
| 210 ~ActiveEntryProxy() override { | 218 ~ActiveEntryProxy() override { |
| 211 if (backend_) { | 219 if (backend_) { |
| 212 DCHECK_EQ(1U, backend_->active_entries_.count(entry_hash_)); | 220 DCHECK_EQ(1U, backend_->active_entries_.count(entry_hash_)); |
| 213 backend_->active_entries_.erase(entry_hash_); | 221 backend_->active_entries_.erase(entry_hash_); |
| 214 } | 222 } |
| 215 } | 223 } |
| 216 | 224 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 std::pair<std::string, std::string> item; | 553 std::pair<std::string, std::string> item; |
| 546 item.first = "Cache type"; | 554 item.first = "Cache type"; |
| 547 item.second = "Simple Cache"; | 555 item.second = "Simple Cache"; |
| 548 stats->push_back(item); | 556 stats->push_back(item); |
| 549 } | 557 } |
| 550 | 558 |
| 551 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | 559 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
| 552 index_->UseIfExists(simple_util::GetEntryHashKey(key)); | 560 index_->UseIfExists(simple_util::GetEntryHashKey(key)); |
| 553 } | 561 } |
| 554 | 562 |
| 563 size_t SimpleBackendImpl::EstimateMemoryUsage() const { | |
| 564 // TODO(xunjieli): crbug.com/669108. Track |entries_pending_doom_| once | |
| 565 // base::Closure is suppported in memory_usage_estimator.h. | |
| 566 return base::trace_event::EstimateMemoryUsage(index_) + | |
| 567 base::trace_event::EstimateMemoryUsage(active_entries_); | |
| 568 } | |
| 569 | |
| 555 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, | 570 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, |
| 556 const DiskStatResult& result) { | 571 const DiskStatResult& result) { |
| 557 if (result.net_error == net::OK) { | 572 if (result.net_error == net::OK) { |
| 558 index_->SetMaxSize(result.max_size); | 573 index_->SetMaxSize(result.max_size); |
| 559 index_->Initialize(result.cache_dir_mtime); | 574 index_->Initialize(result.cache_dir_mtime); |
| 560 } | 575 } |
| 561 callback.Run(result.net_error); | 576 callback.Run(result.net_error); |
| 562 } | 577 } |
| 563 | 578 |
| 564 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, | 579 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 } | 762 } |
| 748 | 763 |
| 749 // static | 764 // static |
| 750 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 765 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
| 751 // We only need to do this if we there is an active task runner. | 766 // We only need to do this if we there is an active task runner. |
| 752 if (base::ThreadTaskRunnerHandle::IsSet()) | 767 if (base::ThreadTaskRunnerHandle::IsSet()) |
| 753 g_sequenced_worker_pool.Get().FlushForTesting(); | 768 g_sequenced_worker_pool.Get().FlushForTesting(); |
| 754 } | 769 } |
| 755 | 770 |
| 756 } // namespace disk_cache | 771 } // namespace disk_cache |
| OLD | NEW |