OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/metrics/histogram_macros.h" | 21 #include "base/metrics/histogram_macros.h" |
22 #include "base/pickle.h" | 22 #include "base/pickle.h" |
23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
28 #include "base/threading/worker_pool.h" | 28 #include "base/threading/worker_pool.h" |
29 #include "base/time/default_clock.h" | 29 #include "base/time/default_clock.h" |
30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
| 31 #include "base/trace_event/memory_allocator_dump.h" |
| 32 #include "base/trace_event/memory_usage_estimator.h" |
| 33 #include "base/trace_event/process_memory_dump.h" |
31 #include "net/base/cache_type.h" | 34 #include "net/base/cache_type.h" |
32 #include "net/base/io_buffer.h" | 35 #include "net/base/io_buffer.h" |
33 #include "net/base/load_flags.h" | 36 #include "net/base/load_flags.h" |
34 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
35 #include "net/base/upload_data_stream.h" | 38 #include "net/base/upload_data_stream.h" |
36 #include "net/disk_cache/disk_cache.h" | 39 #include "net/disk_cache/disk_cache.h" |
37 #include "net/http/disk_cache_based_quic_server_info.h" | 40 #include "net/http/disk_cache_based_quic_server_info.h" |
38 #include "net/http/http_cache_transaction.h" | 41 #include "net/http/http_cache_transaction.h" |
39 #include "net/http/http_network_layer.h" | 42 #include "net/http/http_network_layer.h" |
40 #include "net/http/http_network_session.h" | 43 #include "net/http/http_network_session.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 doomed(false) { | 102 doomed(false) { |
100 } | 103 } |
101 | 104 |
102 HttpCache::ActiveEntry::~ActiveEntry() { | 105 HttpCache::ActiveEntry::~ActiveEntry() { |
103 if (disk_entry) { | 106 if (disk_entry) { |
104 disk_entry->Close(); | 107 disk_entry->Close(); |
105 disk_entry = NULL; | 108 disk_entry = NULL; |
106 } | 109 } |
107 } | 110 } |
108 | 111 |
| 112 size_t HttpCache::ActiveEntry::EstimateMemoryUsage() const { |
| 113 // Skip |disk_entry| which is tracked in simple_backend_impl; Skip |readers| |
| 114 // and |pending_queue| because the Transactions are owned by their respective |
| 115 // URLRequestHttpJobs. |
| 116 return 0; |
| 117 } |
| 118 |
109 //----------------------------------------------------------------------------- | 119 //----------------------------------------------------------------------------- |
110 | 120 |
111 // This structure keeps track of work items that are attempting to create or | 121 // This structure keeps track of work items that are attempting to create or |
112 // open cache entries or the backend itself. | 122 // open cache entries or the backend itself. |
113 struct HttpCache::PendingOp { | 123 struct HttpCache::PendingOp { |
114 PendingOp() : disk_entry(NULL) {} | 124 PendingOp() : disk_entry(NULL) {} |
115 ~PendingOp() {} | 125 ~PendingOp() {} |
116 | 126 |
| 127 // Returns the estimate of dynamically allocated memory in bytes. |
| 128 size_t EstimateMemoryUsage() const { |
| 129 // |disk_entry| is tracked in |backend|. |
| 130 return base::trace_event::EstimateMemoryUsage(backend) + |
| 131 base::trace_event::EstimateMemoryUsage(writer) + |
| 132 base::trace_event::EstimateMemoryUsage(pending_queue); |
| 133 } |
| 134 |
117 disk_cache::Entry* disk_entry; | 135 disk_cache::Entry* disk_entry; |
118 std::unique_ptr<disk_cache::Backend> backend; | 136 std::unique_ptr<disk_cache::Backend> backend; |
119 std::unique_ptr<WorkItem> writer; | 137 std::unique_ptr<WorkItem> writer; |
120 CompletionCallback callback; // BackendCallback. | 138 CompletionCallback callback; // BackendCallback. |
121 WorkItemList pending_queue; | 139 WorkItemList pending_queue; |
122 }; | 140 }; |
123 | 141 |
124 //----------------------------------------------------------------------------- | 142 //----------------------------------------------------------------------------- |
125 | 143 |
126 // The type of operation represented by a work item. | 144 // The type of operation represented by a work item. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 return false; | 190 return false; |
173 } | 191 } |
174 | 192 |
175 WorkItemOperation operation() { return operation_; } | 193 WorkItemOperation operation() { return operation_; } |
176 void ClearTransaction() { trans_ = NULL; } | 194 void ClearTransaction() { trans_ = NULL; } |
177 void ClearEntry() { entry_ = NULL; } | 195 void ClearEntry() { entry_ = NULL; } |
178 void ClearCallback() { callback_.Reset(); } | 196 void ClearCallback() { callback_.Reset(); } |
179 bool Matches(Transaction* trans) const { return trans == trans_; } | 197 bool Matches(Transaction* trans) const { return trans == trans_; } |
180 bool IsValid() const { return trans_ || entry_ || !callback_.is_null(); } | 198 bool IsValid() const { return trans_ || entry_ || !callback_.is_null(); } |
181 | 199 |
| 200 // Returns the estimate of dynamically allocated memory in bytes. |
| 201 size_t EstimateMemoryUsage() const { return 0; } |
| 202 |
182 private: | 203 private: |
183 WorkItemOperation operation_; | 204 WorkItemOperation operation_; |
184 Transaction* trans_; | 205 Transaction* trans_; |
185 ActiveEntry** entry_; | 206 ActiveEntry** entry_; |
186 CompletionCallback callback_; // User callback. | 207 CompletionCallback callback_; // User callback. |
187 disk_cache::Backend** backend_; | 208 disk_cache::Backend** backend_; |
188 }; | 209 }; |
189 | 210 |
190 //----------------------------------------------------------------------------- | 211 //----------------------------------------------------------------------------- |
191 | 212 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 497 |
477 std::unique_ptr<HttpTransactionFactory> | 498 std::unique_ptr<HttpTransactionFactory> |
478 HttpCache::SetHttpNetworkTransactionFactoryForTesting( | 499 HttpCache::SetHttpNetworkTransactionFactoryForTesting( |
479 std::unique_ptr<HttpTransactionFactory> new_network_layer) { | 500 std::unique_ptr<HttpTransactionFactory> new_network_layer) { |
480 std::unique_ptr<HttpTransactionFactory> old_network_layer( | 501 std::unique_ptr<HttpTransactionFactory> old_network_layer( |
481 std::move(network_layer_)); | 502 std::move(network_layer_)); |
482 network_layer_ = std::move(new_network_layer); | 503 network_layer_ = std::move(new_network_layer); |
483 return old_network_layer; | 504 return old_network_layer; |
484 } | 505 } |
485 | 506 |
| 507 void HttpCache::DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 508 const std::string& parent_absolute_name) const { |
| 509 // Skip tracking members like |clock_| and |backend_factory_| because they |
| 510 // don't allocate. |
| 511 base::trace_event::MemoryAllocatorDump* dump = |
| 512 pmd->CreateAllocatorDump(parent_absolute_name + "/http_cache"); |
| 513 dump->AddScalar( |
| 514 base::trace_event::MemoryAllocatorDump::kNameSize, |
| 515 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 516 base::trace_event::EstimateMemoryUsage(disk_cache_) + |
| 517 base::trace_event::EstimateMemoryUsage(active_entries_) + |
| 518 base::trace_event::EstimateMemoryUsage(doomed_entries_) + |
| 519 base::trace_event::EstimateMemoryUsage(playback_cache_map_) + |
| 520 base::trace_event::EstimateMemoryUsage(pending_ops_)); |
| 521 } |
| 522 |
486 //----------------------------------------------------------------------------- | 523 //----------------------------------------------------------------------------- |
487 | 524 |
488 int HttpCache::CreateBackend(disk_cache::Backend** backend, | 525 int HttpCache::CreateBackend(disk_cache::Backend** backend, |
489 const CompletionCallback& callback) { | 526 const CompletionCallback& callback) { |
490 if (!backend_factory_.get()) | 527 if (!backend_factory_.get()) |
491 return ERR_FAILED; | 528 return ERR_FAILED; |
492 | 529 |
493 building_backend_ = true; | 530 building_backend_ = true; |
494 | 531 |
495 std::unique_ptr<WorkItem> item = | 532 std::unique_ptr<WorkItem> item = |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 building_backend_ = false; | 1193 building_backend_ = false; |
1157 DeletePendingOp(pending_op); | 1194 DeletePendingOp(pending_op); |
1158 } | 1195 } |
1159 | 1196 |
1160 // The cache may be gone when we return from the callback. | 1197 // The cache may be gone when we return from the callback. |
1161 if (!item->DoCallback(result, disk_cache_.get())) | 1198 if (!item->DoCallback(result, disk_cache_.get())) |
1162 item->NotifyTransaction(result, NULL); | 1199 item->NotifyTransaction(result, NULL); |
1163 } | 1200 } |
1164 | 1201 |
1165 } // namespace net | 1202 } // namespace net |
OLD | NEW |