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 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 cache_pending_ = true; | 1383 cache_pending_ = true; |
1384 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 1384 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
1385 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); | 1385 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); |
1386 DCHECK(entry_lock_waiting_since_.is_null()); | 1386 DCHECK(entry_lock_waiting_since_.is_null()); |
1387 entry_lock_waiting_since_ = TimeTicks::Now(); | 1387 entry_lock_waiting_since_ = TimeTicks::Now(); |
1388 int rv = cache_->AddTransactionToEntry(new_entry_, this); | 1388 int rv = cache_->AddTransactionToEntry(new_entry_, this); |
1389 if (rv == ERR_IO_PENDING) { | 1389 if (rv == ERR_IO_PENDING) { |
1390 if (bypass_lock_for_test_) { | 1390 if (bypass_lock_for_test_) { |
1391 OnAddToEntryTimeout(entry_lock_waiting_since_); | 1391 OnAddToEntryTimeout(entry_lock_waiting_since_); |
1392 } else { | 1392 } else { |
1393 int timeout_secs = 20; | 1393 int timeout_milliseconds = 20 * 1000; |
1394 if (partial_ && new_entry_->writer && | 1394 if (partial_ && new_entry_->writer && |
1395 new_entry_->writer->range_requested_) { | 1395 new_entry_->writer->range_requested_) { |
1396 // Immediately timeout and bypass the cache if we're a range request and | 1396 // Quickly timeout and bypass the cache if we're a range request and |
1397 // we're blocked by the reader/writer lock. Doing so eliminates a long | 1397 // we're blocked by the reader/writer lock. Doing so eliminates a long |
1398 // running issue, http://crbug.com/31014, where two of the same media | 1398 // running issue, http://crbug.com/31014, where two of the same media |
1399 // resources could not be played back simultaneously due to one locking | 1399 // resources could not be played back simultaneously due to one locking |
1400 // the cache entry until the entire video was downloaded. | 1400 // the cache entry until the entire video was downloaded. |
1401 // | 1401 // |
1402 // Bypassing the cache is not ideal, as we are now ignoring the cache | 1402 // Bypassing the cache is not ideal, as we are now ignoring the cache |
1403 // entirely for all range requests to a resource beyond the first. This | 1403 // entirely for all range requests to a resource beyond the first. This |
1404 // is however a much more succinct solution than the alternatives, which | 1404 // is however a much more succinct solution than the alternatives, which |
1405 // would require somewhat significant changes to the http caching logic. | 1405 // would require somewhat significant changes to the http caching logic. |
1406 timeout_secs = 0; | 1406 // |
| 1407 // Allow some timeout slack for the entry addition to complete in case |
| 1408 // the writer lock is imminently released; we want to avoid skipping |
| 1409 // the cache if at all possible. See http://crbug.com/408765 |
| 1410 timeout_milliseconds = 25; |
1407 } | 1411 } |
1408 base::MessageLoop::current()->PostDelayedTask( | 1412 base::MessageLoop::current()->PostDelayedTask( |
1409 FROM_HERE, | 1413 FROM_HERE, |
1410 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, | 1414 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, |
1411 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), | 1415 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), |
1412 TimeDelta::FromSeconds(timeout_secs)); | 1416 TimeDelta::FromMilliseconds(timeout_milliseconds)); |
1413 } | 1417 } |
1414 } | 1418 } |
1415 return rv; | 1419 return rv; |
1416 } | 1420 } |
1417 | 1421 |
1418 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 1422 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
1419 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, | 1423 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, |
1420 result); | 1424 result); |
1421 const TimeDelta entry_lock_wait = | 1425 const TimeDelta entry_lock_wait = |
1422 TimeTicks::Now() - entry_lock_waiting_since_; | 1426 TimeTicks::Now() - entry_lock_waiting_since_; |
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2892 default: | 2896 default: |
2893 NOTREACHED(); | 2897 NOTREACHED(); |
2894 } | 2898 } |
2895 } | 2899 } |
2896 | 2900 |
2897 void HttpCache::Transaction::OnIOComplete(int result) { | 2901 void HttpCache::Transaction::OnIOComplete(int result) { |
2898 DoLoop(result); | 2902 DoLoop(result); |
2899 } | 2903 } |
2900 | 2904 |
2901 } // namespace net | 2905 } // namespace net |
OLD | NEW |