| 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 13 matching lines...) Expand all Loading... |
| 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 "base/trace_event/memory_usage_estimator.h" |
| 34 #include "base/trace_event/process_memory_dump.h" |
| 34 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 35 #include "net/disk_cache/cache_util.h" | 36 #include "net/disk_cache/cache_util.h" |
| 36 #include "net/disk_cache/simple/simple_entry_format.h" | 37 #include "net/disk_cache/simple/simple_entry_format.h" |
| 37 #include "net/disk_cache/simple/simple_entry_impl.h" | 38 #include "net/disk_cache/simple/simple_entry_impl.h" |
| 38 #include "net/disk_cache/simple/simple_experiment.h" | 39 #include "net/disk_cache/simple/simple_experiment.h" |
| 39 #include "net/disk_cache/simple/simple_histogram_macros.h" | 40 #include "net/disk_cache/simple/simple_histogram_macros.h" |
| 40 #include "net/disk_cache/simple/simple_index.h" | 41 #include "net/disk_cache/simple/simple_index.h" |
| 41 #include "net/disk_cache/simple/simple_index_file.h" | 42 #include "net/disk_cache/simple/simple_index_file.h" |
| 42 #include "net/disk_cache/simple/simple_synchronous_entry.h" | 43 #include "net/disk_cache/simple/simple_synchronous_entry.h" |
| 43 #include "net/disk_cache/simple/simple_util.h" | 44 #include "net/disk_cache/simple/simple_util.h" |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 std::pair<std::string, std::string> item; | 554 std::pair<std::string, std::string> item; |
| 554 item.first = "Cache type"; | 555 item.first = "Cache type"; |
| 555 item.second = "Simple Cache"; | 556 item.second = "Simple Cache"; |
| 556 stats->push_back(item); | 557 stats->push_back(item); |
| 557 } | 558 } |
| 558 | 559 |
| 559 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | 560 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
| 560 index_->UseIfExists(simple_util::GetEntryHashKey(key)); | 561 index_->UseIfExists(simple_util::GetEntryHashKey(key)); |
| 561 } | 562 } |
| 562 | 563 |
| 563 size_t SimpleBackendImpl::EstimateMemoryUsage() const { | 564 size_t SimpleBackendImpl::DumpMemoryStats( |
| 565 base::trace_event::ProcessMemoryDump* pmd, |
| 566 const std::string& parent_absolute_name) const { |
| 567 base::trace_event::MemoryAllocatorDump* dump = |
| 568 pmd->CreateAllocatorDump(parent_absolute_name + "/simple_backend"); |
| 569 |
| 570 size_t size = base::trace_event::EstimateMemoryUsage(index_) + |
| 571 base::trace_event::EstimateMemoryUsage(active_entries_); |
| 564 // TODO(xunjieli): crbug.com/669108. Track |entries_pending_doom_| once | 572 // TODO(xunjieli): crbug.com/669108. Track |entries_pending_doom_| once |
| 565 // base::Closure is suppported in memory_usage_estimator.h. | 573 // base::Closure is suppported in memory_usage_estimator.h. |
| 566 return base::trace_event::EstimateMemoryUsage(index_) + | 574 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 567 base::trace_event::EstimateMemoryUsage(active_entries_); | 575 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); |
| 576 return size; |
| 568 } | 577 } |
| 569 | 578 |
| 570 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, | 579 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, |
| 571 const DiskStatResult& result) { | 580 const DiskStatResult& result) { |
| 572 if (result.net_error == net::OK) { | 581 if (result.net_error == net::OK) { |
| 573 index_->SetMaxSize(result.max_size); | 582 index_->SetMaxSize(result.max_size); |
| 574 index_->Initialize(result.cache_dir_mtime); | 583 index_->Initialize(result.cache_dir_mtime); |
| 575 } | 584 } |
| 576 callback.Run(result.net_error); | 585 callback.Run(result.net_error); |
| 577 } | 586 } |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 } | 771 } |
| 763 | 772 |
| 764 // static | 773 // static |
| 765 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 774 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
| 766 // We only need to do this if we there is an active task runner. | 775 // We only need to do this if we there is an active task runner. |
| 767 if (base::ThreadTaskRunnerHandle::IsSet()) | 776 if (base::ThreadTaskRunnerHandle::IsSet()) |
| 768 g_sequenced_worker_pool.Get().FlushForTesting(); | 777 g_sequenced_worker_pool.Get().FlushForTesting(); |
| 769 } | 778 } |
| 770 | 779 |
| 771 } // namespace disk_cache | 780 } // namespace disk_cache |
| OLD | NEW |