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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 reading_(false), | 196 reading_(false), |
197 invalid_range_(false), | 197 invalid_range_(false), |
198 truncated_(false), | 198 truncated_(false), |
199 is_sparse_(false), | 199 is_sparse_(false), |
200 range_requested_(false), | 200 range_requested_(false), |
201 handling_206_(false), | 201 handling_206_(false), |
202 cache_pending_(false), | 202 cache_pending_(false), |
203 done_reading_(false), | 203 done_reading_(false), |
204 vary_mismatch_(false), | 204 vary_mismatch_(false), |
205 couldnt_conditionalize_request_(false), | 205 couldnt_conditionalize_request_(false), |
206 bypass_lock_for_test_(false), | |
206 io_buf_len_(0), | 207 io_buf_len_(0), |
207 read_offset_(0), | 208 read_offset_(0), |
208 effective_load_flags_(0), | 209 effective_load_flags_(0), |
209 write_len_(0), | 210 write_len_(0), |
210 weak_factory_(this), | 211 weak_factory_(this), |
211 io_callback_(base::Bind(&Transaction::OnIOComplete, | 212 io_callback_(base::Bind(&Transaction::OnIOComplete, |
212 weak_factory_.GetWeakPtr())), | 213 weak_factory_.GetWeakPtr())), |
213 transaction_pattern_(PATTERN_UNDEFINED), | 214 transaction_pattern_(PATTERN_UNDEFINED), |
214 total_received_bytes_(0), | 215 total_received_bytes_(0), |
215 websocket_handshake_stream_base_create_helper_(NULL) { | 216 websocket_handshake_stream_base_create_helper_(NULL) { |
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1193 return OK; | 1194 return OK; |
1194 } | 1195 } |
1195 | 1196 |
1196 int HttpCache::Transaction::DoAddToEntry() { | 1197 int HttpCache::Transaction::DoAddToEntry() { |
1197 DCHECK(new_entry_); | 1198 DCHECK(new_entry_); |
1198 cache_pending_ = true; | 1199 cache_pending_ = true; |
1199 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 1200 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
1200 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); | 1201 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); |
1201 DCHECK(entry_lock_waiting_since_.is_null()); | 1202 DCHECK(entry_lock_waiting_since_.is_null()); |
1202 entry_lock_waiting_since_ = TimeTicks::Now(); | 1203 entry_lock_waiting_since_ = TimeTicks::Now(); |
1203 return cache_->AddTransactionToEntry(new_entry_, this); | 1204 int rv = cache_->AddTransactionToEntry(new_entry_, this); |
1205 if (rv == ERR_IO_PENDING) { | |
1206 if (bypass_lock_for_test_) { | |
1207 OnAddToEntryTimeout(entry_lock_waiting_since_); | |
1208 } else { | |
1209 base::MessageLoop::current()->PostDelayedTask( | |
1210 FROM_HERE, | |
1211 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, | |
1212 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), | |
1213 TimeDelta::FromSeconds(20)); | |
davidben
2014/06/20 19:28:35
Nit: Pull the timeout up to a constant?
| |
1214 } | |
1215 } | |
1216 return rv; | |
1204 } | 1217 } |
1205 | 1218 |
1206 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 1219 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
1207 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, | 1220 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, |
1208 result); | 1221 result); |
1209 const TimeDelta entry_lock_wait = | 1222 const TimeDelta entry_lock_wait = |
1210 TimeTicks::Now() - entry_lock_waiting_since_; | 1223 TimeTicks::Now() - entry_lock_waiting_since_; |
1211 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); | 1224 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); |
1212 | 1225 |
1213 entry_lock_waiting_since_ = TimeTicks(); | 1226 entry_lock_waiting_since_ = TimeTicks(); |
1214 DCHECK(new_entry_); | 1227 DCHECK(new_entry_); |
1215 cache_pending_ = false; | 1228 cache_pending_ = false; |
1216 | 1229 |
1217 if (result == OK) | 1230 if (result == OK) |
1218 entry_ = new_entry_; | 1231 entry_ = new_entry_; |
1219 | 1232 |
1220 // If there is a failure, the cache should have taken care of new_entry_. | 1233 // If there is a failure, the cache should have taken care of new_entry_. |
1221 new_entry_ = NULL; | 1234 new_entry_ = NULL; |
1222 | 1235 |
1223 if (result == ERR_CACHE_RACE) { | 1236 if (result == ERR_CACHE_RACE) { |
1224 next_state_ = STATE_INIT_ENTRY; | 1237 next_state_ = STATE_INIT_ENTRY; |
1225 return OK; | 1238 return OK; |
1226 } | 1239 } |
1227 | 1240 |
1241 if (result == ERR_CACHE_LOCK_TIMEOUT) { | |
1242 // The cache is busy, bypass it for this transaction. | |
1243 mode_ = NONE; | |
1244 next_state_ = STATE_SEND_REQUEST; | |
1245 if (partial_) { | |
1246 partial_->RestoreHeaders(&custom_request_->extra_headers); | |
1247 partial_.reset(); | |
1248 } | |
1249 return OK; | |
1250 } | |
1251 | |
1228 if (result != OK) { | 1252 if (result != OK) { |
1229 NOTREACHED(); | 1253 NOTREACHED(); |
1230 return result; | 1254 return result; |
1231 } | 1255 } |
1232 | 1256 |
1233 if (mode_ == WRITE) { | 1257 if (mode_ == WRITE) { |
1234 if (partial_.get()) | 1258 if (partial_.get()) |
1235 partial_->RestoreHeaders(&custom_request_->extra_headers); | 1259 partial_->RestoreHeaders(&custom_request_->extra_headers); |
1236 next_state_ = STATE_SEND_REQUEST; | 1260 next_state_ = STATE_SEND_REQUEST; |
1237 } else { | 1261 } else { |
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2343 entry_ = NULL; | 2367 entry_ = NULL; |
2344 is_sparse_ = false; | 2368 is_sparse_ = false; |
2345 partial_.reset(); | 2369 partial_.reset(); |
2346 next_state_ = STATE_GET_BACKEND; | 2370 next_state_ = STATE_GET_BACKEND; |
2347 return OK; | 2371 return OK; |
2348 } | 2372 } |
2349 | 2373 |
2350 return ERR_CACHE_READ_FAILURE; | 2374 return ERR_CACHE_READ_FAILURE; |
2351 } | 2375 } |
2352 | 2376 |
2377 void HttpCache::Transaction::OnAddToEntryTimeout(base::TimeTicks start_time) { | |
2378 if (entry_lock_waiting_since_ != start_time) | |
davidben
2014/06/20 19:28:35
I can't imagine it's possible for this to cause a
rvargas (doing something else)
2014/06/20 22:40:06
In theory we could just check that entry_lock_wait
davidben
2014/06/20 23:08:18
Hrm. DoAddToEntry -> DoAddToEntryComplete can trig
| |
2379 return; | |
2380 | |
davidben
2014/06/20 19:28:35
Nit: DCHECK_EQ(STATE_ADD_TO_ENTRY_COMPLETE, next_s
rvargas (doing something else)
2014/06/20 22:40:06
Done.
| |
2381 if (!cache_) | |
davidben
2014/06/20 19:28:35
Nit: NOTREACHED() here?
rvargas (doing something else)
2014/06/20 22:40:06
The cache may be gone leaving transactions behind.
davidben
2014/06/20 23:08:18
Oh, didn't notice this was a WeakPtr.
| |
2382 return; | |
2383 | |
2384 cache_->RemovePendingTransaction(this); | |
2385 OnIOComplete(ERR_CACHE_LOCK_TIMEOUT); | |
davidben
2014/06/20 19:28:35
Should we add an entry to the net log when this ha
rvargas (doing something else)
2014/06/20 22:40:06
DoAddToEntryComplete logs the result
| |
2386 } | |
2387 | |
2353 void HttpCache::Transaction::DoomPartialEntry(bool delete_object) { | 2388 void HttpCache::Transaction::DoomPartialEntry(bool delete_object) { |
2354 DVLOG(2) << "DoomPartialEntry"; | 2389 DVLOG(2) << "DoomPartialEntry"; |
2355 int rv = cache_->DoomEntry(cache_key_, NULL); | 2390 int rv = cache_->DoomEntry(cache_key_, NULL); |
2356 DCHECK_EQ(OK, rv); | 2391 DCHECK_EQ(OK, rv); |
2357 cache_->DoneWithEntry(entry_, this, false); | 2392 cache_->DoneWithEntry(entry_, this, false); |
2358 entry_ = NULL; | 2393 entry_ = NULL; |
2359 is_sparse_ = false; | 2394 is_sparse_ = false; |
2360 if (delete_object) | 2395 if (delete_object) |
2361 partial_.reset(NULL); | 2396 partial_.reset(NULL); |
2362 } | 2397 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2520 default: | 2555 default: |
2521 NOTREACHED(); | 2556 NOTREACHED(); |
2522 } | 2557 } |
2523 } | 2558 } |
2524 | 2559 |
2525 void HttpCache::Transaction::OnIOComplete(int result) { | 2560 void HttpCache::Transaction::OnIOComplete(int result) { |
2526 DoLoop(result); | 2561 DoLoop(result); |
2527 } | 2562 } |
2528 | 2563 |
2529 } // namespace net | 2564 } // namespace net |
OLD | NEW |