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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 std::pair<std::string, std::string> item; | 546 std::pair<std::string, std::string> item; |
546 item.first = "Cache type"; | 547 item.first = "Cache type"; |
547 item.second = "Simple Cache"; | 548 item.second = "Simple Cache"; |
548 stats->push_back(item); | 549 stats->push_back(item); |
549 } | 550 } |
550 | 551 |
551 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { | 552 void SimpleBackendImpl::OnExternalCacheHit(const std::string& key) { |
552 index_->UseIfExists(simple_util::GetEntryHashKey(key)); | 553 index_->UseIfExists(simple_util::GetEntryHashKey(key)); |
553 } | 554 } |
554 | 555 |
| 556 size_t SimpleBackendImpl::EstimateMemoryUsage() const { |
| 557 return base::trace_event::EstimateMemoryUsage(index_) + |
| 558 base::trace_event::EstimateMemoryUsage(active_entries_); |
| 559 } |
| 560 |
555 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, | 561 void SimpleBackendImpl::InitializeIndex(const CompletionCallback& callback, |
556 const DiskStatResult& result) { | 562 const DiskStatResult& result) { |
557 if (result.net_error == net::OK) { | 563 if (result.net_error == net::OK) { |
558 index_->SetMaxSize(result.max_size); | 564 index_->SetMaxSize(result.max_size); |
559 index_->Initialize(result.cache_dir_mtime); | 565 index_->Initialize(result.cache_dir_mtime); |
560 } | 566 } |
561 callback.Run(result.net_error); | 567 callback.Run(result.net_error); |
562 } | 568 } |
563 | 569 |
564 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, | 570 void SimpleBackendImpl::IndexReadyForDoom(Time initial_time, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 } | 753 } |
748 | 754 |
749 // static | 755 // static |
750 void SimpleBackendImpl::FlushWorkerPoolForTesting() { | 756 void SimpleBackendImpl::FlushWorkerPoolForTesting() { |
751 // We only need to do this if we there is an active task runner. | 757 // We only need to do this if we there is an active task runner. |
752 if (base::ThreadTaskRunnerHandle::IsSet()) | 758 if (base::ThreadTaskRunnerHandle::IsSet()) |
753 g_sequenced_worker_pool.Get().FlushForTesting(); | 759 g_sequenced_worker_pool.Get().FlushForTesting(); |
754 } | 760 } |
755 | 761 |
756 } // namespace disk_cache | 762 } // namespace disk_cache |
OLD | NEW |