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

Unified Diff: net/http/http_cache_transaction.h

Issue 2519473002: Fixes the cache lock issue. (Closed)
Patch Set: Initial patch Created 4 years 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 32bb23571f48a0a868288b492a1f55dacf48f9cd..e46615d2fa2ea39eeb9d7a5f09b92614b54d7be0 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -107,7 +107,7 @@ class HttpCache::Transaction : public HttpTransaction {
// deleting the active entry.
bool AddTruncatedFlag();
- HttpCache::ActiveEntry* entry() { return entry_; }
+ HttpCache::ActiveEntry* entry() const { return entry_; }
// Returns the LoadState of the writer transaction of a given ActiveEntry. In
// other words, returns the LoadState of this transaction without asking the
@@ -140,6 +140,7 @@ class HttpCache::Transaction : public HttpTransaction {
int RestartWithAuth(const AuthCredentials& credentials,
const CompletionCallback& callback) override;
bool IsReadyToRestartForAuth() override;
+ void Orphan(std::unique_ptr<HttpTransaction> trans) override;
int Read(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
@@ -163,6 +164,26 @@ class HttpCache::Transaction : public HttpTransaction {
const BeforeHeadersSentCallback& callback) override;
int ResumeNetworkStart() override;
void GetConnectionAttempts(ConnectionAttempts* out) const override;
+ // Returns true if the transaction is eligible for reading from the
+ // network and writing to the cache along with other transactions.
+ // It is eligible if any of the following conditions are true:
+ // - Request’s mode is READ_WRITE. If mode is only READ then this
+ // transaction should wait till the whole response is in the cache.
jkarlin 2016/12/06 18:08:18 s/till/until/
shivanisha 2016/12/06 21:53:35 done.
+ // - Method is GET.
+ // - It is not a range request.
+ // - todo: Is this required: It is not a no-store data or data that must not
jkarlin 2016/12/06 18:08:18 s/todo:/TODO(shivanisha):/
shivanisha 2016/12/06 21:53:35 todo comment not needed, removed.
+ // be stored in the cache
+ // due to any other reason.
+ bool IsEligibleForSharedWriting() const;
+ void ProcessForSharedWriting();
+ void SetShared();
+ void ResetShared(bool continue_network_reading = false,
+ bool continue_cache_reading = false);
+ bool shared() const;
+ bool validating_shared() const;
+ void SetSharedWritingFailState();
+ void ContinueWithoutSharedWriting();
+ void SetFinalizeDoomed();
private:
static const size_t kNumValidationHeaders = 2;
@@ -215,16 +236,27 @@ class HttpCache::Transaction : public HttpTransaction {
STATE_PARTIAL_HEADERS_RECEIVED,
STATE_CACHE_READ_METADATA,
STATE_CACHE_READ_METADATA_COMPLETE,
+ // Update the value if another state becomes the last states of the start
+ // state machine.
+ STATE_START_STATE_MACHINE_FINAL = STATE_CACHE_READ_METADATA_COMPLETE,
+ // Start states should always be before Read states.
// These states are entered from Read/AddTruncatedFlag.
STATE_NETWORK_READ,
STATE_NETWORK_READ_COMPLETE,
+ STATE_SHARED_NETWORK_READ,
+ STATE_SHARED_NETWORK_READ_COMPLETE,
+ STATE_SHARED_NETWORK_READ_WAIT_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
+ STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE,
+
+ // This state is reached when this transaction is idle waiting for Read to
+ // be invoked and Shared Writing failed.
+ STATE_SHARED_READ_WRITE_FAILED
};
// Used for categorizing validation triggers in histograms.
@@ -285,6 +317,9 @@ class HttpCache::Transaction : public HttpTransaction {
int DoCacheReadMetadataComplete(int result);
int DoNetworkRead();
int DoNetworkReadComplete(int result);
+ int DoSharedNetworkRead();
+ int DoSharedNetworkReadComplete(int result);
+ int DoSharedNetworkReadWaitComplete(int result);
int DoCacheReadData();
int DoCacheReadDataComplete(int result);
int DoCacheWriteData(int num_bytes);
@@ -374,7 +409,10 @@ class HttpCache::Transaction : public HttpTransaction {
int OnWriteResponseInfoToEntryComplete(int result);
// Called when we are done writing to the cache entry.
- void DoneWritingToEntry(bool success);
+ // In some case we just want to set the internal state of the transaction but
+ // do not want to invoke any cleanup operation on entry_ e.g. when it's
+ // already done by a SharedWriter callback function.
+ void DoneWritingToEntry(bool success, bool perform_entry_cleanup = true);
// Returns an error to signal the caller that the current read failed. The
// current operation |result| is also logged. If |restart| is true, the
@@ -409,6 +447,9 @@ class HttpCache::Transaction : public HttpTransaction {
// |old_network_trans_load_timing_|, which must be NULL when this is called.
void ResetNetworkTransaction();
+ void SaveNetworkTransInfo();
jkarlin 2016/12/06 18:08:18 s/Trans/Transaction/
shivanisha 2016/12/06 21:53:35 done
+ void SaveSharedNetworkTransInfo();
jkarlin 2016/12/06 18:08:18 ditto
shivanisha 2016/12/06 21:53:35 done
+
// 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.
@@ -429,6 +470,9 @@ class HttpCache::Transaction : public HttpTransaction {
// Called to signal completion of asynchronous IO.
void OnIOComplete(int result);
+ // Called when the transaction needs to be deleted after being orphaned.
+ void Delete();
+
State next_state_;
const HttpRequestInfo* request_;
RequestPriority priority_;
@@ -460,6 +504,10 @@ class HttpCache::Transaction : public HttpTransaction {
bool couldnt_conditionalize_request_;
bool bypass_lock_for_test_; // A test is exercising the cache lock.
bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest.
+ // Reads from the network using a SharedWriters object.
jkarlin 2016/12/06 18:08:18 empty line above comment missing.
shivanisha 2016/12/06 21:53:35 Added. Also added comments for finalize_doomed_ an
+ bool shared_;
+ bool finalize_doomed_;
+ bool orphaned_;
scoped_refptr<IOBuffer> read_buf_;
int io_buf_len_;
int read_offset_;
@@ -503,6 +551,9 @@ class HttpCache::Transaction : public HttpTransaction {
BeforeNetworkStartCallback before_network_start_callback_;
BeforeHeadersSentCallback before_headers_sent_callback_;
+ bool have_full_request_headers_;
+ HttpRequestHeaders full_request_headers_;
+
base::WeakPtrFactory<Transaction> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(Transaction);

Powered by Google App Engine
This is Rietveld 408576698