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

Side by Side Diff: net/disk_cache/entry_impl.cc

Issue 10543114: NetLogEventParameter to Callback refactoring 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Update comment in response to comment Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/mem_entry_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/disk_cache/entry_impl.h" 5 #include "net/disk_cache/entry_impl.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 DISALLOW_COPY_AND_ASSIGN(SyncCallback); 55 DISALLOW_COPY_AND_ASSIGN(SyncCallback);
56 }; 56 };
57 57
58 void SyncCallback::OnFileIOComplete(int bytes_copied) { 58 void SyncCallback::OnFileIOComplete(int bytes_copied) {
59 entry_->DecrementIoCount(); 59 entry_->DecrementIoCount();
60 if (!callback_.is_null()) { 60 if (!callback_.is_null()) {
61 if (entry_->net_log().IsLoggingAllEvents()) { 61 if (entry_->net_log().IsLoggingAllEvents()) {
62 entry_->net_log().EndEvent( 62 entry_->net_log().EndEvent(
63 end_event_type_, 63 end_event_type_,
64 make_scoped_refptr( 64 disk_cache::CreateNetLogReadWriteCompleteCallback(bytes_copied));
65 new disk_cache::ReadWriteCompleteParameters(bytes_copied)));
66 } 65 }
67 entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_); 66 entry_->ReportIOTime(disk_cache::EntryImpl::kAsyncIO, start_);
68 callback_.Run(bytes_copied); 67 callback_.Run(bytes_copied);
69 } 68 }
70 entry_->Release(); 69 entry_->Release();
71 delete this; 70 delete this;
72 } 71 }
73 72
74 void SyncCallback::Discard() { 73 void SyncCallback::Discard() {
75 callback_.Reset(); 74 callback_.Reset();
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 306
308 SetPointerForInvalidEntry(backend_->GetCurrentEntryId()); 307 SetPointerForInvalidEntry(backend_->GetCurrentEntryId());
309 backend_->InternalDoomEntry(this); 308 backend_->InternalDoomEntry(this);
310 } 309 }
311 310
312 int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len, 311 int EntryImpl::ReadDataImpl(int index, int offset, IOBuffer* buf, int buf_len,
313 const CompletionCallback& callback) { 312 const CompletionCallback& callback) {
314 if (net_log_.IsLoggingAllEvents()) { 313 if (net_log_.IsLoggingAllEvents()) {
315 net_log_.BeginEvent( 314 net_log_.BeginEvent(
316 net::NetLog::TYPE_ENTRY_READ_DATA, 315 net::NetLog::TYPE_ENTRY_READ_DATA,
317 make_scoped_refptr( 316 CreateNetLogReadWriteDataCallback(index, offset, buf_len, false));
318 new ReadWriteDataParameters(index, offset, buf_len, false)));
319 } 317 }
320 318
321 int result = InternalReadData(index, offset, buf, buf_len, callback); 319 int result = InternalReadData(index, offset, buf, buf_len, callback);
322 320
323 if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { 321 if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) {
324 net_log_.EndEvent( 322 net_log_.EndEvent(
325 net::NetLog::TYPE_ENTRY_READ_DATA, 323 net::NetLog::TYPE_ENTRY_READ_DATA,
326 make_scoped_refptr(new ReadWriteCompleteParameters(result))); 324 CreateNetLogReadWriteCompleteCallback(result));
327 } 325 }
328 return result; 326 return result;
329 } 327 }
330 328
331 int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len, 329 int EntryImpl::WriteDataImpl(int index, int offset, IOBuffer* buf, int buf_len,
332 const CompletionCallback& callback, 330 const CompletionCallback& callback,
333 bool truncate) { 331 bool truncate) {
334 if (net_log_.IsLoggingAllEvents()) { 332 if (net_log_.IsLoggingAllEvents()) {
335 net_log_.BeginEvent( 333 net_log_.BeginEvent(
336 net::NetLog::TYPE_ENTRY_WRITE_DATA, 334 net::NetLog::TYPE_ENTRY_WRITE_DATA,
337 make_scoped_refptr( 335 CreateNetLogReadWriteDataCallback(index, offset, buf_len, truncate));
338 new ReadWriteDataParameters(index, offset, buf_len, truncate)));
339 } 336 }
340 337
341 int result = InternalWriteData(index, offset, buf, buf_len, callback, 338 int result = InternalWriteData(index, offset, buf, buf_len, callback,
342 truncate); 339 truncate);
343 340
344 if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) { 341 if (result != net::ERR_IO_PENDING && net_log_.IsLoggingAllEvents()) {
345 net_log_.EndEvent( 342 net_log_.EndEvent(
346 net::NetLog::TYPE_ENTRY_WRITE_DATA, 343 net::NetLog::TYPE_ENTRY_WRITE_DATA,
347 make_scoped_refptr(new ReadWriteCompleteParameters(result))); 344 CreateNetLogReadWriteCompleteCallback(result));
348 } 345 }
349 return result; 346 return result;
350 } 347 }
351 348
352 int EntryImpl::ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len, 349 int EntryImpl::ReadSparseDataImpl(int64 offset, IOBuffer* buf, int buf_len,
353 const CompletionCallback& callback) { 350 const CompletionCallback& callback) {
354 DCHECK(node_.Data()->dirty || read_only_); 351 DCHECK(node_.Data()->dirty || read_only_);
355 int result = InitSparseData(); 352 int result = InitSparseData();
356 if (net::OK != result) 353 if (net::OK != result)
357 return result; 354 return result;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) { 448 bool EntryImpl::IsSameEntry(const std::string& key, uint32 hash) {
452 if (entry_.Data()->hash != hash || 449 if (entry_.Data()->hash != hash ||
453 static_cast<size_t>(entry_.Data()->key_len) != key.size()) 450 static_cast<size_t>(entry_.Data()->key_len) != key.size())
454 return false; 451 return false;
455 452
456 std::string my_key = GetKey(); 453 std::string my_key = GetKey();
457 return key.compare(my_key) ? false : true; 454 return key.compare(my_key) ? false : true;
458 } 455 }
459 456
460 void EntryImpl::InternalDoom() { 457 void EntryImpl::InternalDoom() {
461 net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM, NULL); 458 net_log_.AddEvent(net::NetLog::TYPE_ENTRY_DOOM);
462 DCHECK(node_.HasData()); 459 DCHECK(node_.HasData());
463 if (!node_.Data()->dirty) { 460 if (!node_.Data()->dirty) {
464 node_.Data()->dirty = backend_->GetCurrentEntryId(); 461 node_.Data()->dirty = backend_->GetCurrentEntryId();
465 node_.Store(); 462 node_.Store();
466 } 463 }
467 doomed_ = true; 464 doomed_ = true;
468 } 465 }
469 466
470 void EntryImpl::DeleteEntryData(bool everything) { 467 void EntryImpl::DeleteEntryData(bool everything) {
471 DCHECK(doomed_ || !everything); 468 DCHECK(doomed_ || !everything);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 NOTREACHED(); 714 NOTREACHED();
718 } 715 }
719 } 716 }
720 717
721 void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) { 718 void EntryImpl::BeginLogging(net::NetLog* net_log, bool created) {
722 DCHECK(!net_log_.net_log()); 719 DCHECK(!net_log_.net_log());
723 net_log_ = net::BoundNetLog::Make( 720 net_log_ = net::BoundNetLog::Make(
724 net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY); 721 net_log, net::NetLog::SOURCE_DISK_CACHE_ENTRY);
725 net_log_.BeginEvent( 722 net_log_.BeginEvent(
726 net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, 723 net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL,
727 make_scoped_refptr(new EntryCreationParameters(GetKey(), created))); 724 CreateNetLogEntryCreationCallback(this, created));
728 } 725 }
729 726
730 const net::BoundNetLog& EntryImpl::net_log() const { 727 const net::BoundNetLog& EntryImpl::net_log() const {
731 return net_log_; 728 return net_log_;
732 } 729 }
733 730
734 // static 731 // static
735 int EntryImpl::NumBlocksForEntry(int key_size) { 732 int EntryImpl::NumBlocksForEntry(int key_size) {
736 // The longest key that can be stored using one block. 733 // The longest key that can be stored using one block.
737 int key1_len = 734 int key1_len =
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 924
928 // Remove this entry from the list of open entries. 925 // Remove this entry from the list of open entries.
929 backend_->OnEntryDestroyBegin(entry_.address()); 926 backend_->OnEntryDestroyBegin(entry_.address());
930 927
931 if (doomed_) { 928 if (doomed_) {
932 DeleteEntryData(true); 929 DeleteEntryData(true);
933 } else { 930 } else {
934 #if defined(NET_BUILD_STRESS_CACHE) 931 #if defined(NET_BUILD_STRESS_CACHE)
935 SanityCheck(); 932 SanityCheck();
936 #endif 933 #endif
937 net_log_.AddEvent(net::NetLog::TYPE_ENTRY_CLOSE, NULL); 934 net_log_.AddEvent(net::NetLog::TYPE_ENTRY_CLOSE);
938 bool ret = true; 935 bool ret = true;
939 for (int index = 0; index < kNumStreams; index++) { 936 for (int index = 0; index < kNumStreams; index++) {
940 if (user_buffers_[index].get()) { 937 if (user_buffers_[index].get()) {
941 if (!(ret = Flush(index, 0))) 938 if (!(ret = Flush(index, 0)))
942 LOG(ERROR) << "Failed to save user data"; 939 LOG(ERROR) << "Failed to save user data";
943 } 940 }
944 if (unreported_size_[index]) { 941 if (unreported_size_[index]) {
945 backend_->ModifyStorageSize( 942 backend_->ModifyStorageSize(
946 entry_.Data()->data_size[index] - unreported_size_[index], 943 entry_.Data()->data_size[index] - unreported_size_[index],
947 entry_.Data()->data_size[index]); 944 entry_.Data()->data_size[index]);
948 } 945 }
949 } 946 }
950 947
951 if (!ret) { 948 if (!ret) {
952 // There was a failure writing the actual data. Mark the entry as dirty. 949 // There was a failure writing the actual data. Mark the entry as dirty.
953 int current_id = backend_->GetCurrentEntryId(); 950 int current_id = backend_->GetCurrentEntryId();
954 node_.Data()->dirty = current_id == 1 ? -1 : current_id - 1; 951 node_.Data()->dirty = current_id == 1 ? -1 : current_id - 1;
955 node_.Store(); 952 node_.Store();
956 } else if (node_.HasData() && !dirty_ && node_.Data()->dirty) { 953 } else if (node_.HasData() && !dirty_ && node_.Data()->dirty) {
957 node_.Data()->dirty = 0; 954 node_.Data()->dirty = 0;
958 node_.Store(); 955 node_.Store();
959 } 956 }
960 } 957 }
961 958
962 Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this)); 959 Trace("~EntryImpl out 0x%p", reinterpret_cast<void*>(this));
963 net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL, NULL); 960 net_log_.EndEvent(net::NetLog::TYPE_DISK_CACHE_ENTRY_IMPL);
964 backend_->OnEntryDestroyEnd(); 961 backend_->OnEntryDestroyEnd();
965 } 962 }
966 963
967 // ------------------------------------------------------------------------ 964 // ------------------------------------------------------------------------
968 965
969 int EntryImpl::InternalReadData(int index, int offset, 966 int EntryImpl::InternalReadData(int index, int offset,
970 IOBuffer* buf, int buf_len, 967 IOBuffer* buf, int buf_len,
971 const CompletionCallback& callback) { 968 const CompletionCallback& callback) {
972 DCHECK(node_.Data()->dirty || read_only_); 969 DCHECK(node_.Data()->dirty || read_only_);
973 DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len; 970 DVLOG(2) << "Read from " << index << " at " << offset << " : " << buf_len;
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this), 1537 Trace("%s 0x%p 0x%x 0x%x", msg, reinterpret_cast<void*>(this),
1541 entry_.address().value(), node_.address().value()); 1538 entry_.address().value(), node_.address().value());
1542 1539
1543 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0], 1540 Trace(" data: 0x%x 0x%x 0x%x", entry_.Data()->data_addr[0],
1544 entry_.Data()->data_addr[1], entry_.Data()->long_key); 1541 entry_.Data()->data_addr[1], entry_.Data()->long_key);
1545 1542
1546 Trace(" doomed: %d 0x%x", doomed_, dirty); 1543 Trace(" doomed: %d 0x%x", doomed_, dirty);
1547 } 1544 }
1548 1545
1549 } // namespace disk_cache 1546 } // namespace disk_cache
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/mem_entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698