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

Unified 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: Add missing MockTransaction initializers Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_cache_transaction.h
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h
index 30f3ec408d59dd3297e2bd7b4013980f633074e3..a9edd1b534dedf7db594a56f65422b901f068274 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -212,15 +212,14 @@ class HttpCache::Transaction : public HttpTransaction {
STATE_CACHE_READ_METADATA,
STATE_CACHE_READ_METADATA_COMPLETE,
- // These states are entered from Read/AddTruncatedFlag.
+ // These states are entered from Read.
+ STATE_SWITCH_TO_NETWORK,
STATE_NETWORK_READ,
STATE_NETWORK_READ_COMPLETE,
STATE_CACHE_READ_DATA,
STATE_CACHE_READ_DATA_COMPLETE,
STATE_CACHE_WRITE_DATA,
STATE_CACHE_WRITE_DATA_COMPLETE,
- STATE_CACHE_WRITE_TRUNCATED_RESPONSE,
- STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE
};
// Used for categorizing transactions for reporting in histograms. Patterns
@@ -284,14 +283,13 @@ class HttpCache::Transaction : public HttpTransaction {
int DoPartialHeadersReceived();
int DoCacheReadMetadata();
int DoCacheReadMetadataComplete(int result);
+ int DoSwitchToNetwork();
int DoNetworkRead();
int DoNetworkReadComplete(int result);
int DoCacheReadData();
int DoCacheReadDataComplete(int result);
int DoCacheWriteData(int num_bytes);
int DoCacheWriteDataComplete(int result);
- int DoCacheWriteTruncatedResponse();
- int DoCacheWriteTruncatedResponseComplete(int result);
// These functions are involved in a field trial testing storing certificates
// in seperate entries from the HttpResponseInfo.
@@ -366,17 +364,25 @@ class HttpCache::Transaction : public HttpTransaction {
const CompletionCallback& callback);
// Called to write response_ to the cache entry. |truncated| indicates if the
- // entry should be marked as incomplete.
- int WriteResponseInfoToEntry(bool truncated);
+ // entry should be marked as incomplete. Returns ERR_IO_PENDING if an
+ // operation is pending. Once |callback| is invoked, the caller should call
+ // OnWriteResponseInfoToEntryComplete() with the result to complete the
+ // write operation.
+ int WriteResponseInfoToEntry(bool truncated,
+ const CompletionCallback& callback);
// Helper function, should be called with result of WriteResponseInfoToEntry
// (or the result of the callback, when WriteResponseInfoToEntry returns
- // ERR_IO_PENDING). Calls DoneWritingToEntry if |result| is not the right
- // number of bytes. It is expected that the state that calls this will
- // return whatever net error code this function returns, which currently
- // is always "OK".
+ // ERR_IO_PENDING). Calls ReleaseCacheEntry() to doom the entry if the number
+ // of bytes written is less than expected. It is expected that the state that
+ // calls this will return whatever net error code this function returns, which
+ // currently is always "OK".
int OnWriteResponseInfoToEntryComplete(int result);
+ // Releases the cache entry. The |entry_state| parameter specifies the state
+ // of the entry following the release.
+ void ReleaseCacheEntry(EntryState entry_state);
+
// Called when we are done writing to the cache entry.
void DoneWritingToEntry(bool success);
@@ -405,6 +411,8 @@ class HttpCache::Transaction : public HttpTransaction {
// between the byte range request and the cached entry.
int DoRestartPartialRequest();
+ void OnCacheReleaseComplete(const base::Closure& closure, int result);
+
// Resets the relavant internal state to remove traces of internal processing
// related to range requests. Deletes |partial_| if |delete_object| is true.
void ResetPartialState(bool delete_object);
@@ -424,6 +432,25 @@ class HttpCache::Transaction : public HttpTransaction {
// Called to signal completion of asynchronous IO.
void OnIOComplete(int result);
+ // Abandons a cache entry.
+ //
+ // This should be called when the transaction abnormally terminates writing to
+ // a cache entry. Once called, the cache entry could be either retained or
+ // truncated or destroyed depending on whether the full response entity was
+ // written to the cache or whether the partial cache entry can be fulfiled
+ // later by resuming the network request.
+ //
+ // If any asynchronous operations are pending, returns ERR_IO_PENDING and
+ // invokes |callback| when the opearations are complete. entry_ is always
+ // released upon completion.
+ //
+ // If |callback| is empty, then releases the cache entry synchronously. It is
+ // possible for the cache entry to be in an indeterminate state in this case.
+ int AbandonCacheEntry(const CompletionCallback& callback);
+
+ // Called to signal IO completion for AbandonCacheEntry().
+ void OnAbandonCacheEntryIOComplete(int result);
+
State next_state_;
const HttpRequestInfo* request_;
RequestPriority priority_;
@@ -444,18 +471,20 @@ class HttpCache::Transaction : public HttpTransaction {
std::string cache_key_;
Mode mode_;
bool reading_; // We are already reading. Never reverts to false once set.
- bool invalid_range_; // We may bypass the cache for this request.
- bool truncated_; // We don't have all the response data.
- bool is_sparse_; // The data is stored in sparse byte ranges.
+ bool invalid_range_; // We may bypass the cache for this request.
+ bool truncated_; // We don't have all the response data.
+ bool is_sparse_; // The data is stored in sparse byte ranges.
bool range_requested_; // The user requested a byte range.
- bool handling_206_; // We must deal with this 206 response.
- bool cache_pending_; // We are waiting for the HttpCache.
- bool done_reading_; // All available data was read.
- bool vary_mismatch_; // The request doesn't match the stored vary data.
+ bool handling_206_; // We must deal with this 206 response.
+ bool cache_pending_; // We are waiting for the HttpCache.
+ bool done_reading_; // All available data was written to the cache entry.
+ bool vary_mismatch_; // The request doesn't match the stored vary data.
bool couldnt_conditionalize_request_;
+ bool stopped_caching_; // Avoid further writes to the cache.
bool bypass_lock_for_test_; // A test is exercising the cache lock.
bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest.
scoped_refptr<IOBuffer> read_buf_;
+ int read_buf_len_;
int io_buf_len_;
int read_offset_;
int effective_load_flags_;
@@ -464,6 +493,9 @@ class HttpCache::Transaction : public HttpTransaction {
UploadProgress final_upload_progress_;
CompletionCallback io_callback_;
+ // Completion callback for AbandonCacheEntry().
+ CompletionCallback abandon_cache_entry_callback_;
+
// Members used to track data for histograms.
TransactionPattern transaction_pattern_;
base::TimeTicks entry_lock_waiting_since_;

Powered by Google App Engine
This is Rietveld 408576698