Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Side by Side Diff: net/http/http_cache_transaction.h

Issue 1230113012: [net] Better StopCaching() handling for HttpCache::Transaction. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // This file declares HttpCache::Transaction, a private class of HttpCache so 5 // This file declares HttpCache::Transaction, a private class of HttpCache so
6 // it should only be included by http_cache.cc 6 // it should only be included by http_cache.cc
7 7
8 #ifndef NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 8 #ifndef NET_HTTP_HTTP_CACHE_TRANSACTION_H_
9 #define NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 9 #define NET_HTTP_HTTP_CACHE_TRANSACTION_H_
10 10
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 STATE_CACHE_WRITE_RESPONSE, 203 STATE_CACHE_WRITE_RESPONSE,
204 STATE_CACHE_WRITE_RESPONSE_COMPLETE, 204 STATE_CACHE_WRITE_RESPONSE_COMPLETE,
205 STATE_TRUNCATE_CACHED_DATA, 205 STATE_TRUNCATE_CACHED_DATA,
206 STATE_TRUNCATE_CACHED_DATA_COMPLETE, 206 STATE_TRUNCATE_CACHED_DATA_COMPLETE,
207 STATE_TRUNCATE_CACHED_METADATA, 207 STATE_TRUNCATE_CACHED_METADATA,
208 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, 208 STATE_TRUNCATE_CACHED_METADATA_COMPLETE,
209 STATE_PARTIAL_HEADERS_RECEIVED, 209 STATE_PARTIAL_HEADERS_RECEIVED,
210 STATE_CACHE_READ_METADATA, 210 STATE_CACHE_READ_METADATA,
211 STATE_CACHE_READ_METADATA_COMPLETE, 211 STATE_CACHE_READ_METADATA_COMPLETE,
212 212
213 // These states are entered from Read/AddTruncatedFlag. 213 // These states are entered from Read
rvargas (doing something else) 2015/08/19 23:46:39 nit: period at the end.
asanka 2015/09/04 19:09:04 Done.
214 STATE_RELEASE_CACHE_ENTRY_AND_CONTINUE_USING_NETWORK,
214 STATE_NETWORK_READ, 215 STATE_NETWORK_READ,
215 STATE_NETWORK_READ_COMPLETE, 216 STATE_NETWORK_READ_COMPLETE,
216 STATE_CACHE_READ_DATA, 217 STATE_CACHE_READ_DATA,
217 STATE_CACHE_READ_DATA_COMPLETE, 218 STATE_CACHE_READ_DATA_COMPLETE,
218 STATE_CACHE_WRITE_DATA, 219 STATE_CACHE_WRITE_DATA,
219 STATE_CACHE_WRITE_DATA_COMPLETE, 220 STATE_CACHE_WRITE_DATA_COMPLETE,
221
220 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, 222 STATE_CACHE_WRITE_TRUNCATED_RESPONSE,
221 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE 223 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE,
222 }; 224 };
223 225
224 // Used for categorizing transactions for reporting in histograms. Patterns 226 // Used for categorizing transactions for reporting in histograms. Patterns
225 // cover relatively common use cases being measured and considered for 227 // cover relatively common use cases being measured and considered for
226 // optimization. Many use cases that are more complex or uncommon are binned 228 // optimization. Many use cases that are more complex or uncommon are binned
227 // as PATTERN_NOT_COVERED, and details are not reported. 229 // as PATTERN_NOT_COVERED, and details are not reported.
228 // NOTE: This enumeration is used in histograms, so please do not add entries 230 // NOTE: This enumeration is used in histograms, so please do not add entries
229 // in the middle. 231 // in the middle.
230 enum TransactionPattern { 232 enum TransactionPattern {
231 PATTERN_UNDEFINED, 233 PATTERN_UNDEFINED,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 int DoCacheReadMetadata(); 285 int DoCacheReadMetadata();
284 int DoCacheReadMetadataComplete(int result); 286 int DoCacheReadMetadataComplete(int result);
285 int DoNetworkRead(); 287 int DoNetworkRead();
286 int DoNetworkReadComplete(int result); 288 int DoNetworkReadComplete(int result);
287 int DoCacheReadData(); 289 int DoCacheReadData();
288 int DoCacheReadDataComplete(int result); 290 int DoCacheReadDataComplete(int result);
289 int DoCacheWriteData(int num_bytes); 291 int DoCacheWriteData(int num_bytes);
290 int DoCacheWriteDataComplete(int result); 292 int DoCacheWriteDataComplete(int result);
291 int DoCacheWriteTruncatedResponse(); 293 int DoCacheWriteTruncatedResponse();
292 int DoCacheWriteTruncatedResponseComplete(int result); 294 int DoCacheWriteTruncatedResponseComplete(int result);
295 int DoReleaseCacheEntryAndContinueUsingNetwork();
rvargas (doing something else) 2015/08/19 23:46:39 nit: keep the same order of the enum.
asanka 2015/09/04 19:09:04 Done.
293 296
294 // These functions are involved in a field trial testing storing certificates 297 // These functions are involved in a field trial testing storing certificates
295 // in seperate entries from the HttpResponseInfo. 298 // in seperate entries from the HttpResponseInfo.
296 void ReadCertChain(); 299 void ReadCertChain();
297 void WriteCertChain(); 300 void WriteCertChain();
298 301
299 // Sets request_ and fields derived from it. 302 // Sets request_ and fields derived from it.
300 void SetRequest(const BoundNetLog& net_log, const HttpRequestInfo* request); 303 void SetRequest(const BoundNetLog& net_log, const HttpRequestInfo* request);
301 304
302 // Returns true if the request should be handled exclusively by the network 305 // Returns true if the request should be handled exclusively by the network
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 int WriteResponseInfoToEntry(bool truncated); 371 int WriteResponseInfoToEntry(bool truncated);
369 372
370 // Helper function, should be called with result of WriteResponseInfoToEntry 373 // Helper function, should be called with result of WriteResponseInfoToEntry
371 // (or the result of the callback, when WriteResponseInfoToEntry returns 374 // (or the result of the callback, when WriteResponseInfoToEntry returns
372 // ERR_IO_PENDING). Calls DoneWritingToEntry if |result| is not the right 375 // ERR_IO_PENDING). Calls DoneWritingToEntry if |result| is not the right
373 // number of bytes. It is expected that the state that calls this will 376 // number of bytes. It is expected that the state that calls this will
374 // return whatever net error code this function returns, which currently 377 // return whatever net error code this function returns, which currently
375 // is always "OK". 378 // is always "OK".
376 int OnWriteResponseInfoToEntryComplete(int result); 379 int OnWriteResponseInfoToEntryComplete(int result);
377 380
381 // Requested state of the cache entry after a call to
382 // ReleaseCacheEntry().
383 enum CacheEntryDisposition {
384 // Preserve the cache entry if it already existed prior to this cache
385 // transaction.
386 CACHE_ENTRY_PRESERVE_PREEXISTING,
387
388 // Try to preserve the existing cache entry. It will be marked as truncated
389 // if necessary.
390 CACHE_ENTRY_PRESERVE,
391
392 // Doom the cache entry.
393 CACHE_ENTRY_DOOM
394 };
395
396 // Called when the client has finished with the cache entry. May start the
397 // state machine again. Hence should only be called when there are no more
398 // pending operations.
399 //
400 // If |entry_disposition| is CACHE_ENTRY_PRESERVE_PREEXISTING:
401 // If the cache entry is sparse or was not created by this transaction, then
402 // acts as if |entry_disposition| was CACHE_ENTRY_PRESERVE. Otherwise acts
403 // as if it was CACHE_ENTRY_DOOM.
404 //
405 // If |entry_disposition| is CACHE_ENTRY_PRESERVE:
406 // If the cache entry was written completely or if the entry is resumable or
407 // sparse, then preserves the cache entry. If a non-sparse entry wasn't
408 // written completely, it will be marked as truncated.
409 //
410 // If |entry_disposition| is CACHE_ENTRY_DOOM:
411 // Marks the cache entry as doomed.
rvargas (doing something else) 2015/08/19 23:46:39 nit: Dooms the entry (there's no really a doom mar
asanka 2015/09/04 19:09:04 Done.
412 //
413 // In all cases other than the case where the entry needs to be marked as
414 // truncated, this call will completely synchronously.
415 int ReleaseCacheEntry(CacheEntryDisposition entry_disposition);
416
378 // Called when we are done writing to the cache entry. 417 // Called when we are done writing to the cache entry.
379 void DoneWritingToEntry(bool success); 418 void DoneWritingToEntry(bool success);
380 419
381 // Returns an error to signal the caller that the current read failed. The 420 // Returns an error to signal the caller that the current read failed. The
382 // current operation |result| is also logged. If |restart| is true, the 421 // current operation |result| is also logged. If |restart| is true, the
383 // transaction should be restarted. 422 // transaction should be restarted.
384 int OnCacheReadError(int result, bool restart); 423 int OnCacheReadError(int result, bool restart);
385 424
386 // Called when the cache lock timeout fires. 425 // Called when the cache lock timeout fires.
387 void OnAddToEntryTimeout(base::TimeTicks start_time); 426 void OnAddToEntryTimeout(base::TimeTicks start_time);
388 427
389 // Deletes the current partial cache entry (sparse), and optionally removes 428 // Deletes the current partial cache entry (sparse), and optionally removes
390 // the control object (partial_). 429 // the control object (partial_).
391 void DoomPartialEntry(bool delete_object); 430 void DoomPartialEntry(bool delete_object);
392 431
393 // Performs the needed work after receiving data from the network, when 432 // Performs the needed work after receiving data from the network, when
394 // working with range requests. 433 // working with range requests.
395 int DoPartialNetworkReadCompleted(int result); 434 int DoPartialNetworkReadCompleted(int result);
396 435
397 // Performs the needed work after receiving data from the cache, when 436 // Performs the needed work after receiving data from the cache, when
398 // working with range requests. 437 // working with range requests.
399 int DoPartialCacheReadCompleted(int result); 438 int DoPartialCacheReadCompleted(int result);
400 439
401 // Restarts this transaction after deleting the cached data. It is meant to 440 // Restarts this transaction after deleting the cached data. It is meant to
402 // be used when the current request cannot be fulfilled due to conflicts 441 // be used when the current request cannot be fulfilled due to conflicts
403 // between the byte range request and the cached entry. 442 // between the byte range request and the cached entry.
404 int DoRestartPartialRequest(); 443 int DoRestartPartialRequest();
405 444
445 void OnCacheReleaseComplete(const base::Closure& closure, int result);
446
406 // Resets the relavant internal state to remove traces of internal processing 447 // Resets the relavant internal state to remove traces of internal processing
407 // related to range requests. Deletes |partial_| if |delete_object| is true. 448 // related to range requests. Deletes |partial_| if |delete_object| is true.
408 void ResetPartialState(bool delete_object); 449 void ResetPartialState(bool delete_object);
409 450
410 // Resets |network_trans_|, which must be non-NULL. Also updates 451 // Resets |network_trans_|, which must be non-NULL. Also updates
411 // |old_network_trans_load_timing_|, which must be NULL when this is called. 452 // |old_network_trans_load_timing_|, which must be NULL when this is called.
412 void ResetNetworkTransaction(); 453 void ResetNetworkTransaction();
413 454
414 // Returns true if we should bother attempting to resume this request if it 455 // Returns true if we should bother attempting to resume this request if it
415 // is aborted while in progress. If |has_data| is true, the size of the stored 456 // is aborted while in progress. If |has_data| is true, the size of the stored
(...skipping 19 matching lines...) Expand all
435 HttpCache::ActiveEntry* entry_; 476 HttpCache::ActiveEntry* entry_;
436 HttpCache::ActiveEntry* new_entry_; 477 HttpCache::ActiveEntry* new_entry_;
437 scoped_ptr<HttpTransaction> network_trans_; 478 scoped_ptr<HttpTransaction> network_trans_;
438 CompletionCallback callback_; // Consumer's callback. 479 CompletionCallback callback_; // Consumer's callback.
439 HttpResponseInfo response_; 480 HttpResponseInfo response_;
440 HttpResponseInfo auth_response_; 481 HttpResponseInfo auth_response_;
441 const HttpResponseInfo* new_response_; 482 const HttpResponseInfo* new_response_;
442 std::string cache_key_; 483 std::string cache_key_;
443 Mode mode_; 484 Mode mode_;
444 bool reading_; // We are already reading. Never reverts to false once set. 485 bool reading_; // We are already reading. Never reverts to false once set.
445 bool invalid_range_; // We may bypass the cache for this request. 486 bool invalid_range_; // We may bypass the cache for this request.
446 bool truncated_; // We don't have all the response data. 487 bool truncated_; // We don't have all the response data.
447 bool is_sparse_; // The data is stored in sparse byte ranges. 488 bool is_sparse_; // The data is stored in sparse byte ranges.
448 bool range_requested_; // The user requested a byte range. 489 bool range_requested_; // The user requested a byte range.
449 bool handling_206_; // We must deal with this 206 response. 490 bool handling_206_; // We must deal with this 206 response.
450 bool cache_pending_; // We are waiting for the HttpCache. 491 bool cache_pending_; // We are waiting for the HttpCache.
451 bool done_reading_; // All available data was read. 492 bool done_reading_; // All available data was written to the cache entry.
452 bool vary_mismatch_; // The request doesn't match the stored vary data. 493 bool vary_mismatch_; // The request doesn't match the stored vary data.
453 bool couldnt_conditionalize_request_; 494 bool couldnt_conditionalize_request_;
495 bool stopped_caching_; // Avoid further writes to the cache.
454 bool bypass_lock_for_test_; // A test is exercising the cache lock. 496 bool bypass_lock_for_test_; // A test is exercising the cache lock.
455 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. 497 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest.
456 scoped_refptr<IOBuffer> read_buf_; 498 scoped_refptr<IOBuffer> read_buf_;
457 int io_buf_len_; 499 int io_buf_len_;
458 int read_offset_; 500 int read_offset_;
459 int effective_load_flags_; 501 int effective_load_flags_;
460 int write_len_; 502 int write_len_;
461 scoped_ptr<PartialData> partial_; // We are dealing with range requests. 503 scoped_ptr<PartialData> partial_; // We are dealing with range requests.
462 UploadProgress final_upload_progress_; 504 UploadProgress final_upload_progress_;
463 CompletionCallback io_callback_; 505 CompletionCallback io_callback_;
(...skipping 24 matching lines...) Expand all
488 BeforeProxyHeadersSentCallback before_proxy_headers_sent_callback_; 530 BeforeProxyHeadersSentCallback before_proxy_headers_sent_callback_;
489 531
490 base::WeakPtrFactory<Transaction> weak_factory_; 532 base::WeakPtrFactory<Transaction> weak_factory_;
491 533
492 DISALLOW_COPY_AND_ASSIGN(Transaction); 534 DISALLOW_COPY_AND_ASSIGN(Transaction);
493 }; 535 };
494 536
495 } // namespace net 537 } // namespace net
496 538
497 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 539 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698