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_allocator_dump.h" |
| 34 #include "base/trace_event/memory_usage_estimator.h" |
| 35 #include "base/trace_event/process_memory_dump.h" |
33 #include "net/base/net_errors.h" | 36 #include "net/base/net_errors.h" |
34 #include "net/disk_cache/cache_util.h" | 37 #include "net/disk_cache/cache_util.h" |
35 #include "net/disk_cache/simple/simple_entry_format.h" | 38 #include "net/disk_cache/simple/simple_entry_format.h" |
36 #include "net/disk_cache/simple/simple_entry_impl.h" | 39 #include "net/disk_cache/simple/simple_entry_impl.h" |
37 #include "net/disk_cache/simple/simple_experiment.h" | 40 #include "net/disk_cache/simple/simple_experiment.h" |
38 #include "net/disk_cache/simple/simple_histogram_macros.h" | 41 #include "net/disk_cache/simple/simple_histogram_macros.h" |
39 #include "net/disk_cache/simple/simple_index.h" | 42 #include "net/disk_cache/simple/simple_index.h" |
40 #include "net/disk_cache/simple/simple_index_file.h" | 43 #include "net/disk_cache/simple/simple_index_file.h" |
41 #include "net/disk_cache/simple/simple_synchronous_entry.h" | 44 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
42 #include "net/disk_cache/simple/simple_util.h" | 45 #include "net/disk_cache/simple/simple_util.h" |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 std::pair<std::string, std::string> item; | 548 std::pair<std::string, std::string> item; |
546 item.first = "Cache type"; | 549 item.first = "Cache type"; |
547 item.second = "Simple Cache"; | 550 item.second = "Simple Cache"; |
548 stats->push_back(item); | 551 stats->push_back(item); |
549 } | 552 } |
550 | 553 |
551 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | 554 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
552 index_->UseIfExists(simple_util::GetEntryHashKey(key)); | 555 index_->UseIfExists(simple_util::GetEntryHashKey(key)); |
553 } | 556 } |
554 | 557 |
| 558 void SimpleBackendImpl::DumpMemoryStats( |
| 559 base::trace_event::ProcessMemoryDump* pmd, |
| 560 const std::string& parent_absolute_name) const { |
| 561 if (!index_) |
| 562 return; |
| 563 size_t memory_estimate = base::trace_event::EstimateMemoryUsage(index_); |
| 564 base::trace_event::MemoryAllocatorDump* dump = |
| 565 pmd->CreateAllocatorDump(parent_absolute_name + "/simple_cache"); |
| 566 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 567 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 568 memory_estimate); |
| 569 } |
| 570 |
555 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, | 571 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, |
556 const DiskStatResult& result) { | 572 const DiskStatResult& result) { |
557 if (result.net_error == net::OK) { | 573 if (result.net_error == net::OK) { |
558 index_->SetMaxSize(result.max_size); | 574 index_->SetMaxSize(result.max_size); |
559 index_->Initialize(result.cache_dir_mtime); | 575 index_->Initialize(result.cache_dir_mtime); |
560 } | 576 } |
561 callback.Run(result.net_error); | 577 callback.Run(result.net_error); |
562 } | 578 } |
563 | 579 |
564 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, | 580 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 } | 763 } |
748 | 764 |
749 // static | 765 // static |
750 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 766 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
751 // We only need to do this if we there is an active task runner. | 767 // We only need to do this if we there is an active task runner. |
752 if (base::ThreadTaskRunnerHandle::IsSet()) | 768 if (base::ThreadTaskRunnerHandle::IsSet()) |
753 g_sequenced_worker_pool.Get().FlushForTesting(); | 769 g_sequenced_worker_pool.Get().FlushForTesting(); |
754 } | 770 } |
755 | 771 |
756 } // namespace disk_cache | 772 } // namespace disk_cache |
OLD | NEW |