| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 //----------------------------------------------------------------------------- | 123 //----------------------------------------------------------------------------- |
| 124 | 124 |
| 125 // This structure keeps track of work items that are attempting to create or | 125 // This structure keeps track of work items that are attempting to create or |
| 126 // open cache entries or the backend itself. | 126 // open cache entries or the backend itself. |
| 127 struct HttpCache::PendingOp { | 127 struct HttpCache::PendingOp { |
| 128 PendingOp() : disk_entry(NULL) {} | 128 PendingOp() : disk_entry(NULL) {} |
| 129 ~PendingOp() {} | 129 ~PendingOp() {} |
| 130 | 130 |
| 131 // Returns the estimate of dynamically allocated memory in bytes. | 131 // Returns the estimate of dynamically allocated memory in bytes. |
| 132 size_t EstimateMemoryUsage() const { | 132 size_t EstimateMemoryUsage() const { |
| 133 // |disk_entry| is tracked in |backend|. | 133 // Note that backend isn't counted because it doesn't provide an EMU |
| 134 return base::trace_event::EstimateMemoryUsage(backend) + | 134 // function. |
| 135 base::trace_event::EstimateMemoryUsage(writer) + | 135 return base::trace_event::EstimateMemoryUsage(writer) + |
| 136 base::trace_event::EstimateMemoryUsage(pending_queue); | 136 base::trace_event::EstimateMemoryUsage(pending_queue); |
| 137 } | 137 } |
| 138 | 138 |
| 139 disk_cache::Entry* disk_entry; | 139 disk_cache::Entry* disk_entry; |
| 140 std::unique_ptr<disk_cache::Backend> backend; | 140 std::unique_ptr<disk_cache::Backend> backend; |
| 141 std::unique_ptr<WorkItem> writer; | 141 std::unique_ptr<WorkItem> writer; |
| 142 CompletionCallback callback; // BackendCallback. | 142 CompletionCallback callback; // BackendCallback. |
| 143 WorkItemList pending_queue; | 143 WorkItemList pending_queue; |
| 144 }; | 144 }; |
| 145 | 145 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 std::unique_ptr<HttpTransactionFactory> old_network_layer( | 505 std::unique_ptr<HttpTransactionFactory> old_network_layer( |
| 506 std::move(network_layer_)); | 506 std::move(network_layer_)); |
| 507 network_layer_ = std::move(new_network_layer); | 507 network_layer_ = std::move(new_network_layer); |
| 508 return old_network_layer; | 508 return old_network_layer; |
| 509 } | 509 } |
| 510 | 510 |
| 511 void HttpCache::DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, | 511 void HttpCache::DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 512 const std::string& parent_absolute_name) const { | 512 const std::string& parent_absolute_name) const { |
| 513 // Skip tracking members like |clock_| and |backend_factory_| because they | 513 // Skip tracking members like |clock_| and |backend_factory_| because they |
| 514 // don't allocate. | 514 // don't allocate. |
| 515 base::trace_event::MemoryAllocatorDump* dump = | 515 std::string name = parent_absolute_name + "/http_cache"; |
| 516 pmd->CreateAllocatorDump(parent_absolute_name + "/http_cache"); | 516 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(name); |
| 517 dump->AddScalar( | 517 size_t size = base::trace_event::EstimateMemoryUsage(active_entries_) + |
| 518 base::trace_event::MemoryAllocatorDump::kNameSize, | 518 base::trace_event::EstimateMemoryUsage(doomed_entries_) + |
| 519 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 519 base::trace_event::EstimateMemoryUsage(playback_cache_map_) + |
| 520 base::trace_event::EstimateMemoryUsage(disk_cache_) + | 520 base::trace_event::EstimateMemoryUsage(pending_ops_); |
| 521 base::trace_event::EstimateMemoryUsage(active_entries_) + | 521 if (disk_cache_) |
| 522 base::trace_event::EstimateMemoryUsage(doomed_entries_) + | 522 size += disk_cache_->DumpMemoryStats(pmd, name); |
| 523 base::trace_event::EstimateMemoryUsage(playback_cache_map_) + | 523 |
| 524 base::trace_event::EstimateMemoryUsage(pending_ops_)); | 524 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 525 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); |
| 525 } | 526 } |
| 526 | 527 |
| 527 //----------------------------------------------------------------------------- | 528 //----------------------------------------------------------------------------- |
| 528 | 529 |
| 529 int HttpCache::CreateBackend(disk_cache::Backend** backend, | 530 int HttpCache::CreateBackend(disk_cache::Backend** backend, |
| 530 const CompletionCallback& callback) { | 531 const CompletionCallback& callback) { |
| 531 if (!backend_factory_.get()) | 532 if (!backend_factory_.get()) |
| 532 return ERR_FAILED; | 533 return ERR_FAILED; |
| 533 | 534 |
| 534 building_backend_ = true; | 535 building_backend_ = true; |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 building_backend_ = false; | 1196 building_backend_ = false; |
| 1196 DeletePendingOp(pending_op); | 1197 DeletePendingOp(pending_op); |
| 1197 } | 1198 } |
| 1198 | 1199 |
| 1199 // The cache may be gone when we return from the callback. | 1200 // The cache may be gone when we return from the callback. |
| 1200 if (!item->DoCallback(result, disk_cache_.get())) | 1201 if (!item->DoCallback(result, disk_cache_.get())) |
| 1201 item->NotifyTransaction(result, NULL); | 1202 item->NotifyTransaction(result, NULL); |
| 1202 } | 1203 } |
| 1203 | 1204 |
| 1204 } // namespace net | 1205 } // namespace net |
| OLD | NEW |