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

Side by Side Diff: net/http/http_cache_transaction.cc

Issue 4067002: First pass at adding http/backend cache to NetLog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Removing class I decided not to use Created 10 years 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_transaction.h" 5 #include "net/http/http_cache_transaction.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
11 #endif 11 #endif
12 12
13 #include <string> 13 #include <string>
14 14
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/ref_counted.h" 18 #include "base/ref_counted.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/time.h" 20 #include "base/time.h"
21 #include "base/values.h"
21 #include "net/base/cert_status_flags.h" 22 #include "net/base/cert_status_flags.h"
22 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
23 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
24 #include "net/base/net_errors.h" 25 #include "net/base/net_errors.h"
25 #include "net/base/net_log.h" 26 #include "net/base/net_log.h"
26 #include "net/base/ssl_cert_request_info.h" 27 #include "net/base/ssl_cert_request_info.h"
27 #include "net/base/ssl_config_service.h" 28 #include "net/base/ssl_config_service.h"
28 #include "net/disk_cache/disk_cache.h" 29 #include "net/disk_cache/disk_cache.h"
29 #include "net/http/disk_cache_based_ssl_host_info.h" 30 #include "net/http/disk_cache_based_ssl_host_info.h"
30 #include "net/http/http_request_info.h" 31 #include "net/http/http_request_info.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 379 }
379 380
380 LoadState HttpCache::Transaction::GetWriterLoadState() const { 381 LoadState HttpCache::Transaction::GetWriterLoadState() const {
381 if (network_trans_.get()) 382 if (network_trans_.get())
382 return network_trans_->GetLoadState(); 383 return network_trans_->GetLoadState();
383 if (entry_ || !request_) 384 if (entry_ || !request_)
384 return LOAD_STATE_IDLE; 385 return LOAD_STATE_IDLE;
385 return LOAD_STATE_WAITING_FOR_CACHE; 386 return LOAD_STATE_WAITING_FOR_CACHE;
386 } 387 }
387 388
389 const BoundNetLog& HttpCache::Transaction::net_log() const {
390 return net_log_;
391 }
392
388 //----------------------------------------------------------------------------- 393 //-----------------------------------------------------------------------------
389 394
390 void HttpCache::Transaction::DoCallback(int rv) { 395 void HttpCache::Transaction::DoCallback(int rv) {
391 DCHECK(rv != ERR_IO_PENDING); 396 DCHECK(rv != ERR_IO_PENDING);
392 DCHECK(callback_); 397 DCHECK(callback_);
393 398
394 // Since Run may result in Read being called, clear callback_ up front. 399 // Since Run may result in Read being called, clear callback_ up front.
395 CompletionCallback* c = callback_; 400 CompletionCallback* c = callback_;
396 callback_ = NULL; 401 callback_ = NULL;
397 c->Run(rv); 402 c->Run(rv);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 564
560 if (rv != ERR_IO_PENDING) 565 if (rv != ERR_IO_PENDING)
561 HandleResult(rv); 566 HandleResult(rv);
562 567
563 return rv; 568 return rv;
564 } 569 }
565 570
566 int HttpCache::Transaction::DoGetBackend() { 571 int HttpCache::Transaction::DoGetBackend() {
567 cache_pending_ = true; 572 cache_pending_ = true;
568 next_state_ = STATE_GET_BACKEND_COMPLETE; 573 next_state_ = STATE_GET_BACKEND_COMPLETE;
569 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); 574 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, NULL);
570 return cache_->GetBackendForTransaction(this); 575 return cache_->GetBackendForTransaction(this);
571 } 576 }
572 577
573 int HttpCache::Transaction::DoGetBackendComplete(int result) { 578 int HttpCache::Transaction::DoGetBackendComplete(int result) {
574 DCHECK(result == OK || result == ERR_FAILED); 579 DCHECK(result == OK || result == ERR_FAILED);
575 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); 580 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, result);
576 cache_pending_ = false; 581 cache_pending_ = false;
577 582
578 if (!ShouldPassThrough()) { 583 if (!ShouldPassThrough()) {
579 cache_key_ = cache_->GenerateCacheKey(request_); 584 cache_key_ = cache_->GenerateCacheKey(request_);
580 585
581 // Requested cache access mode. 586 // Requested cache access mode.
582 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { 587 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) {
583 mode_ = READ; 588 mode_ = READ;
584 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { 589 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) {
585 mode_ = WRITE; 590 mode_ = WRITE;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 next_state_ = STATE_OPEN_ENTRY_COMPLETE; 744 next_state_ = STATE_OPEN_ENTRY_COMPLETE;
740 cache_pending_ = true; 745 cache_pending_ = true;
741 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL); 746 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL);
742 return cache_->OpenEntry(cache_key_, &new_entry_, this); 747 return cache_->OpenEntry(cache_key_, &new_entry_, this);
743 } 748 }
744 749
745 int HttpCache::Transaction::DoOpenEntryComplete(int result) { 750 int HttpCache::Transaction::DoOpenEntryComplete(int result) {
746 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is 751 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is
747 // OK, otherwise the cache will end up with an active entry without any 752 // OK, otherwise the cache will end up with an active entry without any
748 // transaction attached. 753 // transaction attached.
749 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL); 754 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result);
750 cache_pending_ = false; 755 cache_pending_ = false;
751 if (result == OK) { 756 if (result == OK) {
752 next_state_ = STATE_ADD_TO_ENTRY; 757 next_state_ = STATE_ADD_TO_ENTRY;
753 return OK; 758 return OK;
754 } 759 }
755 760
756 if (result == ERR_CACHE_RACE) { 761 if (result == ERR_CACHE_RACE) {
757 next_state_ = STATE_INIT_ENTRY; 762 next_state_ = STATE_INIT_ENTRY;
758 return OK; 763 return OK;
759 } 764 }
(...skipping 22 matching lines...) Expand all
782 next_state_ = STATE_CREATE_ENTRY_COMPLETE; 787 next_state_ = STATE_CREATE_ENTRY_COMPLETE;
783 cache_pending_ = true; 788 cache_pending_ = true;
784 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL); 789 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL);
785 return cache_->CreateEntry(cache_key_, &new_entry_, this); 790 return cache_->CreateEntry(cache_key_, &new_entry_, this);
786 } 791 }
787 792
788 int HttpCache::Transaction::DoCreateEntryComplete(int result) { 793 int HttpCache::Transaction::DoCreateEntryComplete(int result) {
789 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is 794 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is
790 // OK, otherwise the cache will end up with an active entry without any 795 // OK, otherwise the cache will end up with an active entry without any
791 // transaction attached. 796 // transaction attached.
792 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL); 797 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, result);
793 cache_pending_ = false; 798 cache_pending_ = false;
794 next_state_ = STATE_ADD_TO_ENTRY; 799 next_state_ = STATE_ADD_TO_ENTRY;
795 800
796 if (result == ERR_CACHE_RACE) { 801 if (result == ERR_CACHE_RACE) {
797 next_state_ = STATE_INIT_ENTRY; 802 next_state_ = STATE_INIT_ENTRY;
798 return OK; 803 return OK;
799 } 804 }
800 805
801 if (result != OK) { 806 if (result != OK) {
802 // We have a race here: Maybe we failed to open the entry and decided to 807 // We have a race here: Maybe we failed to open the entry and decided to
(...skipping 10 matching lines...) Expand all
813 } 818 }
814 819
815 int HttpCache::Transaction::DoDoomEntry() { 820 int HttpCache::Transaction::DoDoomEntry() {
816 next_state_ = STATE_DOOM_ENTRY_COMPLETE; 821 next_state_ = STATE_DOOM_ENTRY_COMPLETE;
817 cache_pending_ = true; 822 cache_pending_ = true;
818 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL); 823 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL);
819 return cache_->DoomEntry(cache_key_, this); 824 return cache_->DoomEntry(cache_key_, this);
820 } 825 }
821 826
822 int HttpCache::Transaction::DoDoomEntryComplete(int result) { 827 int HttpCache::Transaction::DoDoomEntryComplete(int result) {
823 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL); 828 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result);
824 next_state_ = STATE_CREATE_ENTRY; 829 next_state_ = STATE_CREATE_ENTRY;
825 cache_pending_ = false; 830 cache_pending_ = false;
826 if (result == ERR_CACHE_RACE) 831 if (result == ERR_CACHE_RACE)
827 next_state_ = STATE_INIT_ENTRY; 832 next_state_ = STATE_INIT_ENTRY;
828 833
829 return OK; 834 return OK;
830 } 835 }
831 836
832 int HttpCache::Transaction::DoAddToEntry() { 837 int HttpCache::Transaction::DoAddToEntry() {
833 DCHECK(new_entry_); 838 DCHECK(new_entry_);
834 cache_pending_ = true; 839 cache_pending_ = true;
835 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; 840 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE;
836 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); 841 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY,
842 new NetLogSourceParameter("source_dependency",
843 new_entry_->net_log.source()));
837 DCHECK(entry_lock_waiting_since_.is_null()); 844 DCHECK(entry_lock_waiting_since_.is_null());
838 entry_lock_waiting_since_ = base::TimeTicks::Now(); 845 entry_lock_waiting_since_ = base::TimeTicks::Now();
839 return cache_->AddTransactionToEntry(new_entry_, this); 846 return cache_->AddTransactionToEntry(new_entry_, this);
840 } 847 }
841 848
842 int HttpCache::Transaction::DoAddToEntryComplete(int result) { 849 int HttpCache::Transaction::DoAddToEntryComplete(int result) {
843 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); 850 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, result);
844
845 const base::TimeDelta entry_lock_wait = 851 const base::TimeDelta entry_lock_wait =
846 base::TimeTicks::Now() - entry_lock_waiting_since_; 852 base::TimeTicks::Now() - entry_lock_waiting_since_;
847 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); 853 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait);
848 static const bool prefetching_fieldtrial = 854 static const bool prefetching_fieldtrial =
849 base::FieldTrialList::Find("Prefetch") && 855 base::FieldTrialList::Find("Prefetch") &&
850 !base::FieldTrialList::Find("Prefetch")->group_name().empty(); 856 !base::FieldTrialList::Find("Prefetch")->group_name().empty();
851 if (prefetching_fieldtrial) { 857 if (prefetching_fieldtrial) {
852 UMA_HISTOGRAM_TIMES( 858 UMA_HISTOGRAM_TIMES(
853 base::FieldTrial::MakeName("HttpCache.EntryLockWait", "Prefetch"), 859 base::FieldTrial::MakeName("HttpCache.EntryLockWait", "Prefetch"),
854 entry_lock_wait); 860 entry_lock_wait);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : 990 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE :
985 STATE_CACHE_WRITE_RESPONSE; 991 STATE_CACHE_WRITE_RESPONSE;
986 return OK; 992 return OK;
987 } 993 }
988 994
989 int HttpCache::Transaction::DoTruncateCachedData() { 995 int HttpCache::Transaction::DoTruncateCachedData() {
990 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; 996 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE;
991 cache_callback_->AddRef(); // Balanced in DoTruncateCachedDataComplete. 997 cache_callback_->AddRef(); // Balanced in DoTruncateCachedDataComplete.
992 if (!entry_) 998 if (!entry_)
993 return OK; 999 return OK;
1000 if (net_log_.IsLoggingAllEvents())
1001 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL);
994 1002
995 // Truncate the stream. 1003 // Truncate the stream.
996 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, cache_callback_); 1004 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, cache_callback_);
997 } 1005 }
998 1006
999 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { 1007 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) {
1008 if (net_log_.IsLoggingAllEvents() && entry_)
1009 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, result);
1010
1000 // Balance the AddRef from DoTruncateCachedData. 1011 // Balance the AddRef from DoTruncateCachedData.
1001 cache_callback_->Release(); 1012 cache_callback_->Release();
1002 next_state_ = STATE_TRUNCATE_CACHED_METADATA; 1013 next_state_ = STATE_TRUNCATE_CACHED_METADATA;
1003 return OK; 1014 return OK;
1004 } 1015 }
1005 1016
1006 int HttpCache::Transaction::DoTruncateCachedMetadata() { 1017 int HttpCache::Transaction::DoTruncateCachedMetadata() {
1007 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; 1018 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE;
1008 cache_callback_->AddRef(); // Balanced in DoTruncateCachedMetadataComplete. 1019 cache_callback_->AddRef(); // Balanced in DoTruncateCachedMetadataComplete.
1009 if (!entry_) 1020 if (!entry_)
1010 return OK; 1021 return OK;
1011 1022
1023 if (net_log_.IsLoggingAllEvents())
1024 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
rvargas (doing something else) 2010/12/11 00:29:01 This one is most likely redundant.
1012 return WriteToEntry(kMetadataIndex, 0, NULL, 0, cache_callback_); 1025 return WriteToEntry(kMetadataIndex, 0, NULL, 0, cache_callback_);
1013 } 1026 }
1014 1027
1015 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { 1028 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) {
1029 if (net_log_.IsLoggingAllEvents() && entry_)
1030 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, result);
1031
1016 // Balance the AddRef from DoTruncateCachedMetadata. 1032 // Balance the AddRef from DoTruncateCachedMetadata.
1017 cache_callback_->Release(); 1033 cache_callback_->Release();
1018 1034
1019 // If this response is a redirect, then we can stop writing now. (We don't 1035 // If this response is a redirect, then we can stop writing now. (We don't
1020 // need to cache the response body of a redirect.) 1036 // need to cache the response body of a redirect.)
1021 if (response_.headers->IsRedirect(NULL)) 1037 if (response_.headers->IsRedirect(NULL))
1022 DoneWritingToEntry(true); 1038 DoneWritingToEntry(true);
1023 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; 1039 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED;
1024 return OK; 1040 return OK;
1025 } 1041 }
(...skipping 29 matching lines...) Expand all
1055 read_buf_ = new IOBuffer(io_buf_len_); 1071 read_buf_ = new IOBuffer(io_buf_len_);
1056 1072
1057 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); 1073 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL);
1058 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete. 1074 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete.
1059 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, 1075 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_,
1060 io_buf_len_, cache_callback_); 1076 io_buf_len_, cache_callback_);
1061 } 1077 }
1062 1078
1063 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { 1079 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
1064 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse. 1080 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse.
1065 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); 1081 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result);
1066 if (result != io_buf_len_ || 1082 if (result != io_buf_len_ ||
1067 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, 1083 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_,
1068 &response_, &truncated_)) { 1084 &response_, &truncated_)) {
1069 DLOG(ERROR) << "ReadData failed: " << result; 1085 DLOG(ERROR) << "ReadData failed: " << result;
1070 return ERR_CACHE_READ_FAILURE; 1086 return ERR_CACHE_READ_FAILURE;
1071 } 1087 }
1072 1088
1073 // We now have access to the cache entry. 1089 // We now have access to the cache entry.
1074 // 1090 //
1075 // o if we are a reader for the transaction, then we can start reading the 1091 // o if we are a reader for the transaction, then we can start reading the
(...skipping 19 matching lines...) Expand all
1095 break; 1111 break;
1096 case WRITE: 1112 case WRITE:
1097 default: 1113 default:
1098 NOTREACHED(); 1114 NOTREACHED();
1099 result = ERR_FAILED; 1115 result = ERR_FAILED;
1100 } 1116 }
1101 return result; 1117 return result;
1102 } 1118 }
1103 1119
1104 int HttpCache::Transaction::DoCacheWriteResponse() { 1120 int HttpCache::Transaction::DoCacheWriteResponse() {
1121 if (net_log_.IsLoggingAllEvents() && entry_)
1122 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
1105 return WriteResponseInfoToEntry(false); 1123 return WriteResponseInfoToEntry(false);
1106 } 1124 }
1107 1125
1108 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { 1126 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() {
1127 if (net_log_.IsLoggingAllEvents() && entry_)
1128 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
1109 return WriteResponseInfoToEntry(true); 1129 return WriteResponseInfoToEntry(true);
1110 } 1130 }
1111 1131
1112 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { 1132 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) {
1113 next_state_ = target_state_; 1133 next_state_ = target_state_;
1114 target_state_ = STATE_NONE; 1134 target_state_ = STATE_NONE;
1115 if (!entry_) 1135 if (!entry_)
1116 return OK; 1136 return OK;
1137 if (net_log_.IsLoggingAllEvents())
rvargas (doing something else) 2010/12/11 00:29:01 You should probably move this before the previous
mmenke 2010/12/11 01:51:05 Both write events check for entry_'s existence bef
rvargas (doing something else) 2010/12/13 23:34:38 DoCacheWriteResponse and DoCacheWriteTruncatedResp
mmenke 2010/12/14 00:04:43 Which is why in DoCacheWriteResponse and DoCacheWr
rvargas (doing something else) 2010/12/14 00:14:26 And that just shows how blind I am!
1138 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, result);
1117 1139
1118 // Balance the AddRef from WriteResponseInfoToEntry. 1140 // Balance the AddRef from WriteResponseInfoToEntry.
1119 write_headers_callback_->Release(); 1141 write_headers_callback_->Release();
1120 if (result != io_buf_len_) { 1142 if (result != io_buf_len_) {
1121 DLOG(ERROR) << "failed to write response info to cache"; 1143 DLOG(ERROR) << "failed to write response info to cache";
1122 DoneWritingToEntry(false); 1144 DoneWritingToEntry(false);
1123 } 1145 }
1124 return OK; 1146 return OK;
1125 } 1147 }
1126 1148
1127 int HttpCache::Transaction::DoCacheReadMetadata() { 1149 int HttpCache::Transaction::DoCacheReadMetadata() {
1128 DCHECK(entry_); 1150 DCHECK(entry_);
1129 DCHECK(!response_.metadata); 1151 DCHECK(!response_.metadata);
1130 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; 1152 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE;
1131 1153
1132 response_.metadata = 1154 response_.metadata =
1133 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); 1155 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex));
1134 1156
1135 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); 1157 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL);
1136 cache_callback_->AddRef(); // Balanced in DoCacheReadMetadataComplete. 1158 cache_callback_->AddRef(); // Balanced in DoCacheReadMetadataComplete.
1137 return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, 1159 return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata,
1138 response_.metadata->size(), 1160 response_.metadata->size(),
1139 cache_callback_); 1161 cache_callback_);
1140 } 1162 }
1141 1163
1142 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { 1164 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) {
1143 cache_callback_->Release(); // Balance the AddRef from DoCacheReadMetadata. 1165 cache_callback_->Release(); // Balance the AddRef from DoCacheReadMetadata.
1144 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); 1166 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result);
1145 if (result != response_.metadata->size()) { 1167 if (result != response_.metadata->size()) {
1146 DLOG(ERROR) << "ReadData failed: " << result; 1168 DLOG(ERROR) << "ReadData failed: " << result;
1147 return ERR_CACHE_READ_FAILURE; 1169 return ERR_CACHE_READ_FAILURE;
1148 } 1170 }
1149 1171
1150 return OK; 1172 return OK;
1151 } 1173 }
1152 1174
1153 int HttpCache::Transaction::DoCacheQueryData() { 1175 int HttpCache::Transaction::DoCacheQueryData() {
1154 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; 1176 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE;
(...skipping 10 matching lines...) Expand all
1165 if (!cache_) 1187 if (!cache_)
1166 return ERR_UNEXPECTED; 1188 return ERR_UNEXPECTED;
1167 1189
1168 return ValidateEntryHeadersAndContinue(true); 1190 return ValidateEntryHeadersAndContinue(true);
1169 } 1191 }
1170 1192
1171 int HttpCache::Transaction::DoCacheReadData() { 1193 int HttpCache::Transaction::DoCacheReadData() {
1172 DCHECK(entry_); 1194 DCHECK(entry_);
1173 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; 1195 next_state_ = STATE_CACHE_READ_DATA_COMPLETE;
1174 cache_callback_->AddRef(); // Balanced in DoCacheReadDataComplete. 1196 cache_callback_->AddRef(); // Balanced in DoCacheReadDataComplete.
1197
1198 if (net_log_.IsLoggingAllEvents())
1199 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA, NULL);
rvargas (doing something else) 2010/12/11 00:29:01 Isn't this a little excessive? I'd expect a lot of
mmenke 2010/12/11 01:51:05 There is indeed a lot of noise, but it all ends up
rvargas (doing something else) 2010/12/13 23:34:38 OK, I didn't notice before that we log bytes recei
1175 if (partial_.get()) { 1200 if (partial_.get()) {
1176 return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, 1201 return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_,
1177 cache_callback_); 1202 cache_callback_);
1178 } 1203 }
1179 1204
1180 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, 1205 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_,
1181 read_buf_, io_buf_len_, cache_callback_); 1206 read_buf_, io_buf_len_, cache_callback_);
1182 } 1207 }
1183 1208
1184 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { 1209 int HttpCache::Transaction::DoCacheReadDataComplete(int result) {
1185 cache_callback_->Release(); // Balance the AddRef from DoCacheReadData. 1210 cache_callback_->Release(); // Balance the AddRef from DoCacheReadData.
1211 if (net_log_.IsLoggingAllEvents())
1212 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, result);
1186 1213
1187 if (!cache_) 1214 if (!cache_)
1188 return ERR_UNEXPECTED; 1215 return ERR_UNEXPECTED;
1189 1216
1190 if (partial_.get()) 1217 if (partial_.get())
1191 return DoPartialCacheReadCompleted(result); 1218 return DoPartialCacheReadCompleted(result);
1192 1219
1193 if (result > 0) { 1220 if (result > 0) {
1194 read_offset_ += result; 1221 read_offset_ += result;
1195 } else if (result == 0) { // End of file. 1222 } else if (result == 0) { // End of file.
1196 cache_->DoneReadingFromEntry(entry_, this); 1223 cache_->DoneReadingFromEntry(entry_, this);
1197 entry_ = NULL; 1224 entry_ = NULL;
1198 } 1225 }
1199 return result; 1226 return result;
1200 } 1227 }
1201 1228
1202 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { 1229 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) {
1203 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; 1230 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE;
1204 write_len_ = num_bytes; 1231 write_len_ = num_bytes;
1232 if (net_log_.IsLoggingAllEvents())
1233 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL);
rvargas (doing something else) 2010/12/11 00:29:01 same here.
1205 cache_callback_->AddRef(); // Balanced in DoCacheWriteDataComplete. 1234 cache_callback_->AddRef(); // Balanced in DoCacheWriteDataComplete.
1206 1235
1207 return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_); 1236 return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_);
1208 } 1237 }
1209 1238
1210 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { 1239 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) {
1240 if (net_log_.IsLoggingAllEvents() && entry_)
1241 net_log_.EndEventWithErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, result);
1211 // Balance the AddRef from DoCacheWriteData. 1242 // Balance the AddRef from DoCacheWriteData.
1212 cache_callback_->Release(); 1243 cache_callback_->Release();
1213 if (!cache_) 1244 if (!cache_)
1214 return ERR_UNEXPECTED; 1245 return ERR_UNEXPECTED;
1215 1246
1216 if (result != write_len_) { 1247 if (result != write_len_) {
1217 DLOG(ERROR) << "failed to write response data to cache"; 1248 DLOG(ERROR) << "failed to write response data to cache";
1218 DoneWritingToEntry(false); 1249 DoneWritingToEntry(false);
1219 1250
1220 // We want to ignore errors writing to disk and just keep reading from 1251 // We want to ignore errors writing to disk and just keep reading from
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1896 // |value| goes from 0 to 63. Actually, the max value should be 47 (0x2f) 1927 // |value| goes from 0 to 63. Actually, the max value should be 47 (0x2f)
1897 // but we'll see. 1928 // but we'll see.
1898 UMA_HISTOGRAM_ENUMERATION("HttpCache.ResponseHeaders", value, 65); 1929 UMA_HISTOGRAM_ENUMERATION("HttpCache.ResponseHeaders", value, 65);
1899 } 1930 }
1900 1931
1901 void HttpCache::Transaction::OnIOComplete(int result) { 1932 void HttpCache::Transaction::OnIOComplete(int result) {
1902 DoLoop(result); 1933 DoLoop(result);
1903 } 1934 }
1904 1935
1905 } // namespace net 1936 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698