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