Index: net/http/http_cache_transaction.h |
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h |
index 51c0db70256cbd31505ca20ffba6486ab4c36aad..853c456ee686e23d1f0e38f6d322d20dc94ffdc4 100644 |
--- a/net/http/http_cache_transaction.h |
+++ b/net/http/http_cache_transaction.h |
@@ -80,6 +80,8 @@ class HttpCache::Transaction : public HttpTransaction { |
Mode mode() const { return mode_; } |
+ std::string& method() { return method_; } |
+ |
const std::string& key() const { return cache_key_; } |
// Writes |buf_len| bytes of meta-data from the provided buffer |buf|. to the |
@@ -104,8 +106,10 @@ class HttpCache::Transaction : public HttpTransaction { |
// This transaction is being deleted and we are not done writing to the cache. |
// We need to indicate that the response data was truncated. Returns true on |
// success. Keep in mind that this operation may have side effects, such as |
- // deleting the active entry. |
- bool AddTruncatedFlag(); |
+ // deleting the active entry. This also returns success if the response was |
+ // completely written, |*is_truncated| will be set if it was actually |
jkarlin
2017/06/08 16:14:10
It'd be cleaner if is_truncated were assigned a va
shivanisha
2017/06/08 18:26:02
Done
|
+ // truncated. |
+ bool AddTruncatedFlag(bool* is_truncated); |
jkarlin
2017/06/08 16:14:09
optional nit: rename is_truncated to did_truncate
shivanisha
2017/06/08 18:26:02
done
|
HttpCache::ActiveEntry* entry() { return entry_; } |
@@ -164,6 +168,10 @@ class HttpCache::Transaction : public HttpTransaction { |
int ResumeNetworkStart() override; |
void GetConnectionAttempts(ConnectionAttempts* out) const override; |
+ // Invoked when parallel validation cannot proceed due to response failure |
+ // and this transaction needs to be restarted. |
+ void SetValidatingCannotProceed(); |
+ |
// Returns the estimate of dynamically allocated memory in bytes. |
size_t EstimateMemoryUsage() const; |
@@ -178,6 +186,14 @@ class HttpCache::Transaction : public HttpTransaction { |
bool initialized; |
}; |
+ // A snapshot of pieces of the transaction before entering the state machine |
+ // so that the state can be restored when restarting the state machine. |
+ struct RestartInfo { |
+ Mode mode = NONE; |
+ HttpResponseInfo::CacheEntryStatus cache_entry_status = |
+ HttpResponseInfo::CacheEntryStatus::ENTRY_UNDEFINED; |
+ }; |
+ |
enum State { |
STATE_UNSET, |
@@ -220,6 +236,9 @@ class HttpCache::Transaction : public HttpTransaction { |
STATE_PARTIAL_HEADERS_RECEIVED, |
STATE_CACHE_READ_METADATA, |
STATE_CACHE_READ_METADATA_COMPLETE, |
+ STATE_HEADERS_PHASE_CANNOT_PROCEED, |
+ STATE_FINISH_HEADERS, |
+ STATE_FINISH_HEADERS_COMPLETE, |
// These states are entered from Read/AddTruncatedFlag. |
STATE_NETWORK_READ, |
@@ -288,6 +307,9 @@ class HttpCache::Transaction : public HttpTransaction { |
int DoPartialHeadersReceived(); |
int DoCacheReadMetadata(); |
int DoCacheReadMetadataComplete(int result); |
+ int DoHeadersPhaseCannotProceed(); |
+ int DoFinishHeaders(int result); |
+ int DoFinishHeadersComplete(int result); |
int DoNetworkRead(); |
int DoNetworkReadComplete(int result); |
int DoCacheReadData(); |
@@ -430,7 +452,12 @@ class HttpCache::Transaction : public HttpTransaction { |
void SyncCacheEntryStatusToResponse(); |
void RecordHistograms(); |
- // Called to signal completion of asynchronous IO. |
+ // Called to signal completion of asynchronous IO. Note that this callback is |
+ // used in the conventional sense where one layer calls the callback of the |
+ // layer above it e.g. this callback gets called from the network transaction |
+ // layer. In addition, it is also used for HttpCache layer to let this |
+ // transaction know when it is out of a queued state in ActiveEntry and can |
+ // continue its processing. |
void OnIOComplete(int result); |
// When in a DoLoop, use this to set the next state as it verifies that the |
@@ -439,6 +466,7 @@ class HttpCache::Transaction : public HttpTransaction { |
State next_state_; |
const HttpRequestInfo* request_; |
+ std::string method_; |
RequestPriority priority_; |
NetLogWithSource net_log_; |
std::unique_ptr<HttpRequestInfo> custom_request_; |
@@ -514,6 +542,12 @@ class HttpCache::Transaction : public HttpTransaction { |
// True if the Transaction is currently processing the DoLoop. |
bool in_do_loop_; |
+ // Used to restore some members when the state machine is restarted after it |
+ // has already been added to an entry e.g after |this| has completed |
+ // validation and the writer transaction fails to completely write the |
+ // response to the cache. |
+ RestartInfo restart_info_; |
+ |
base::WeakPtrFactory<Transaction> weak_factory_; |
DISALLOW_COPY_AND_ASSIGN(Transaction); |