Chromium Code Reviews| Index: net/http/http_cache.h |
| diff --git a/net/http/http_cache.h b/net/http/http_cache.h |
| index 2aae2fcf27e1cc0aed6fcbbe3b73eb3c3d293708..04d256b5f9efdbc064a16be4ffbb351d80d9889b 100644 |
| --- a/net/http/http_cache.h |
| +++ b/net/http/http_cache.h |
| @@ -19,6 +19,8 @@ |
| #include <memory> |
| #include <string> |
| #include <unordered_map> |
| +#include <unordered_set> |
| +#include <utility> |
|
Randy Smith (Not in Mondays)
2017/01/19 00:53:42
What is this include for? I think of <utility> as
shivanisha
2017/01/19 21:13:06
Included this as per git cl lint. I agree it's not
Randy Smith (Not in Mondays)
2017/01/20 19:54:31
Weird. No, I don't think it's overriding an autom
shivanisha
2017/01/25 19:46:12
Removed the include.
|
| #include "base/files/file_path.h" |
| #include "base/macros.h" |
| @@ -202,7 +204,7 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, |
| // HttpTransactionFactory implementation: |
| int CreateTransaction(RequestPriority priority, |
| - std::unique_ptr<HttpTransaction>* trans) override; |
| + std::unique_ptr<HttpTransaction>* transaction) override; |
| HttpCache* GetCache() override; |
| HttpNetworkSession* GetSession() override; |
| @@ -229,15 +231,17 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, |
| kNumCacheEntryDataIndices |
| }; |
| + class DataAccess; |
| + class SharedWriters; |
| + class Transaction; |
| + typedef std::list<Transaction*> TransactionList; |
| + typedef std::unordered_set<Transaction*> TransactionSet; |
| class MetadataWriter; |
| class QuicServerInfoFactoryAdaptor; |
| - class Transaction; |
| class WorkItem; |
| - friend class Transaction; |
| friend class ViewCacheHelper; |
| struct PendingOp; // Info for an entry under construction. |
| - typedef std::list<Transaction*> TransactionList; |
| typedef std::list<std::unique_ptr<WorkItem>> WorkItemList; |
| struct ActiveEntry { |
| @@ -245,8 +249,10 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, |
| ~ActiveEntry(); |
| disk_cache::Entry* disk_entry; |
| + // Either writer or shared_writers will be non-null at any point in time. |
| Transaction* writer; |
| - TransactionList readers; |
| + std::unique_ptr<SharedWriters> shared_writers; |
| + TransactionSet readers; |
| TransactionList pending_queue; |
| bool will_process_pending_queue; |
| bool doomed; |
| @@ -302,7 +308,9 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, |
| // cache entry. |
| ActiveEntry* ActivateEntry(disk_cache::Entry* disk_entry); |
| - // Deletes an ActiveEntry. |
| + // Deletes an ActiveEntry. Expects all of the transaction pointers to be |
| + // null and containers to be empty: writer, shared_writers, pending_queue |
| + // and readers. |
| void DeactivateEntry(ActiveEntry* entry); |
| // Deletes an ActiveEntry using an exhaustive search. |
| @@ -392,6 +400,92 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, |
| // Processes the backend creation notification. |
| void OnBackendCreated(int result, PendingOp* pending_op); |
| + // Destroys the entry and any pending queue transactions' callbacks are |
| + // invoked with ERR_CACHE_RACE that restarts their state machine. |
| + void DestroyEntryAndRestartPendingQueueTransactions(ActiveEntry* entry); |
| + |
| + // Writes response info to entry. |
| + int WriteResponseInfo(ActiveEntry* entry, |
| + const HttpResponseInfo* response, |
| + CompletionCallback& callback, |
| + bool truncated, |
| + int* io_buf_len); |
| + |
| + // Checks if the response is completed based on content length. |
| + bool IsResponseCompleted(const ActiveEntry* entry, |
| + const HttpResponseInfo* response); |
| + |
| + // Returns true if we should bother attempting to resume this request if it is |
| + // aborted while in progress. If |has_data| is true, the size of the stored |
| + // data is considered for the result. |
| + bool CanResumeEntry(bool has_data, |
| + const std::string& method, |
| + const HttpResponseInfo* response, |
| + ActiveEntry* entry); |
| + |
| + // Creates a SharedWriters object. The ownership of the network_transaction is |
| + // transferred to a new DataAccess object owned by the SharedWriters object. |
| + void CreateSharedWriters(Transaction* cacheTransaction, |
| + std::unique_ptr<HttpTransaction> network_transaction, |
| + RequestPriority priority); |
| + |
| + // Shared Writing scenarios requiring processing of transactions in the entry |
| + // or removal of entry. |
| + // |
| + // These are invoked from SharedWriters IO callback and will lead to shared |
| + // writers' ownership being released from entry which will be deleted at the |
| + // end of the callback processing by the SharedWriters object itself. |
| + // |
|
Randy Smith (Not in Mondays)
2017/01/19 00:53:42
To me, it would make it more clear that these comm
shivanisha
2017/01/25 19:46:12
N/A due to recent changes.
|
| + // Response data completely written to the cache successfully. |
| + void ResponseCompleteSharedWriters(ActiveEntry* entry); |
| + |
| + // Response data could not be written to the cache successfully, or |
| + // Response data could not be read from the network successfully. |
| + // Success is true if the entry was marked as truncated successfully. |
| + void ResponseFailedSharedWriters(bool success, ActiveEntry* entry); |
| + |
| + // Resets or releases if entry contains an empty SharedWriters object and |
| + // calls ProcessPendingQueue. It will release if SharedWriters is about to |
| + // delete itself at the end of the flow, else resets. |
| + void ResetSharedWritersProcessPendingQueue(ActiveEntry* entry); |
| + |
| + // These are invoked from HttpCache::Transaction and might lead to shared |
| + // writers being destroyed. |
| + // |
| + // DoneReading() API invoked on the transaction. |
| + void DoneReadingSharedWriters(Transaction* transaction, ActiveEntry* entry); |
| + |
| + // StopCaching() API invoked on the transaction. |
| + void StopCachingSharedWriters(Transaction* transaction, ActiveEntry* entry); |
| + |
| + // Validating transaction receives a non-304 response. |
| + std::unique_ptr<HttpTransaction> ValidationNoMatchSharedWriters( |
| + const std::string& key, |
| + Transaction* transaction, |
| + std::unique_ptr<HttpTransaction> network_transaction, |
| + RequestPriority priority, |
| + ActiveEntry* entry); |
| + |
| + // Current Writer is destroyed by its consumer. |
| + void RemoveCurrentSharedWriter(Transaction* transaction, ActiveEntry* entry); |
| + |
| + // An idle writer is destroyed by its consumer. |
| + void RemoveIdleSharedWriter(Transaction* transaction, ActiveEntry* entry); |
| + |
| + // Validating transaction is destroyed by its consumer. |
| + void RemoveValidatingTransSharedWriters(Transaction* transaction, |
| + ActiveEntry* entry); |
| + |
| + // Invokes the io callback of the transaction with the result, if the |
| + // transaction is still alive. |
| + void NotifyTransaction(base::WeakPtr<Transaction> transaction, int result); |
| + |
| + // Reset SharedWriters except in the scenario given here: SharedWriters may |
| + // be in a flow where it is meant to destroy itself at the end of the flow |
| + // and we are here as a result of a callback. Do not reset in that case and |
| + // just release the ownership of SharedWriters. |
| + void ResetOrReleaseSharedWriters(ActiveEntry* entry); |
| + |
| // Variables ---------------------------------------------------------------- |
| NetLog* net_log_; |