Chromium Code Reviews| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 } | 110 } |
| 108 | 111 |
| 109 //----------------------------------------------------------------------------- | 112 //----------------------------------------------------------------------------- |
| 110 | 113 |
| 111 // This structure keeps track of work items that are attempting to create or | 114 // This structure keeps track of work items that are attempting to create or |
| 112 // open cache entries or the backend itself. | 115 // open cache entries or the backend itself. |
| 113 struct HttpCache::PendingOp { | 116 struct HttpCache::PendingOp { |
| 114 PendingOp() : disk_entry(NULL) {} | 117 PendingOp() : disk_entry(NULL) {} |
| 115 ~PendingOp() {} | 118 ~PendingOp() {} |
| 116 | 119 |
| 120 // Returns the estimate of dynamically allocated memory in bytes. | |
| 121 size_t EstimateMemoryUsage() const { | |
| 122 // |disk_entry| is tracked in |backend|. | |
| 123 return base::trace_event::EstimateMemoryUsage(backend) + | |
| 124 base::trace_event::EstimateMemoryUsage(writer) + | |
| 125 base::trace_event::EstimateMemoryUsage(pending_queue); | |
| 126 } | |
| 127 | |
| 117 disk_cache::Entry* disk_entry; | 128 disk_cache::Entry* disk_entry; |
| 118 std::unique_ptr<disk_cache::Backend> backend; | 129 std::unique_ptr<disk_cache::Backend> backend; |
| 119 std::unique_ptr<WorkItem> writer; | 130 std::unique_ptr<WorkItem> writer; |
| 120 CompletionCallback callback; // BackendCallback. | 131 CompletionCallback callback; // BackendCallback. |
| 121 WorkItemList pending_queue; | 132 WorkItemList pending_queue; |
| 122 }; | 133 }; |
| 123 | 134 |
| 124 //----------------------------------------------------------------------------- | 135 //----------------------------------------------------------------------------- |
| 125 | 136 |
| 126 // The type of operation represented by a work item. | 137 // 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; | 183 return false; |
| 173 } | 184 } |
| 174 | 185 |
| 175 WorkItemOperation operation() { return operation_; } | 186 WorkItemOperation operation() { return operation_; } |
| 176 void ClearTransaction() { trans_ = NULL; } | 187 void ClearTransaction() { trans_ = NULL; } |
| 177 void ClearEntry() { entry_ = NULL; } | 188 void ClearEntry() { entry_ = NULL; } |
| 178 void ClearCallback() { callback_.Reset(); } | 189 void ClearCallback() { callback_.Reset(); } |
| 179 bool Matches(Transaction* trans) const { return trans == trans_; } | 190 bool Matches(Transaction* trans) const { return trans == trans_; } |
| 180 bool IsValid() const { return trans_ || entry_ || !callback_.is_null(); } | 191 bool IsValid() const { return trans_ || entry_ || !callback_.is_null(); } |
| 181 | 192 |
| 193 // Returns the estimate of dynamically allocated memory in bytes. | |
| 194 size_t EstimateMemoryUsage() const { return 0; } | |
| 195 | |
| 182 private: | 196 private: |
| 183 WorkItemOperation operation_; | 197 WorkItemOperation operation_; |
| 184 Transaction* trans_; | 198 Transaction* trans_; |
| 185 ActiveEntry** entry_; | 199 ActiveEntry** entry_; |
| 186 CompletionCallback callback_; // User callback. | 200 CompletionCallback callback_; // User callback. |
| 187 disk_cache::Backend** backend_; | 201 disk_cache::Backend** backend_; |
| 188 }; | 202 }; |
| 189 | 203 |
| 190 //----------------------------------------------------------------------------- | 204 //----------------------------------------------------------------------------- |
| 191 | 205 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 476 | 490 |
| 477 std::unique_ptr<HttpTransactionFactory> | 491 std::unique_ptr<HttpTransactionFactory> |
| 478 HttpCache::SetHttpNetworkTransactionFactoryForTesting( | 492 HttpCache::SetHttpNetworkTransactionFactoryForTesting( |
| 479 std::unique_ptr<HttpTransactionFactory> new_network_layer) { | 493 std::unique_ptr<HttpTransactionFactory> new_network_layer) { |
| 480 std::unique_ptr<HttpTransactionFactory> old_network_layer( | 494 std::unique_ptr<HttpTransactionFactory> old_network_layer( |
| 481 std::move(network_layer_)); | 495 std::move(network_layer_)); |
| 482 network_layer_ = std::move(new_network_layer); | 496 network_layer_ = std::move(new_network_layer); |
| 483 return old_network_layer; | 497 return old_network_layer; |
| 484 } | 498 } |
| 485 | 499 |
| 500 void HttpCache::DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, | |
| 501 const std::string& parent_absolute_name) const { | |
| 502 // |active_entries_| and |doomed_entries_| are tracked in |disk_cache_| which | |
| 503 // has references to all entries. Skip tracking members like |clock_| and | |
| 504 // |backend_factory_| because they don't allocate. | |
|
jkarlin
2017/02/21 16:23:29
Ah, not quite. We do want to track active_entries_
xunjieli
2017/02/21 19:44:14
Done.
| |
| 505 size_t memory_estimate = | |
| 506 base::trace_event::EstimateMemoryUsage(disk_cache_) + | |
| 507 base::trace_event::EstimateMemoryUsage(playback_cache_map_) + | |
| 508 base::trace_event::EstimateMemoryUsage(pending_ops_); | |
| 509 base::trace_event::MemoryAllocatorDump* dump = | |
| 510 pmd->CreateAllocatorDump(parent_absolute_name + "/http_cache"); | |
| 511 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 512 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 513 memory_estimate); | |
| 514 } | |
| 515 | |
| 486 //----------------------------------------------------------------------------- | 516 //----------------------------------------------------------------------------- |
| 487 | 517 |
| 488 int HttpCache::CreateBackend(disk_cache::Backend** backend, | 518 int HttpCache::CreateBackend(disk_cache::Backend** backend, |
| 489 const CompletionCallback& callback) { | 519 const CompletionCallback& callback) { |
| 490 if (!backend_factory_.get()) | 520 if (!backend_factory_.get()) |
| 491 return ERR_FAILED; | 521 return ERR_FAILED; |
| 492 | 522 |
| 493 building_backend_ = true; | 523 building_backend_ = true; |
| 494 | 524 |
| 495 std::unique_ptr<WorkItem> item = | 525 std::unique_ptr<WorkItem> item = |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 building_backend_ = false; | 1186 building_backend_ = false; |
| 1157 DeletePendingOp(pending_op); | 1187 DeletePendingOp(pending_op); |
| 1158 } | 1188 } |
| 1159 | 1189 |
| 1160 // The cache may be gone when we return from the callback. | 1190 // The cache may be gone when we return from the callback. |
| 1161 if (!item->DoCallback(result, disk_cache_.get())) | 1191 if (!item->DoCallback(result, disk_cache_.get())) |
| 1162 item->NotifyTransaction(result, NULL); | 1192 item->NotifyTransaction(result, NULL); |
| 1163 } | 1193 } |
| 1164 | 1194 |
| 1165 } // namespace net | 1195 } // namespace net |
| OLD | NEW |