OLD | NEW |
---|---|
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/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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 // and returned it. | 187 // and returned it. |
188 OFFLINE_STATUS_FRESH_CACHE, | 188 OFFLINE_STATUS_FRESH_CACHE, |
189 | 189 |
190 // A network request was required for a cache entry, and it succeeded. | 190 // A network request was required for a cache entry, and it succeeded. |
191 OFFLINE_STATUS_NETWORK_SUCCEEDED, | 191 OFFLINE_STATUS_NETWORK_SUCCEEDED, |
192 | 192 |
193 // A network request was required for a cache entry, and it failed with | 193 // A network request was required for a cache entry, and it failed with |
194 // a non-offline error. | 194 // a non-offline error. |
195 OFFLINE_STATUS_NETWORK_FAILED, | 195 OFFLINE_STATUS_NETWORK_FAILED, |
196 | 196 |
197 // A network request was required for a cache entry, it failed with an | |
198 // offline error, and we could serve stale data if | |
199 // LOAD_FROM_CACHE_IF_OFFLINE was set. | |
200 OFFLINE_STATUS_DATA_AVAILABLE_OFFLINE, | |
201 | |
202 // A network request was required for a cache entry, it failed with | 197 // A network request was required for a cache entry, it failed with |
203 // an offline error, and there was no servable data in cache (even | 198 // an offline error, and there was no servable data in cache (even |
204 // stale data). | 199 // stale data). |
205 OFFLINE_STATUS_DATA_UNAVAILABLE_OFFLINE, | 200 OFFLINE_STATUS_DATA_UNAVAILABLE_OFFLINE, |
206 | 201 |
207 OFFLINE_STATUS_MAX_ENTRIES | 202 OFFLINE_STATUS_MAX_ENTRIES |
208 }; | 203 }; |
mmenke
2015/04/23 14:41:28
You can remove this entire enum.
mmenke
2015/04/24 12:14:01
It's possible you're making the changes now, just
g.mehndiratt
2015/04/24 12:58:18
On 2015/04/23 14:41:28, mmenke (Out 4-27 to 5-1) w
g.mehndiratt
2015/04/24 12:58:18
On 2015/04/24 12:14:01, mmenke (Out 4-27 to 5-1) w
| |
209 | 204 |
210 void RecordOfflineStatus(int load_flags, RequestOfflineStatus status) { | |
211 // Restrict to main frame to keep statistics close to | |
212 // "would have shown them something useful if offline mode was enabled". | |
213 if (load_flags & net::LOAD_MAIN_FRAME) { | |
214 UMA_HISTOGRAM_ENUMERATION("HttpCache.OfflineStatus", status, | |
215 OFFLINE_STATUS_MAX_ENTRIES); | |
216 } | |
217 } | |
218 | |
219 void RecordNoStoreHeaderHistogram(int load_flags, | 205 void RecordNoStoreHeaderHistogram(int load_flags, |
220 const net::HttpResponseInfo* response) { | 206 const net::HttpResponseInfo* response) { |
221 if (load_flags & net::LOAD_MAIN_FRAME) { | 207 if (load_flags & net::LOAD_MAIN_FRAME) { |
222 UMA_HISTOGRAM_BOOLEAN( | 208 UMA_HISTOGRAM_BOOLEAN( |
223 "Net.MainFrameNoStore", | 209 "Net.MainFrameNoStore", |
224 response->headers->HasHeaderValue("cache-control", "no-store")); | 210 response->headers->HasHeaderValue("cache-control", "no-store")); |
225 } | 211 } |
226 } | 212 } |
227 | 213 |
228 base::Value* NetLogAsyncRevalidationInfoCallback( | 214 base::Value* NetLogAsyncRevalidationInfoCallback( |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1109 | 1095 |
1110 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 1096 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
1111 rv = network_trans_->Start(request_, io_callback_, net_log_); | 1097 rv = network_trans_->Start(request_, io_callback_, net_log_); |
1112 return rv; | 1098 return rv; |
1113 } | 1099 } |
1114 | 1100 |
1115 int HttpCache::Transaction::DoSendRequestComplete(int result) { | 1101 int HttpCache::Transaction::DoSendRequestComplete(int result) { |
1116 if (!cache_.get()) | 1102 if (!cache_.get()) |
1117 return ERR_UNEXPECTED; | 1103 return ERR_UNEXPECTED; |
1118 | 1104 |
1119 // If requested, and we have a readable cache entry, and we have | |
1120 // an error indicating that we're offline as opposed to in contact | |
1121 // with a bad server, read from cache anyway. | |
1122 if (IsOfflineError(result)) { | |
1123 if (mode_ == READ_WRITE && entry_ && !partial_) { | |
1124 RecordOfflineStatus(effective_load_flags_, | |
1125 OFFLINE_STATUS_DATA_AVAILABLE_OFFLINE); | |
1126 if (effective_load_flags_ & LOAD_FROM_CACHE_IF_OFFLINE) { | |
1127 UpdateTransactionPattern(PATTERN_NOT_COVERED); | |
1128 response_.server_data_unavailable = true; | |
1129 return SetupEntryForRead(); | |
1130 } | |
1131 } else { | |
1132 RecordOfflineStatus(effective_load_flags_, | |
1133 OFFLINE_STATUS_DATA_UNAVAILABLE_OFFLINE); | |
1134 } | |
1135 } else { | |
1136 RecordOfflineStatus(effective_load_flags_, | |
1137 (result == OK ? OFFLINE_STATUS_NETWORK_SUCCEEDED : | |
1138 OFFLINE_STATUS_NETWORK_FAILED)); | |
1139 } | |
1140 | |
1141 // If we tried to conditionalize the request and failed, we know | 1105 // If we tried to conditionalize the request and failed, we know |
1142 // we won't be reading from the cache after this point. | 1106 // we won't be reading from the cache after this point. |
1143 if (couldnt_conditionalize_request_) | 1107 if (couldnt_conditionalize_request_) |
1144 mode_ = WRITE; | 1108 mode_ = WRITE; |
1145 | 1109 |
1146 if (result == OK) { | 1110 if (result == OK) { |
1147 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; | 1111 next_state_ = STATE_SUCCESSFUL_SEND_REQUEST; |
1148 return OK; | 1112 return OK; |
1149 } | 1113 } |
1150 | 1114 |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2219 (!partial_->IsCurrentRangeCached() || invalid_range_)) { | 2183 (!partial_->IsCurrentRangeCached() || invalid_range_)) { |
2220 // Force revalidation for sparse or truncated entries. Note that we don't | 2184 // Force revalidation for sparse or truncated entries. Note that we don't |
2221 // want to ignore the regular validation logic just because a byte range was | 2185 // want to ignore the regular validation logic just because a byte range was |
2222 // part of the request. | 2186 // part of the request. |
2223 skip_validation = false; | 2187 skip_validation = false; |
2224 } | 2188 } |
2225 | 2189 |
2226 if (skip_validation) { | 2190 if (skip_validation) { |
2227 // TODO(ricea): Is this pattern okay for asynchronous revalidations? | 2191 // TODO(ricea): Is this pattern okay for asynchronous revalidations? |
2228 UpdateTransactionPattern(PATTERN_ENTRY_USED); | 2192 UpdateTransactionPattern(PATTERN_ENTRY_USED); |
2229 RecordOfflineStatus(effective_load_flags_, OFFLINE_STATUS_FRESH_CACHE); | |
2230 return SetupEntryForRead(); | 2193 return SetupEntryForRead(); |
2231 } else { | 2194 } else { |
2232 // Make the network request conditional, to see if we may reuse our cached | 2195 // Make the network request conditional, to see if we may reuse our cached |
2233 // response. If we cannot do so, then we just resort to a normal fetch. | 2196 // response. If we cannot do so, then we just resort to a normal fetch. |
2234 // Our mode remains READ_WRITE for a conditional request. Even if the | 2197 // Our mode remains READ_WRITE for a conditional request. Even if the |
2235 // conditionalization fails, we don't switch to WRITE mode until we | 2198 // conditionalization fails, we don't switch to WRITE mode until we |
2236 // know we won't be falling back to using the cache entry in the | 2199 // know we won't be falling back to using the cache entry in the |
2237 // LOAD_FROM_CACHE_IF_OFFLINE case. | 2200 // LOAD_FROM_CACHE_IF_OFFLINE case. |
2238 if (!ConditionalizeRequest()) { | 2201 if (!ConditionalizeRequest()) { |
2239 couldnt_conditionalize_request_ = true; | 2202 couldnt_conditionalize_request_ = true; |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3032 default: | 2995 default: |
3033 NOTREACHED(); | 2996 NOTREACHED(); |
3034 } | 2997 } |
3035 } | 2998 } |
3036 | 2999 |
3037 void HttpCache::Transaction::OnIOComplete(int result) { | 3000 void HttpCache::Transaction::OnIOComplete(int result) { |
3038 DoLoop(result); | 3001 DoLoop(result); |
3039 } | 3002 } |
3040 | 3003 |
3041 } // namespace net | 3004 } // namespace net |
OLD | NEW |