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

Side by Side 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 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 int WriteMetadata(IOBuffer* buf, 100 int WriteMetadata(IOBuffer* buf,
101 int buf_len, 101 int buf_len,
102 const CompletionCallback& callback); 102 const CompletionCallback& callback);
103 103
104 // This transaction is being deleted and we are not done writing to the cache. 104 // This transaction is being deleted and we are not done writing to the cache.
105 // We need to indicate that the response data was truncated. Returns true on 105 // We need to indicate that the response data was truncated. Returns true on
106 // success. Keep in mind that this operation may have side effects, such as 106 // success. Keep in mind that this operation may have side effects, such as
107 // deleting the active entry. 107 // deleting the active entry.
108 bool AddTruncatedFlag(); 108 bool AddTruncatedFlag();
109 109
110 HttpCache::ActiveEntry* entry() { return entry_; } 110 HttpCache::ActiveEntry* entry() const { return entry_; }
111 111
112 // Returns the LoadState of the writer transaction of a given ActiveEntry. In 112 // Returns the LoadState of the writer transaction of a given ActiveEntry. In
113 // other words, returns the LoadState of this transaction without asking the 113 // other words, returns the LoadState of this transaction without asking the
114 // http cache, because this transaction should be the one currently writing 114 // http cache, because this transaction should be the one currently writing
115 // to the cache entry. 115 // to the cache entry.
116 LoadState GetWriterLoadState() const; 116 LoadState GetWriterLoadState() const;
117 117
118 const CompletionCallback& io_callback() { return io_callback_; } 118 const CompletionCallback& io_callback() { return io_callback_; }
119 119
120 const NetLogWithSource& net_log() const; 120 const NetLogWithSource& net_log() const;
(...skipping 12 matching lines...) Expand all
133 int Start(const HttpRequestInfo* request_info, 133 int Start(const HttpRequestInfo* request_info,
134 const CompletionCallback& callback, 134 const CompletionCallback& callback,
135 const NetLogWithSource& net_log) override; 135 const NetLogWithSource& net_log) override;
136 int RestartIgnoringLastError(const CompletionCallback& callback) override; 136 int RestartIgnoringLastError(const CompletionCallback& callback) override;
137 int RestartWithCertificate(X509Certificate* client_cert, 137 int RestartWithCertificate(X509Certificate* client_cert,
138 SSLPrivateKey* client_private_key, 138 SSLPrivateKey* client_private_key,
139 const CompletionCallback& callback) override; 139 const CompletionCallback& callback) override;
140 int RestartWithAuth(const AuthCredentials& credentials, 140 int RestartWithAuth(const AuthCredentials& credentials,
141 const CompletionCallback& callback) override; 141 const CompletionCallback& callback) override;
142 bool IsReadyToRestartForAuth() override; 142 bool IsReadyToRestartForAuth() override;
143 void Orphan(std::unique_ptr<HttpTransaction> trans) override;
143 int Read(IOBuffer* buf, 144 int Read(IOBuffer* buf,
144 int buf_len, 145 int buf_len,
145 const CompletionCallback& callback) override; 146 const CompletionCallback& callback) override;
146 void StopCaching() override; 147 void StopCaching() override;
147 bool GetFullRequestHeaders(HttpRequestHeaders* headers) const override; 148 bool GetFullRequestHeaders(HttpRequestHeaders* headers) const override;
148 int64_t GetTotalReceivedBytes() const override; 149 int64_t GetTotalReceivedBytes() const override;
149 int64_t GetTotalSentBytes() const override; 150 int64_t GetTotalSentBytes() const override;
150 void DoneReading() override; 151 void DoneReading() override;
151 const HttpResponseInfo* GetResponseInfo() const override; 152 const HttpResponseInfo* GetResponseInfo() const override;
152 LoadState GetLoadState() const override; 153 LoadState GetLoadState() const override;
153 void SetQuicServerInfo(QuicServerInfo* quic_server_info) override; 154 void SetQuicServerInfo(QuicServerInfo* quic_server_info) override;
154 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override; 155 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override;
155 bool GetRemoteEndpoint(IPEndPoint* endpoint) const override; 156 bool GetRemoteEndpoint(IPEndPoint* endpoint) const override;
156 void PopulateNetErrorDetails(NetErrorDetails* details) const override; 157 void PopulateNetErrorDetails(NetErrorDetails* details) const override;
157 void SetPriority(RequestPriority priority) override; 158 void SetPriority(RequestPriority priority) override;
158 void SetWebSocketHandshakeStreamCreateHelper( 159 void SetWebSocketHandshakeStreamCreateHelper(
159 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; 160 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override;
160 void SetBeforeNetworkStartCallback( 161 void SetBeforeNetworkStartCallback(
161 const BeforeNetworkStartCallback& callback) override; 162 const BeforeNetworkStartCallback& callback) override;
162 void SetBeforeHeadersSentCallback( 163 void SetBeforeHeadersSentCallback(
163 const BeforeHeadersSentCallback& callback) override; 164 const BeforeHeadersSentCallback& callback) override;
164 int ResumeNetworkStart() override; 165 int ResumeNetworkStart() override;
165 void GetConnectionAttempts(ConnectionAttempts* out) const override; 166 void GetConnectionAttempts(ConnectionAttempts* out) const override;
167 // Returns true if the transaction is eligible for reading from the
168 // network and writing to the cache along with other transactions.
169 // It is eligible if any of the following conditions are true:
170 // - Request’s mode is READ_WRITE. If mode is only READ then this
171 // 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.
172 // - Method is GET.
173 // - It is not a range request.
174 // - 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.
175 // be stored in the cache
176 // due to any other reason.
177 bool IsEligibleForSharedWriting() const;
178 void ProcessForSharedWriting();
179 void SetShared();
180 void ResetShared(bool continue_network_reading = false,
181 bool continue_cache_reading = false);
182 bool shared() const;
183 bool validating_shared() const;
184 void SetSharedWritingFailState();
185 void ContinueWithoutSharedWriting();
186 void SetFinalizeDoomed();
166 187
167 private: 188 private:
168 static const size_t kNumValidationHeaders = 2; 189 static const size_t kNumValidationHeaders = 2;
169 // Helper struct to pair a header name with its value, for 190 // Helper struct to pair a header name with its value, for
170 // headers used to validate cache entries. 191 // headers used to validate cache entries.
171 struct ValidationHeaders { 192 struct ValidationHeaders {
172 ValidationHeaders() : initialized(false) {} 193 ValidationHeaders() : initialized(false) {}
173 194
174 std::string values[kNumValidationHeaders]; 195 std::string values[kNumValidationHeaders];
175 bool initialized; 196 bool initialized;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 STATE_OVERWRITE_CACHED_RESPONSE, 229 STATE_OVERWRITE_CACHED_RESPONSE,
209 STATE_CACHE_WRITE_RESPONSE, 230 STATE_CACHE_WRITE_RESPONSE,
210 STATE_CACHE_WRITE_RESPONSE_COMPLETE, 231 STATE_CACHE_WRITE_RESPONSE_COMPLETE,
211 STATE_TRUNCATE_CACHED_DATA, 232 STATE_TRUNCATE_CACHED_DATA,
212 STATE_TRUNCATE_CACHED_DATA_COMPLETE, 233 STATE_TRUNCATE_CACHED_DATA_COMPLETE,
213 STATE_TRUNCATE_CACHED_METADATA, 234 STATE_TRUNCATE_CACHED_METADATA,
214 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, 235 STATE_TRUNCATE_CACHED_METADATA_COMPLETE,
215 STATE_PARTIAL_HEADERS_RECEIVED, 236 STATE_PARTIAL_HEADERS_RECEIVED,
216 STATE_CACHE_READ_METADATA, 237 STATE_CACHE_READ_METADATA,
217 STATE_CACHE_READ_METADATA_COMPLETE, 238 STATE_CACHE_READ_METADATA_COMPLETE,
239 // Update the value if another state becomes the last states of the start
240 // state machine.
241 STATE_START_STATE_MACHINE_FINAL = STATE_CACHE_READ_METADATA_COMPLETE,
218 242
243 // Start states should always be before Read states.
219 // These states are entered from Read/AddTruncatedFlag. 244 // These states are entered from Read/AddTruncatedFlag.
220 STATE_NETWORK_READ, 245 STATE_NETWORK_READ,
221 STATE_NETWORK_READ_COMPLETE, 246 STATE_NETWORK_READ_COMPLETE,
247 STATE_SHARED_NETWORK_READ,
248 STATE_SHARED_NETWORK_READ_COMPLETE,
249 STATE_SHARED_NETWORK_READ_WAIT_COMPLETE,
222 STATE_CACHE_READ_DATA, 250 STATE_CACHE_READ_DATA,
223 STATE_CACHE_READ_DATA_COMPLETE, 251 STATE_CACHE_READ_DATA_COMPLETE,
224 STATE_CACHE_WRITE_DATA, 252 STATE_CACHE_WRITE_DATA,
225 STATE_CACHE_WRITE_DATA_COMPLETE, 253 STATE_CACHE_WRITE_DATA_COMPLETE,
226 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, 254 STATE_CACHE_WRITE_TRUNCATED_RESPONSE,
227 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE 255 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE,
256
257 // This state is reached when this transaction is idle waiting for Read to
258 // be invoked and Shared Writing failed.
259 STATE_SHARED_READ_WRITE_FAILED
228 }; 260 };
229 261
230 // Used for categorizing validation triggers in histograms. 262 // Used for categorizing validation triggers in histograms.
231 // NOTE: This enumeration is used in histograms, so please do not add entries 263 // NOTE: This enumeration is used in histograms, so please do not add entries
232 // in the middle. 264 // in the middle.
233 enum ValidationCause { 265 enum ValidationCause {
234 VALIDATION_CAUSE_UNDEFINED, 266 VALIDATION_CAUSE_UNDEFINED,
235 VALIDATION_CAUSE_VARY_MISMATCH, 267 VALIDATION_CAUSE_VARY_MISMATCH,
236 VALIDATION_CAUSE_VALIDATE_FLAG, 268 VALIDATION_CAUSE_VALIDATE_FLAG,
237 VALIDATION_CAUSE_STALE, 269 VALIDATION_CAUSE_STALE,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 int DoCacheWriteResponseComplete(int result); 310 int DoCacheWriteResponseComplete(int result);
279 int DoTruncateCachedData(); 311 int DoTruncateCachedData();
280 int DoTruncateCachedDataComplete(int result); 312 int DoTruncateCachedDataComplete(int result);
281 int DoTruncateCachedMetadata(); 313 int DoTruncateCachedMetadata();
282 int DoTruncateCachedMetadataComplete(int result); 314 int DoTruncateCachedMetadataComplete(int result);
283 int DoPartialHeadersReceived(); 315 int DoPartialHeadersReceived();
284 int DoCacheReadMetadata(); 316 int DoCacheReadMetadata();
285 int DoCacheReadMetadataComplete(int result); 317 int DoCacheReadMetadataComplete(int result);
286 int DoNetworkRead(); 318 int DoNetworkRead();
287 int DoNetworkReadComplete(int result); 319 int DoNetworkReadComplete(int result);
320 int DoSharedNetworkRead();
321 int DoSharedNetworkReadComplete(int result);
322 int DoSharedNetworkReadWaitComplete(int result);
288 int DoCacheReadData(); 323 int DoCacheReadData();
289 int DoCacheReadDataComplete(int result); 324 int DoCacheReadDataComplete(int result);
290 int DoCacheWriteData(int num_bytes); 325 int DoCacheWriteData(int num_bytes);
291 int DoCacheWriteDataComplete(int result); 326 int DoCacheWriteDataComplete(int result);
292 int DoCacheWriteTruncatedResponse(); 327 int DoCacheWriteTruncatedResponse();
293 int DoCacheWriteTruncatedResponseComplete(int result); 328 int DoCacheWriteTruncatedResponseComplete(int result);
294 329
295 // Sets request_ and fields derived from it. 330 // Sets request_ and fields derived from it.
296 void SetRequest(const NetLogWithSource& net_log, 331 void SetRequest(const NetLogWithSource& net_log,
297 const HttpRequestInfo* request); 332 const HttpRequestInfo* request);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 402
368 // Helper function, should be called with result of WriteResponseInfoToEntry 403 // Helper function, should be called with result of WriteResponseInfoToEntry
369 // (or the result of the callback, when WriteResponseInfoToEntry returns 404 // (or the result of the callback, when WriteResponseInfoToEntry returns
370 // ERR_IO_PENDING). Calls DoneWritingToEntry if |result| is not the right 405 // ERR_IO_PENDING). Calls DoneWritingToEntry if |result| is not the right
371 // number of bytes. It is expected that the state that calls this will 406 // number of bytes. It is expected that the state that calls this will
372 // return whatever net error code this function returns, which currently 407 // return whatever net error code this function returns, which currently
373 // is always "OK". 408 // is always "OK".
374 int OnWriteResponseInfoToEntryComplete(int result); 409 int OnWriteResponseInfoToEntryComplete(int result);
375 410
376 // Called when we are done writing to the cache entry. 411 // Called when we are done writing to the cache entry.
377 void DoneWritingToEntry(bool success); 412 // In some case we just want to set the internal state of the transaction but
413 // do not want to invoke any cleanup operation on entry_ e.g. when it's
414 // already done by a SharedWriter callback function.
415 void DoneWritingToEntry(bool success, bool perform_entry_cleanup = true);
378 416
379 // Returns an error to signal the caller that the current read failed. The 417 // Returns an error to signal the caller that the current read failed. The
380 // current operation |result| is also logged. If |restart| is true, the 418 // current operation |result| is also logged. If |restart| is true, the
381 // transaction should be restarted. 419 // transaction should be restarted.
382 int OnCacheReadError(int result, bool restart); 420 int OnCacheReadError(int result, bool restart);
383 421
384 // Called when the cache lock timeout fires. 422 // Called when the cache lock timeout fires.
385 void OnAddToEntryTimeout(base::TimeTicks start_time); 423 void OnAddToEntryTimeout(base::TimeTicks start_time);
386 424
387 // Deletes the current partial cache entry (sparse), and optionally removes 425 // Deletes the current partial cache entry (sparse), and optionally removes
(...skipping 14 matching lines...) Expand all
402 int DoRestartPartialRequest(); 440 int DoRestartPartialRequest();
403 441
404 // Resets the relavant internal state to remove traces of internal processing 442 // Resets the relavant internal state to remove traces of internal processing
405 // related to range requests. Deletes |partial_| if |delete_object| is true. 443 // related to range requests. Deletes |partial_| if |delete_object| is true.
406 void ResetPartialState(bool delete_object); 444 void ResetPartialState(bool delete_object);
407 445
408 // Resets |network_trans_|, which must be non-NULL. Also updates 446 // Resets |network_trans_|, which must be non-NULL. Also updates
409 // |old_network_trans_load_timing_|, which must be NULL when this is called. 447 // |old_network_trans_load_timing_|, which must be NULL when this is called.
410 void ResetNetworkTransaction(); 448 void ResetNetworkTransaction();
411 449
450 void SaveNetworkTransInfo();
jkarlin 2016/12/06 18:08:18 s/Trans/Transaction/
shivanisha 2016/12/06 21:53:35 done
451 void SaveSharedNetworkTransInfo();
jkarlin 2016/12/06 18:08:18 ditto
shivanisha 2016/12/06 21:53:35 done
452
412 // Returns true if we should bother attempting to resume this request if it is 453 // Returns true if we should bother attempting to resume this request if it is
413 // aborted while in progress. If |has_data| is true, the size of the stored 454 // aborted while in progress. If |has_data| is true, the size of the stored
414 // data is considered for the result. 455 // data is considered for the result.
415 bool CanResume(bool has_data); 456 bool CanResume(bool has_data);
416 457
417 // Setter for response_ and auth_response_. It updates its cache entry status, 458 // Setter for response_ and auth_response_. It updates its cache entry status,
418 // if needed. 459 // if needed.
419 void SetResponse(const HttpResponseInfo& new_response); 460 void SetResponse(const HttpResponseInfo& new_response);
420 void SetAuthResponse(const HttpResponseInfo& new_response); 461 void SetAuthResponse(const HttpResponseInfo& new_response);
421 462
422 void UpdateCacheEntryStatus( 463 void UpdateCacheEntryStatus(
423 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); 464 HttpResponseInfo::CacheEntryStatus new_cache_entry_status);
424 465
425 // Sets the response.cache_entry_status to the current cache_entry_status_. 466 // Sets the response.cache_entry_status to the current cache_entry_status_.
426 void SyncCacheEntryStatusToResponse(); 467 void SyncCacheEntryStatusToResponse();
427 void RecordHistograms(); 468 void RecordHistograms();
428 469
429 // Called to signal completion of asynchronous IO. 470 // Called to signal completion of asynchronous IO.
430 void OnIOComplete(int result); 471 void OnIOComplete(int result);
431 472
473 // Called when the transaction needs to be deleted after being orphaned.
474 void Delete();
475
432 State next_state_; 476 State next_state_;
433 const HttpRequestInfo* request_; 477 const HttpRequestInfo* request_;
434 RequestPriority priority_; 478 RequestPriority priority_;
435 NetLogWithSource net_log_; 479 NetLogWithSource net_log_;
436 std::unique_ptr<HttpRequestInfo> custom_request_; 480 std::unique_ptr<HttpRequestInfo> custom_request_;
437 HttpRequestHeaders request_headers_copy_; 481 HttpRequestHeaders request_headers_copy_;
438 // If extra_headers specified a "if-modified-since" or "if-none-match", 482 // If extra_headers specified a "if-modified-since" or "if-none-match",
439 // |external_validation_| contains the value of those headers. 483 // |external_validation_| contains the value of those headers.
440 ValidationHeaders external_validation_; 484 ValidationHeaders external_validation_;
441 base::WeakPtr<HttpCache> cache_; 485 base::WeakPtr<HttpCache> cache_;
(...skipping 11 matching lines...) Expand all
453 bool truncated_; // We don't have all the response data. 497 bool truncated_; // We don't have all the response data.
454 bool is_sparse_; // The data is stored in sparse byte ranges. 498 bool is_sparse_; // The data is stored in sparse byte ranges.
455 bool range_requested_; // The user requested a byte range. 499 bool range_requested_; // The user requested a byte range.
456 bool handling_206_; // We must deal with this 206 response. 500 bool handling_206_; // We must deal with this 206 response.
457 bool cache_pending_; // We are waiting for the HttpCache. 501 bool cache_pending_; // We are waiting for the HttpCache.
458 bool done_reading_; // All available data was read. 502 bool done_reading_; // All available data was read.
459 bool vary_mismatch_; // The request doesn't match the stored vary data. 503 bool vary_mismatch_; // The request doesn't match the stored vary data.
460 bool couldnt_conditionalize_request_; 504 bool couldnt_conditionalize_request_;
461 bool bypass_lock_for_test_; // A test is exercising the cache lock. 505 bool bypass_lock_for_test_; // A test is exercising the cache lock.
462 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. 506 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest.
507 // 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
508 bool shared_;
509 bool finalize_doomed_;
510 bool orphaned_;
463 scoped_refptr<IOBuffer> read_buf_; 511 scoped_refptr<IOBuffer> read_buf_;
464 int io_buf_len_; 512 int io_buf_len_;
465 int read_offset_; 513 int read_offset_;
466 int effective_load_flags_; 514 int effective_load_flags_;
467 int write_len_; 515 int write_len_;
468 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. 516 std::unique_ptr<PartialData> partial_; // We are dealing with range requests.
469 CompletionCallback io_callback_; 517 CompletionCallback io_callback_;
470 518
471 // Members used to track data for histograms. 519 // Members used to track data for histograms.
472 // This cache_entry_status_ takes precedence over 520 // This cache_entry_status_ takes precedence over
(...skipping 23 matching lines...) Expand all
496 // The helper object to use to create WebSocketHandshakeStreamBase 544 // The helper object to use to create WebSocketHandshakeStreamBase
497 // objects. Only relevant when establishing a WebSocket connection. 545 // objects. Only relevant when establishing a WebSocket connection.
498 // This is passed to the underlying network transaction. It is stored here in 546 // This is passed to the underlying network transaction. It is stored here in
499 // case the transaction does not exist yet. 547 // case the transaction does not exist yet.
500 WebSocketHandshakeStreamBase::CreateHelper* 548 WebSocketHandshakeStreamBase::CreateHelper*
501 websocket_handshake_stream_base_create_helper_; 549 websocket_handshake_stream_base_create_helper_;
502 550
503 BeforeNetworkStartCallback before_network_start_callback_; 551 BeforeNetworkStartCallback before_network_start_callback_;
504 BeforeHeadersSentCallback before_headers_sent_callback_; 552 BeforeHeadersSentCallback before_headers_sent_callback_;
505 553
554 bool have_full_request_headers_;
555 HttpRequestHeaders full_request_headers_;
556
506 base::WeakPtrFactory<Transaction> weak_factory_; 557 base::WeakPtrFactory<Transaction> weak_factory_;
507 558
508 DISALLOW_COPY_AND_ASSIGN(Transaction); 559 DISALLOW_COPY_AND_ASSIGN(Transaction);
509 }; 560 };
510 561
511 } // namespace net 562 } // namespace net
512 563
513 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 564 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698