Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: net/disk_cache/simple/simple_entry_impl.cc

Issue 2661333002: Track SimpleCache memory usage in net/ MemoryDumpProvider (Closed)
Patch Set: address comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_entry_impl.h" 5 #include "net/disk_cache/simple/simple_entry_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/location.h" 16 #include "base/location.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/task_runner.h" 19 #include "base/task_runner.h"
20 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "base/trace_event/memory_usage_estimator.h"
23 #include "net/base/io_buffer.h" 24 #include "net/base/io_buffer.h"
24 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
25 #include "net/disk_cache/net_log_parameters.h" 26 #include "net/disk_cache/net_log_parameters.h"
26 #include "net/disk_cache/simple/simple_backend_impl.h" 27 #include "net/disk_cache/simple/simple_backend_impl.h"
27 #include "net/disk_cache/simple/simple_histogram_macros.h" 28 #include "net/disk_cache/simple/simple_histogram_macros.h"
28 #include "net/disk_cache/simple/simple_index.h" 29 #include "net/disk_cache/simple/simple_index.h"
29 #include "net/disk_cache/simple/simple_net_log_parameters.h" 30 #include "net/disk_cache/simple/simple_net_log_parameters.h"
30 #include "net/disk_cache/simple/simple_synchronous_entry.h" 31 #include "net/disk_cache/simple/simple_synchronous_entry.h"
31 #include "net/disk_cache/simple/simple_util.h" 32 #include "net/disk_cache/simple/simple_util.h"
32 #include "net/log/net_log.h" 33 #include "net/log/net_log.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 completion_callback.Run(result); 143 completion_callback.Run(result);
143 } 144 }
144 145
145 } // namespace 146 } // namespace
146 147
147 using base::Closure; 148 using base::Closure;
148 using base::FilePath; 149 using base::FilePath;
149 using base::Time; 150 using base::Time;
150 using base::TaskRunner; 151 using base::TaskRunner;
151 152
153 // Static function called by base::trace_event::EstimateMemoryUsage() to
154 // estimate the memory of SimpleEntryOperation.
155 // This needs to be in disk_cache namespace.
156 size_t EstimateMemoryUsage(const SimpleEntryOperation& op) {
157 return 0;
158 }
159
152 // A helper class to insure that RunNextOperationIfNeeded() is called when 160 // A helper class to insure that RunNextOperationIfNeeded() is called when
153 // exiting the current stack frame. 161 // exiting the current stack frame.
154 class SimpleEntryImpl::ScopedOperationRunner { 162 class SimpleEntryImpl::ScopedOperationRunner {
155 public: 163 public:
156 explicit ScopedOperationRunner(SimpleEntryImpl* entry) : entry_(entry) { 164 explicit ScopedOperationRunner(SimpleEntryImpl* entry) : entry_(entry) {
157 } 165 }
158 166
159 ~ScopedOperationRunner() { 167 ~ScopedOperationRunner() {
160 entry_->RunNextOperationIfNeeded(); 168 entry_->RunNextOperationIfNeeded();
161 } 169 }
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 544 }
537 545
538 int SimpleEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) { 546 int SimpleEntryImpl::ReadyForSparseIO(const CompletionCallback& callback) {
539 DCHECK(io_thread_checker_.CalledOnValidThread()); 547 DCHECK(io_thread_checker_.CalledOnValidThread());
540 // The simple Cache does not return distinct objects for the same non-doomed 548 // The simple Cache does not return distinct objects for the same non-doomed
541 // entry, so there's no need to coordinate which object is performing sparse 549 // entry, so there's no need to coordinate which object is performing sparse
542 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly. 550 // I/O. Therefore, CancelSparseIO and ReadyForSparseIO succeed instantly.
543 return net::OK; 551 return net::OK;
544 } 552 }
545 553
554 size_t SimpleEntryImpl::EstimateMemoryUsage() const {
555 // TODO(xunjieli): crbug.com/669108. It'd be nice to have the rest of |entry|
556 // measured, but the ownership of SimpleSynchronousEntry isn't straightforward
557 return sizeof(SimpleSynchronousEntry) +
558 base::trace_event::EstimateMemoryUsage(pending_operations_) +
559 base::trace_event::EstimateMemoryUsage(executing_operation_) +
560 (stream_0_data_ ? stream_0_data_->capacity() : 0);
561 }
562
546 SimpleEntryImpl::~SimpleEntryImpl() { 563 SimpleEntryImpl::~SimpleEntryImpl() {
547 DCHECK(io_thread_checker_.CalledOnValidThread()); 564 DCHECK(io_thread_checker_.CalledOnValidThread());
548 DCHECK_EQ(0U, pending_operations_.size()); 565 DCHECK_EQ(0U, pending_operations_.size());
549 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE); 566 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_FAILURE);
550 DCHECK(!synchronous_entry_); 567 DCHECK(!synchronous_entry_);
551 net_log_.EndEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY); 568 net_log_.EndEvent(net::NetLogEventType::SIMPLE_CACHE_ENTRY);
552 } 569 }
553 570
554 void SimpleEntryImpl::PostClientCallback(const CompletionCallback& callback, 571 void SimpleEntryImpl::PostClientCallback(const CompletionCallback& callback,
555 int result) { 572 int result) {
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 } 1562 }
1546 crc32s_end_offset_[stream_index] = offset + length; 1563 crc32s_end_offset_[stream_index] = offset + length;
1547 } else if (offset < crc32s_end_offset_[stream_index]) { 1564 } else if (offset < crc32s_end_offset_[stream_index]) {
1548 // If a range for which the crc32 was already computed is rewritten, the 1565 // If a range for which the crc32 was already computed is rewritten, the
1549 // computation of the crc32 need to start from 0 again. 1566 // computation of the crc32 need to start from 0 again.
1550 crc32s_end_offset_[stream_index] = 0; 1567 crc32s_end_offset_[stream_index] = 0;
1551 } 1568 }
1552 } 1569 }
1553 1570
1554 } // namespace disk_cache 1571 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698