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