| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   391 } |   391 } | 
|   392  |   392  | 
|   393 LoadState HttpCache::Transaction::GetWriterLoadState() const { |   393 LoadState HttpCache::Transaction::GetWriterLoadState() const { | 
|   394   if (network_trans_.get()) |   394   if (network_trans_.get()) | 
|   395     return network_trans_->GetLoadState(); |   395     return network_trans_->GetLoadState(); | 
|   396   if (entry_ || !request_) |   396   if (entry_ || !request_) | 
|   397     return LOAD_STATE_IDLE; |   397     return LOAD_STATE_IDLE; | 
|   398   return LOAD_STATE_WAITING_FOR_CACHE; |   398   return LOAD_STATE_WAITING_FOR_CACHE; | 
|   399 } |   399 } | 
|   400  |   400  | 
 |   401 const BoundNetLog& HttpCache::Transaction::net_log() const { | 
 |   402   return net_log_; | 
 |   403 } | 
 |   404  | 
|   401 //----------------------------------------------------------------------------- |   405 //----------------------------------------------------------------------------- | 
|   402  |   406  | 
|   403 void HttpCache::Transaction::DoCallback(int rv) { |   407 void HttpCache::Transaction::DoCallback(int rv) { | 
|   404   DCHECK(rv != ERR_IO_PENDING); |   408   DCHECK(rv != ERR_IO_PENDING); | 
|   405   DCHECK(callback_); |   409   DCHECK(callback_); | 
|   406  |   410  | 
|   407   // Since Run may result in Read being called, clear callback_ up front. |   411   // Since Run may result in Read being called, clear callback_ up front. | 
|   408   CompletionCallback* c = callback_; |   412   CompletionCallback* c = callback_; | 
|   409   callback_ = NULL; |   413   callback_ = NULL; | 
|   410   c->Run(rv); |   414   c->Run(rv); | 
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   572  |   576  | 
|   573   if (rv != ERR_IO_PENDING) |   577   if (rv != ERR_IO_PENDING) | 
|   574     HandleResult(rv); |   578     HandleResult(rv); | 
|   575  |   579  | 
|   576   return rv; |   580   return rv; | 
|   577 } |   581 } | 
|   578  |   582  | 
|   579 int HttpCache::Transaction::DoGetBackend() { |   583 int HttpCache::Transaction::DoGetBackend() { | 
|   580   cache_pending_ = true; |   584   cache_pending_ = true; | 
|   581   next_state_ = STATE_GET_BACKEND_COMPLETE; |   585   next_state_ = STATE_GET_BACKEND_COMPLETE; | 
|   582   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); |   586   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, NULL); | 
|   583   return cache_->GetBackendForTransaction(this); |   587   return cache_->GetBackendForTransaction(this); | 
|   584 } |   588 } | 
|   585  |   589  | 
|   586 int HttpCache::Transaction::DoGetBackendComplete(int result) { |   590 int HttpCache::Transaction::DoGetBackendComplete(int result) { | 
|   587   DCHECK(result == OK || result == ERR_FAILED); |   591   DCHECK(result == OK || result == ERR_FAILED); | 
|   588   net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); |   592   net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, | 
 |   593                                     result); | 
|   589   cache_pending_ = false; |   594   cache_pending_ = false; | 
|   590  |   595  | 
|   591   if (!ShouldPassThrough()) { |   596   if (!ShouldPassThrough()) { | 
|   592     cache_key_ = cache_->GenerateCacheKey(request_); |   597     cache_key_ = cache_->GenerateCacheKey(request_); | 
|   593  |   598  | 
|   594     // Requested cache access mode. |   599     // Requested cache access mode. | 
|   595     if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { |   600     if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { | 
|   596       mode_ = READ; |   601       mode_ = READ; | 
|   597     } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { |   602     } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { | 
|   598       mode_ = WRITE; |   603       mode_ = WRITE; | 
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   750   next_state_ = STATE_OPEN_ENTRY_COMPLETE; |   755   next_state_ = STATE_OPEN_ENTRY_COMPLETE; | 
|   751   cache_pending_ = true; |   756   cache_pending_ = true; | 
|   752   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL); |   757   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL); | 
|   753   return cache_->OpenEntry(cache_key_, &new_entry_, this); |   758   return cache_->OpenEntry(cache_key_, &new_entry_, this); | 
|   754 } |   759 } | 
|   755  |   760  | 
|   756 int HttpCache::Transaction::DoOpenEntryComplete(int result) { |   761 int HttpCache::Transaction::DoOpenEntryComplete(int result) { | 
|   757   // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |   762   // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 
|   758   // OK, otherwise the cache will end up with an active entry without any |   763   // OK, otherwise the cache will end up with an active entry without any | 
|   759   // transaction attached. |   764   // transaction attached. | 
|   760   net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL); |   765   net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); | 
|   761   cache_pending_ = false; |   766   cache_pending_ = false; | 
|   762   if (result == OK) { |   767   if (result == OK) { | 
|   763     next_state_ = STATE_ADD_TO_ENTRY; |   768     next_state_ = STATE_ADD_TO_ENTRY; | 
|   764     return OK; |   769     return OK; | 
|   765   } |   770   } | 
|   766  |   771  | 
|   767   if (result == ERR_CACHE_RACE) { |   772   if (result == ERR_CACHE_RACE) { | 
|   768     next_state_ = STATE_INIT_ENTRY; |   773     next_state_ = STATE_INIT_ENTRY; | 
|   769     return OK; |   774     return OK; | 
|   770   } |   775   } | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|   793   next_state_ = STATE_CREATE_ENTRY_COMPLETE; |   798   next_state_ = STATE_CREATE_ENTRY_COMPLETE; | 
|   794   cache_pending_ = true; |   799   cache_pending_ = true; | 
|   795   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL); |   800   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL); | 
|   796   return cache_->CreateEntry(cache_key_, &new_entry_, this); |   801   return cache_->CreateEntry(cache_key_, &new_entry_, this); | 
|   797 } |   802 } | 
|   798  |   803  | 
|   799 int HttpCache::Transaction::DoCreateEntryComplete(int result) { |   804 int HttpCache::Transaction::DoCreateEntryComplete(int result) { | 
|   800   // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |   805   // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 
|   801   // OK, otherwise the cache will end up with an active entry without any |   806   // OK, otherwise the cache will end up with an active entry without any | 
|   802   // transaction attached. |   807   // transaction attached. | 
|   803   net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL); |   808   net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, | 
 |   809                                     result); | 
|   804   cache_pending_ = false; |   810   cache_pending_ = false; | 
|   805   next_state_ = STATE_ADD_TO_ENTRY; |   811   next_state_ = STATE_ADD_TO_ENTRY; | 
|   806  |   812  | 
|   807   if (result == ERR_CACHE_RACE) { |   813   if (result == ERR_CACHE_RACE) { | 
|   808     next_state_ = STATE_INIT_ENTRY; |   814     next_state_ = STATE_INIT_ENTRY; | 
|   809     return OK; |   815     return OK; | 
|   810   } |   816   } | 
|   811  |   817  | 
|   812   if (result != OK) { |   818   if (result != OK) { | 
|   813     // We have a race here: Maybe we failed to open the entry and decided to |   819     // We have a race here: Maybe we failed to open the entry and decided to | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|   824 } |   830 } | 
|   825  |   831  | 
|   826 int HttpCache::Transaction::DoDoomEntry() { |   832 int HttpCache::Transaction::DoDoomEntry() { | 
|   827   next_state_ = STATE_DOOM_ENTRY_COMPLETE; |   833   next_state_ = STATE_DOOM_ENTRY_COMPLETE; | 
|   828   cache_pending_ = true; |   834   cache_pending_ = true; | 
|   829   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL); |   835   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL); | 
|   830   return cache_->DoomEntry(cache_key_, this); |   836   return cache_->DoomEntry(cache_key_, this); | 
|   831 } |   837 } | 
|   832  |   838  | 
|   833 int HttpCache::Transaction::DoDoomEntryComplete(int result) { |   839 int HttpCache::Transaction::DoDoomEntryComplete(int result) { | 
|   834   net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL); |   840   net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result); | 
|   835   next_state_ = STATE_CREATE_ENTRY; |   841   next_state_ = STATE_CREATE_ENTRY; | 
|   836   cache_pending_ = false; |   842   cache_pending_ = false; | 
|   837   if (result == ERR_CACHE_RACE) |   843   if (result == ERR_CACHE_RACE) | 
|   838     next_state_ = STATE_INIT_ENTRY; |   844     next_state_ = STATE_INIT_ENTRY; | 
|   839  |   845  | 
|   840   return OK; |   846   return OK; | 
|   841 } |   847 } | 
|   842  |   848  | 
|   843 int HttpCache::Transaction::DoAddToEntry() { |   849 int HttpCache::Transaction::DoAddToEntry() { | 
|   844   DCHECK(new_entry_); |   850   DCHECK(new_entry_); | 
|   845   cache_pending_ = true; |   851   cache_pending_ = true; | 
|   846   next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |   852   next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 
|   847   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); |   853   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, NULL); | 
|   848   DCHECK(entry_lock_waiting_since_.is_null()); |   854   DCHECK(entry_lock_waiting_since_.is_null()); | 
|   849   entry_lock_waiting_since_ = base::TimeTicks::Now(); |   855   entry_lock_waiting_since_ = base::TimeTicks::Now(); | 
|   850   return cache_->AddTransactionToEntry(new_entry_, this); |   856   return cache_->AddTransactionToEntry(new_entry_, this); | 
|   851 } |   857 } | 
|   852  |   858  | 
|   853 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |   859 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 
|   854   net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); |   860   net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, | 
 |   861                                     result); | 
|   855  |   862  | 
|   856   const base::TimeDelta entry_lock_wait = |   863   const base::TimeDelta entry_lock_wait = | 
|   857       base::TimeTicks::Now() - entry_lock_waiting_since_; |   864       base::TimeTicks::Now() - entry_lock_waiting_since_; | 
|   858   UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); |   865   UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); | 
|   859   static const bool prefetching_fieldtrial = |   866   static const bool prefetching_fieldtrial = | 
|   860       base::FieldTrialList::Find("Prefetch") && |   867       base::FieldTrialList::Find("Prefetch") && | 
|   861       !base::FieldTrialList::Find("Prefetch")->group_name().empty(); |   868       !base::FieldTrialList::Find("Prefetch")->group_name().empty(); | 
|   862   if (prefetching_fieldtrial) { |   869   if (prefetching_fieldtrial) { | 
|   863     UMA_HISTOGRAM_TIMES( |   870     UMA_HISTOGRAM_TIMES( | 
|   864         base::FieldTrial::MakeName("HttpCache.EntryLockWait", "Prefetch"), |   871         base::FieldTrial::MakeName("HttpCache.EntryLockWait", "Prefetch"), | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   995   next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : |  1002   next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : | 
|   996                              STATE_CACHE_WRITE_RESPONSE; |  1003                              STATE_CACHE_WRITE_RESPONSE; | 
|   997   return OK; |  1004   return OK; | 
|   998 } |  1005 } | 
|   999  |  1006  | 
|  1000 int HttpCache::Transaction::DoTruncateCachedData() { |  1007 int HttpCache::Transaction::DoTruncateCachedData() { | 
|  1001   next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; |  1008   next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; | 
|  1002   cache_callback_->AddRef();  // Balanced in DoTruncateCachedDataComplete. |  1009   cache_callback_->AddRef();  // Balanced in DoTruncateCachedDataComplete. | 
|  1003   if (!entry_) |  1010   if (!entry_) | 
|  1004     return OK; |  1011     return OK; | 
 |  1012   if (net_log_.IsLoggingAllEvents()) | 
 |  1013     net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL); | 
|  1005  |  1014  | 
|  1006   // Truncate the stream. |  1015   // Truncate the stream. | 
|  1007   return WriteToEntry(kResponseContentIndex, 0, NULL, 0, cache_callback_); |  1016   return WriteToEntry(kResponseContentIndex, 0, NULL, 0, cache_callback_); | 
|  1008 } |  1017 } | 
|  1009  |  1018  | 
|  1010 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { |  1019 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { | 
 |  1020   if (net_log_.IsLoggingAllEvents() && entry_) { | 
 |  1021     net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | 
 |  1022                                       result); | 
 |  1023   } | 
 |  1024  | 
|  1011   // Balance the AddRef from DoTruncateCachedData. |  1025   // Balance the AddRef from DoTruncateCachedData. | 
|  1012   cache_callback_->Release(); |  1026   cache_callback_->Release(); | 
|  1013   next_state_ = STATE_TRUNCATE_CACHED_METADATA; |  1027   next_state_ = STATE_TRUNCATE_CACHED_METADATA; | 
|  1014   return OK; |  1028   return OK; | 
|  1015 } |  1029 } | 
|  1016  |  1030  | 
|  1017 int HttpCache::Transaction::DoTruncateCachedMetadata() { |  1031 int HttpCache::Transaction::DoTruncateCachedMetadata() { | 
|  1018   next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; |  1032   next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; | 
|  1019   cache_callback_->AddRef();  // Balanced in DoTruncateCachedMetadataComplete. |  1033   cache_callback_->AddRef();  // Balanced in DoTruncateCachedMetadataComplete. | 
|  1020   if (!entry_) |  1034   if (!entry_) | 
|  1021     return OK; |  1035     return OK; | 
|  1022  |  1036  | 
 |  1037   if (net_log_.IsLoggingAllEvents()) | 
 |  1038     net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); | 
|  1023   return WriteToEntry(kMetadataIndex, 0, NULL, 0, cache_callback_); |  1039   return WriteToEntry(kMetadataIndex, 0, NULL, 0, cache_callback_); | 
|  1024 } |  1040 } | 
|  1025  |  1041  | 
|  1026 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { |  1042 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { | 
 |  1043   if (net_log_.IsLoggingAllEvents() && entry_) { | 
 |  1044     net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | 
 |  1045                                       result); | 
 |  1046   } | 
 |  1047  | 
|  1027   // Balance the AddRef from DoTruncateCachedMetadata. |  1048   // Balance the AddRef from DoTruncateCachedMetadata. | 
|  1028   cache_callback_->Release(); |  1049   cache_callback_->Release(); | 
|  1029  |  1050  | 
|  1030   // If this response is a redirect, then we can stop writing now.  (We don't |  1051   // If this response is a redirect, then we can stop writing now.  (We don't | 
|  1031   // need to cache the response body of a redirect.) |  1052   // need to cache the response body of a redirect.) | 
|  1032   if (response_.headers->IsRedirect(NULL)) |  1053   if (response_.headers->IsRedirect(NULL)) | 
|  1033     DoneWritingToEntry(true); |  1054     DoneWritingToEntry(true); | 
|  1034   next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |  1055   next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 
|  1035   return OK; |  1056   return OK; | 
|  1036 } |  1057 } | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|  1066   read_buf_ = new IOBuffer(io_buf_len_); |  1087   read_buf_ = new IOBuffer(io_buf_len_); | 
|  1067  |  1088  | 
|  1068   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |  1089   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); | 
|  1069   cache_callback_->AddRef();  // Balanced in DoCacheReadResponseComplete. |  1090   cache_callback_->AddRef();  // Balanced in DoCacheReadResponseComplete. | 
|  1070   return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, |  1091   return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, | 
|  1071                                       io_buf_len_, cache_callback_); |  1092                                       io_buf_len_, cache_callback_); | 
|  1072 } |  1093 } | 
|  1073  |  1094  | 
|  1074 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |  1095 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { | 
|  1075   cache_callback_->Release();  // Balance the AddRef from DoCacheReadResponse. |  1096   cache_callback_->Release();  // Balance the AddRef from DoCacheReadResponse. | 
|  1076   net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |  1097   net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 
|  1077   if (result != io_buf_len_ || |  1098   if (result != io_buf_len_ || | 
|  1078       !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, |  1099       !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, | 
|  1079                                     &response_, &truncated_)) { |  1100                                     &response_, &truncated_)) { | 
|  1080     DLOG(ERROR) << "ReadData failed: " << result; |  1101     DLOG(ERROR) << "ReadData failed: " << result; | 
|  1081     return ERR_CACHE_READ_FAILURE; |  1102     return ERR_CACHE_READ_FAILURE; | 
|  1082   } |  1103   } | 
|  1083  |  1104  | 
|  1084   // We now have access to the cache entry. |  1105   // We now have access to the cache entry. | 
|  1085   // |  1106   // | 
|  1086   //  o if we are a reader for the transaction, then we can start reading the |  1107   //  o if we are a reader for the transaction, then we can start reading the | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  1106       break; |  1127       break; | 
|  1107     case WRITE: |  1128     case WRITE: | 
|  1108     default: |  1129     default: | 
|  1109       NOTREACHED(); |  1130       NOTREACHED(); | 
|  1110       result = ERR_FAILED; |  1131       result = ERR_FAILED; | 
|  1111   } |  1132   } | 
|  1112   return result; |  1133   return result; | 
|  1113 } |  1134 } | 
|  1114  |  1135  | 
|  1115 int HttpCache::Transaction::DoCacheWriteResponse() { |  1136 int HttpCache::Transaction::DoCacheWriteResponse() { | 
 |  1137   if (net_log_.IsLoggingAllEvents() && entry_) | 
 |  1138     net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); | 
|  1116   return WriteResponseInfoToEntry(false); |  1139   return WriteResponseInfoToEntry(false); | 
|  1117 } |  1140 } | 
|  1118  |  1141  | 
|  1119 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |  1142 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 
 |  1143   if (net_log_.IsLoggingAllEvents() && entry_) | 
 |  1144     net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); | 
|  1120   return WriteResponseInfoToEntry(true); |  1145   return WriteResponseInfoToEntry(true); | 
|  1121 } |  1146 } | 
|  1122  |  1147  | 
|  1123 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |  1148 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 
|  1124   next_state_ = target_state_; |  1149   next_state_ = target_state_; | 
|  1125   target_state_ = STATE_NONE; |  1150   target_state_ = STATE_NONE; | 
|  1126   if (!entry_) |  1151   if (!entry_) | 
|  1127     return OK; |  1152     return OK; | 
 |  1153   if (net_log_.IsLoggingAllEvents()) { | 
 |  1154     net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | 
 |  1155                                       result); | 
 |  1156   } | 
|  1128  |  1157  | 
|  1129   // Balance the AddRef from WriteResponseInfoToEntry. |  1158   // Balance the AddRef from WriteResponseInfoToEntry. | 
|  1130   write_headers_callback_->Release(); |  1159   write_headers_callback_->Release(); | 
|  1131   if (result != io_buf_len_) { |  1160   if (result != io_buf_len_) { | 
|  1132     DLOG(ERROR) << "failed to write response info to cache"; |  1161     DLOG(ERROR) << "failed to write response info to cache"; | 
|  1133     DoneWritingToEntry(false); |  1162     DoneWritingToEntry(false); | 
|  1134   } |  1163   } | 
|  1135   return OK; |  1164   return OK; | 
|  1136 } |  1165 } | 
|  1137  |  1166  | 
|  1138 int HttpCache::Transaction::DoCacheReadMetadata() { |  1167 int HttpCache::Transaction::DoCacheReadMetadata() { | 
|  1139   DCHECK(entry_); |  1168   DCHECK(entry_); | 
|  1140   DCHECK(!response_.metadata); |  1169   DCHECK(!response_.metadata); | 
|  1141   next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; |  1170   next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; | 
|  1142  |  1171  | 
|  1143   response_.metadata = |  1172   response_.metadata = | 
|  1144       new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |  1173       new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); | 
|  1145  |  1174  | 
|  1146   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |  1175   net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); | 
|  1147   cache_callback_->AddRef();  // Balanced in DoCacheReadMetadataComplete. |  1176   cache_callback_->AddRef();  // Balanced in DoCacheReadMetadataComplete. | 
|  1148   return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, |  1177   return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, | 
|  1149                                       response_.metadata->size(), |  1178                                       response_.metadata->size(), | 
|  1150                                       cache_callback_); |  1179                                       cache_callback_); | 
|  1151 } |  1180 } | 
|  1152  |  1181  | 
|  1153 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |  1182 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { | 
|  1154   cache_callback_->Release();  // Balance the AddRef from DoCacheReadMetadata. |  1183   cache_callback_->Release();  // Balance the AddRef from DoCacheReadMetadata. | 
|  1155   net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |  1184   net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 
|  1156   if (result != response_.metadata->size()) { |  1185   if (result != response_.metadata->size()) { | 
|  1157     DLOG(ERROR) << "ReadData failed: " << result; |  1186     DLOG(ERROR) << "ReadData failed: " << result; | 
|  1158     return ERR_CACHE_READ_FAILURE; |  1187     return ERR_CACHE_READ_FAILURE; | 
|  1159   } |  1188   } | 
|  1160  |  1189  | 
|  1161   return OK; |  1190   return OK; | 
|  1162 } |  1191 } | 
|  1163  |  1192  | 
|  1164 int HttpCache::Transaction::DoCacheQueryData() { |  1193 int HttpCache::Transaction::DoCacheQueryData() { | 
|  1165   next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; |  1194   next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  1176   if (!cache_) |  1205   if (!cache_) | 
|  1177     return ERR_UNEXPECTED; |  1206     return ERR_UNEXPECTED; | 
|  1178  |  1207  | 
|  1179   return ValidateEntryHeadersAndContinue(true); |  1208   return ValidateEntryHeadersAndContinue(true); | 
|  1180 } |  1209 } | 
|  1181  |  1210  | 
|  1182 int HttpCache::Transaction::DoCacheReadData() { |  1211 int HttpCache::Transaction::DoCacheReadData() { | 
|  1183   DCHECK(entry_); |  1212   DCHECK(entry_); | 
|  1184   next_state_ = STATE_CACHE_READ_DATA_COMPLETE; |  1213   next_state_ = STATE_CACHE_READ_DATA_COMPLETE; | 
|  1185   cache_callback_->AddRef();  // Balanced in DoCacheReadDataComplete. |  1214   cache_callback_->AddRef();  // Balanced in DoCacheReadDataComplete. | 
 |  1215  | 
 |  1216   if (net_log_.IsLoggingAllEvents()) | 
 |  1217     net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA, NULL); | 
|  1186   if (partial_.get()) { |  1218   if (partial_.get()) { | 
|  1187     return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, |  1219     return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, | 
|  1188                                cache_callback_); |  1220                                cache_callback_); | 
|  1189   } |  1221   } | 
|  1190  |  1222  | 
|  1191   return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |  1223   return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 
|  1192                                       read_buf_, io_buf_len_, cache_callback_); |  1224                                       read_buf_, io_buf_len_, cache_callback_); | 
|  1193 } |  1225 } | 
|  1194  |  1226  | 
|  1195 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |  1227 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { | 
|  1196   cache_callback_->Release();  // Balance the AddRef from DoCacheReadData. |  1228   cache_callback_->Release();  // Balance the AddRef from DoCacheReadData. | 
 |  1229   if (net_log_.IsLoggingAllEvents()) { | 
 |  1230     net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, | 
 |  1231                                       result); | 
 |  1232   } | 
|  1197  |  1233  | 
|  1198   if (!cache_) |  1234   if (!cache_) | 
|  1199     return ERR_UNEXPECTED; |  1235     return ERR_UNEXPECTED; | 
|  1200  |  1236  | 
|  1201   if (partial_.get()) |  1237   if (partial_.get()) | 
|  1202     return DoPartialCacheReadCompleted(result); |  1238     return DoPartialCacheReadCompleted(result); | 
|  1203  |  1239  | 
|  1204   if (result > 0) { |  1240   if (result > 0) { | 
|  1205     read_offset_ += result; |  1241     read_offset_ += result; | 
|  1206   } else if (result == 0) {  // End of file. |  1242   } else if (result == 0) {  // End of file. | 
|  1207     cache_->DoneReadingFromEntry(entry_, this); |  1243     cache_->DoneReadingFromEntry(entry_, this); | 
|  1208     entry_ = NULL; |  1244     entry_ = NULL; | 
|  1209   } |  1245   } | 
|  1210   return result; |  1246   return result; | 
|  1211 } |  1247 } | 
|  1212  |  1248  | 
|  1213 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |  1249 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 
|  1214   next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |  1250   next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 
|  1215   write_len_ = num_bytes; |  1251   write_len_ = num_bytes; | 
 |  1252   if (net_log_.IsLoggingAllEvents() && entry_) | 
 |  1253     net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL); | 
|  1216   cache_callback_->AddRef();  // Balanced in DoCacheWriteDataComplete. |  1254   cache_callback_->AddRef();  // Balanced in DoCacheWriteDataComplete. | 
|  1217  |  1255  | 
|  1218   return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_); |  1256   return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_); | 
|  1219 } |  1257 } | 
|  1220  |  1258  | 
|  1221 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |  1259 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 
 |  1260   if (net_log_.IsLoggingAllEvents() && entry_) { | 
 |  1261     net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | 
 |  1262                                       result); | 
 |  1263   } | 
|  1222   // Balance the AddRef from DoCacheWriteData. |  1264   // Balance the AddRef from DoCacheWriteData. | 
|  1223   cache_callback_->Release(); |  1265   cache_callback_->Release(); | 
|  1224   if (!cache_) |  1266   if (!cache_) | 
|  1225     return ERR_UNEXPECTED; |  1267     return ERR_UNEXPECTED; | 
|  1226  |  1268  | 
|  1227   if (result != write_len_) { |  1269   if (result != write_len_) { | 
|  1228     DLOG(ERROR) << "failed to write response data to cache"; |  1270     DLOG(ERROR) << "failed to write response data to cache"; | 
|  1229     DoneWritingToEntry(false); |  1271     DoneWritingToEntry(false); | 
|  1230  |  1272  | 
|  1231     // We want to ignore errors writing to disk and just keep reading from |  1273     // We want to ignore errors writing to disk and just keep reading from | 
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1866     next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |  1908     next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 
|  1867   } |  1909   } | 
|  1868   return result; |  1910   return result; | 
|  1869 } |  1911 } | 
|  1870  |  1912  | 
|  1871 void HttpCache::Transaction::OnIOComplete(int result) { |  1913 void HttpCache::Transaction::OnIOComplete(int result) { | 
|  1872   DoLoop(result); |  1914   DoLoop(result); | 
|  1873 } |  1915 } | 
|  1874  |  1916  | 
|  1875 }  // namespace net |  1917 }  // namespace net | 
| OLD | NEW |