| 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 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 return OK; | 1193 return OK; |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 int HttpCache::Transaction::DoAddToEntry() { | 1196 int HttpCache::Transaction::DoAddToEntry() { |
| 1197 DCHECK(new_entry_); | 1197 DCHECK(new_entry_); |
| 1198 cache_pending_ = true; | 1198 cache_pending_ = true; |
| 1199 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 1199 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
| 1200 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); | 1200 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); |
| 1201 DCHECK(entry_lock_waiting_since_.is_null()); | 1201 DCHECK(entry_lock_waiting_since_.is_null()); |
| 1202 entry_lock_waiting_since_ = TimeTicks::Now(); | 1202 entry_lock_waiting_since_ = TimeTicks::Now(); |
| 1203 return cache_->AddTransactionToEntry(new_entry_, this); | 1203 |
| 1204 int result = cache_->AddTransactionToEntry(new_entry_, this); |
| 1205 |
| 1206 // If we're a range request and we're blocked by the reader/writer lock, then |
| 1207 // we'll switch to pass-through mode, this eliminates a long-running issue |
| 1208 // (crbug.com/31014) where two of the same video resource could not be played |
| 1209 // back simultaneously due to one locking the cache entry until the entire |
| 1210 // video was downloaded. |
| 1211 // |
| 1212 // This is not an ideal solution, as we are now ignoring the cache entirely |
| 1213 // for all range requests to a resource beyond the first. This is however a |
| 1214 // much more succinct solution than the alternatives, which would require |
| 1215 // somewhat significant changes to the http caching logic. |
| 1216 // TODO(rileya): Support simultaneous transactions on sparse cache entries, |
| 1217 // and remove this hack (crbug.com/362215). |
| 1218 if (partial_ && result == net::ERR_IO_PENDING && (new_entry_->writer || |
| 1219 (mode() & Transaction::WRITE && !new_entry_->readers.empty()))) { |
| 1220 entry_lock_waiting_since_ = TimeTicks(); |
| 1221 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); |
| 1222 mode_ = NONE; |
| 1223 partial_->RestoreHeaders(&custom_request_->extra_headers); |
| 1224 partial_.reset(); |
| 1225 next_state_ = STATE_SEND_REQUEST; |
| 1226 cache_pending_ = false; |
| 1227 cache_->RemovePendingTransaction(this); |
| 1228 new_entry_ = NULL; |
| 1229 return OK; |
| 1230 } |
| 1231 return result; |
| 1204 } | 1232 } |
| 1205 | 1233 |
| 1206 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 1234 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
| 1207 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, | 1235 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, |
| 1208 result); | 1236 result); |
| 1209 const TimeDelta entry_lock_wait = | 1237 const TimeDelta entry_lock_wait = |
| 1210 TimeTicks::Now() - entry_lock_waiting_since_; | 1238 TimeTicks::Now() - entry_lock_waiting_since_; |
| 1211 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); | 1239 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); |
| 1212 | 1240 |
| 1213 entry_lock_waiting_since_ = TimeTicks(); | 1241 entry_lock_waiting_since_ = TimeTicks(); |
| (...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2520 default: | 2548 default: |
| 2521 NOTREACHED(); | 2549 NOTREACHED(); |
| 2522 } | 2550 } |
| 2523 } | 2551 } |
| 2524 | 2552 |
| 2525 void HttpCache::Transaction::OnIOComplete(int result) { | 2553 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2526 DoLoop(result); | 2554 DoLoop(result); |
| 2527 } | 2555 } |
| 2528 | 2556 |
| 2529 } // namespace net | 2557 } // namespace net |
| OLD | NEW |