Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/disk_cache_based_quic_server_info.h" | 5 #include "net/http/disk_cache_based_quic_server_info.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/trace_event/memory_usage_estimator.h" | |
| 13 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 14 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/http/http_cache.h" | 17 #include "net/http/http_cache.h" |
| 17 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| 18 #include "net/quic/core/quic_server_id.h" | 19 #include "net/quic/core/quic_server_id.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 | 22 |
| 22 // Some APIs inside disk_cache take a handle that the caller must keep alive | 23 // Some APIs inside disk_cache take a handle that the caller must keep alive |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 179 |
| 179 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_EXTERNAL_CACHE_HIT); | 180 RecordQuicServerInfoStatus(QUIC_SERVER_INFO_EXTERNAL_CACHE_HIT); |
| 180 if (!backend_) { | 181 if (!backend_) { |
| 181 RecordQuicServerInfoFailure(PERSIST_NO_BACKEND_FAILURE); | 182 RecordQuicServerInfoFailure(PERSIST_NO_BACKEND_FAILURE); |
| 182 return; | 183 return; |
| 183 } | 184 } |
| 184 | 185 |
| 185 backend_->OnExternalCacheHit(key()); | 186 backend_->OnExternalCacheHit(key()); |
| 186 } | 187 } |
| 187 | 188 |
| 189 size_t DiskCacheBasedQuicServerInfo::EstimateMemoryUsage() const { | |
| 190 return base::trace_event::EstimateMemoryUsage(new_data_) + | |
| 191 base::trace_event::EstimateMemoryUsage(pending_write_data_) + | |
| 192 base::trace_event::EstimateMemoryUsage(server_id_) + | |
| 193 (read_buffer_ == nullptr ? 0 : read_buffer_->size()) + | |
| 194 (write_buffer_ == nullptr ? 0 : read_buffer_->size()) + | |
|
ssid
2017/04/07 17:14:04
write_buffer_?
xunjieli
2017/04/07 21:37:59
Done.
| |
| 195 base::trace_event::EstimateMemoryUsage(data_); | |
| 196 } | |
| 197 | |
| 188 std::string DiskCacheBasedQuicServerInfo::key() const { | 198 std::string DiskCacheBasedQuicServerInfo::key() const { |
| 189 return "quicserverinfo:" + server_id_.ToString(); | 199 return "quicserverinfo:" + server_id_.ToString(); |
| 190 } | 200 } |
| 191 | 201 |
| 192 void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, | 202 void DiskCacheBasedQuicServerInfo::OnIOComplete(CacheOperationDataShim* unused, |
| 193 int rv) { | 203 int rv) { |
| 194 DCHECK_NE(NONE, state_); | 204 DCHECK_NE(NONE, state_); |
| 195 rv = DoLoop(rv); | 205 rv = DoLoop(rv); |
| 196 if (rv == ERR_IO_PENDING) | 206 if (rv == ERR_IO_PENDING) |
| 197 return; | 207 return; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 return backend_->OpenEntry(key(), &data_shim_->entry, io_callback_); | 338 return backend_->OpenEntry(key(), &data_shim_->entry, io_callback_); |
| 329 } | 339 } |
| 330 | 340 |
| 331 int DiskCacheBasedQuicServerInfo::DoRead() { | 341 int DiskCacheBasedQuicServerInfo::DoRead() { |
| 332 const int32_t size = entry_->GetDataSize(0 /* index */); | 342 const int32_t size = entry_->GetDataSize(0 /* index */); |
| 333 if (!size) { | 343 if (!size) { |
| 334 state_ = WAIT_FOR_DATA_READY_DONE; | 344 state_ = WAIT_FOR_DATA_READY_DONE; |
| 335 return OK; | 345 return OK; |
| 336 } | 346 } |
| 337 | 347 |
| 338 read_buffer_ = new IOBuffer(size); | 348 read_buffer_ = new IOBufferWithSize(size); |
| 339 state_ = READ_COMPLETE; | 349 state_ = READ_COMPLETE; |
| 340 return entry_->ReadData( | 350 return entry_->ReadData( |
| 341 0 /* index */, 0 /* offset */, read_buffer_.get(), size, io_callback_); | 351 0 /* index */, 0 /* offset */, read_buffer_.get(), size, io_callback_); |
| 342 } | 352 } |
| 343 | 353 |
| 344 int DiskCacheBasedQuicServerInfo::DoWrite() { | 354 int DiskCacheBasedQuicServerInfo::DoWrite() { |
| 345 write_buffer_ = new IOBuffer(new_data_.size()); | 355 write_buffer_ = new IOBufferWithSize(new_data_.size()); |
| 346 memcpy(write_buffer_->data(), new_data_.data(), new_data_.size()); | 356 memcpy(write_buffer_->data(), new_data_.data(), new_data_.size()); |
| 347 state_ = WRITE_COMPLETE; | 357 state_ = WRITE_COMPLETE; |
| 348 | 358 |
| 349 return entry_->WriteData(0 /* index */, | 359 return entry_->WriteData(0 /* index */, |
| 350 0 /* offset */, | 360 0 /* offset */, |
| 351 write_buffer_.get(), | 361 write_buffer_.get(), |
| 352 new_data_.size(), | 362 new_data_.size(), |
| 353 io_callback_, | 363 io_callback_, |
| 354 true /* truncate */); | 364 true /* truncate */); |
| 355 } | 365 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } else if (backend_->GetCacheType() == MEMORY_CACHE) { | 441 } else if (backend_->GetCacheType() == MEMORY_CACHE) { |
| 432 UMA_HISTOGRAM_ENUMERATION("Net.QuicDiskCache.FailureReason.MemoryCache", | 442 UMA_HISTOGRAM_ENUMERATION("Net.QuicDiskCache.FailureReason.MemoryCache", |
| 433 failure, NUM_OF_FAILURES); | 443 failure, NUM_OF_FAILURES); |
| 434 } else { | 444 } else { |
| 435 UMA_HISTOGRAM_ENUMERATION("Net.QuicDiskCache.FailureReason.DiskCache", | 445 UMA_HISTOGRAM_ENUMERATION("Net.QuicDiskCache.FailureReason.DiskCache", |
| 436 failure, NUM_OF_FAILURES); | 446 failure, NUM_OF_FAILURES); |
| 437 } | 447 } |
| 438 } | 448 } |
| 439 | 449 |
| 440 } // namespace net | 450 } // namespace net |
| OLD | NEW |