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

Side by Side 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: 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 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 STATE_CACHE_WRITE_RESPONSE, 203 STATE_CACHE_WRITE_RESPONSE,
204 STATE_CACHE_WRITE_RESPONSE_COMPLETE, 204 STATE_CACHE_WRITE_RESPONSE_COMPLETE,
205 STATE_TRUNCATE_CACHED_DATA, 205 STATE_TRUNCATE_CACHED_DATA,
206 STATE_TRUNCATE_CACHED_DATA_COMPLETE, 206 STATE_TRUNCATE_CACHED_DATA_COMPLETE,
207 STATE_TRUNCATE_CACHED_METADATA, 207 STATE_TRUNCATE_CACHED_METADATA,
208 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, 208 STATE_TRUNCATE_CACHED_METADATA_COMPLETE,
209 STATE_PARTIAL_HEADERS_RECEIVED, 209 STATE_PARTIAL_HEADERS_RECEIVED,
210 STATE_CACHE_READ_METADATA, 210 STATE_CACHE_READ_METADATA,
211 STATE_CACHE_READ_METADATA_COMPLETE, 211 STATE_CACHE_READ_METADATA_COMPLETE,
212 212
213 // These states are entered from Read/AddTruncatedFlag. 213 // These states are entered from Read.
214 STATE_SWITCH_TO_NETWORK,
214 STATE_NETWORK_READ, 215 STATE_NETWORK_READ,
215 STATE_NETWORK_READ_COMPLETE, 216 STATE_NETWORK_READ_COMPLETE,
216 STATE_CACHE_READ_DATA, 217 STATE_CACHE_READ_DATA,
217 STATE_CACHE_READ_DATA_COMPLETE, 218 STATE_CACHE_READ_DATA_COMPLETE,
218 STATE_CACHE_WRITE_DATA, 219 STATE_CACHE_WRITE_DATA,
219 STATE_CACHE_WRITE_DATA_COMPLETE, 220 STATE_CACHE_WRITE_DATA_COMPLETE,
220 STATE_CACHE_WRITE_TRUNCATED_RESPONSE,
221 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE
222 }; 221 };
223 222
224 // Used for categorizing transactions for reporting in histograms. Patterns 223 // Used for categorizing transactions for reporting in histograms. Patterns
225 // cover relatively common use cases being measured and considered for 224 // cover relatively common use cases being measured and considered for
226 // optimization. Many use cases that are more complex or uncommon are binned 225 // optimization. Many use cases that are more complex or uncommon are binned
227 // as PATTERN_NOT_COVERED, and details are not reported. 226 // as PATTERN_NOT_COVERED, and details are not reported.
228 // NOTE: This enumeration is used in histograms, so please do not add entries 227 // NOTE: This enumeration is used in histograms, so please do not add entries
229 // in the middle. 228 // in the middle.
230 enum TransactionPattern { 229 enum TransactionPattern {
231 PATTERN_UNDEFINED, 230 PATTERN_UNDEFINED,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 int DoOverwriteCachedResponse(); 274 int DoOverwriteCachedResponse();
276 int DoCacheWriteResponse(); 275 int DoCacheWriteResponse();
277 int DoCacheWriteResponseComplete(int result); 276 int DoCacheWriteResponseComplete(int result);
278 int DoTruncateCachedData(); 277 int DoTruncateCachedData();
279 int DoTruncateCachedDataComplete(int result); 278 int DoTruncateCachedDataComplete(int result);
280 int DoTruncateCachedMetadata(); 279 int DoTruncateCachedMetadata();
281 int DoTruncateCachedMetadataComplete(int result); 280 int DoTruncateCachedMetadataComplete(int result);
282 int DoPartialHeadersReceived(); 281 int DoPartialHeadersReceived();
283 int DoCacheReadMetadata(); 282 int DoCacheReadMetadata();
284 int DoCacheReadMetadataComplete(int result); 283 int DoCacheReadMetadataComplete(int result);
284 int DoSwitchToNetwork();
285 int DoNetworkRead(); 285 int DoNetworkRead();
286 int DoNetworkReadComplete(int result); 286 int DoNetworkReadComplete(int result);
287 int DoCacheReadData(); 287 int DoCacheReadData();
288 int DoCacheReadDataComplete(int result); 288 int DoCacheReadDataComplete(int result);
289 int DoCacheWriteData(int num_bytes); 289 int DoCacheWriteData(int num_bytes);
290 int DoCacheWriteDataComplete(int result); 290 int DoCacheWriteDataComplete(int result);
291 int DoCacheWriteTruncatedResponse();
292 int DoCacheWriteTruncatedResponseComplete(int result);
293 291
294 // These functions are involved in a field trial testing storing certificates 292 // These functions are involved in a field trial testing storing certificates
295 // in seperate entries from the HttpResponseInfo. 293 // in seperate entries from the HttpResponseInfo.
296 void ReadCertChain(); 294 void ReadCertChain();
297 void WriteCertChain(); 295 void WriteCertChain();
298 296
299 // Sets request_ and fields derived from it. 297 // Sets request_ and fields derived from it.
300 void SetRequest(const BoundNetLog& net_log, const HttpRequestInfo* request); 298 void SetRequest(const BoundNetLog& net_log, const HttpRequestInfo* request);
301 299
302 // Returns true if the request should be handled exclusively by the network 300 // Returns true if the request should be handled exclusively by the network
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // Setups the transaction for reading from the cache entry. 355 // Setups the transaction for reading from the cache entry.
358 int SetupEntryForRead(); 356 int SetupEntryForRead();
359 357
360 // Called to write data to the cache entry. If the write fails, then the 358 // Called to write data to the cache entry. If the write fails, then the
361 // cache entry is destroyed. Future calls to this function will just do 359 // cache entry is destroyed. Future calls to this function will just do
362 // nothing without side-effect. Returns a network error code. 360 // nothing without side-effect. Returns a network error code.
363 int WriteToEntry(int index, int offset, IOBuffer* data, int data_len, 361 int WriteToEntry(int index, int offset, IOBuffer* data, int data_len,
364 const CompletionCallback& callback); 362 const CompletionCallback& callback);
365 363
366 // Called to write response_ to the cache entry. |truncated| indicates if the 364 // Called to write response_ to the cache entry. |truncated| indicates if the
367 // entry should be marked as incomplete. 365 // entry should be marked as incomplete. Returns ERR_IO_PENDING if an
368 int WriteResponseInfoToEntry(bool truncated); 366 // operation is pending. Once |callback| is invoked, the caller should call
367 // OnWriteResponseInfoToEntryComplete() with the result to complete the
368 // write operation.
369 int WriteResponseInfoToEntry(bool truncated,
370 const CompletionCallback& callback);
369 371
370 // Helper function, should be called with result of WriteResponseInfoToEntry 372 // Helper function, should be called with result of WriteResponseInfoToEntry
371 // (or the result of the callback, when WriteResponseInfoToEntry returns 373 // (or the result of the callback, when WriteResponseInfoToEntry returns
372 // ERR_IO_PENDING). Calls DoneWritingToEntry if |result| is not the right 374 // ERR_IO_PENDING). Calls ReleaseCacheEntry() to doom the entry if the number
373 // number of bytes. It is expected that the state that calls this will 375 // of bytes written is less than expected. It is expected that the state that
374 // return whatever net error code this function returns, which currently 376 // calls this will return whatever net error code this function returns, which
375 // is always "OK". 377 // currently is always "OK".
376 int OnWriteResponseInfoToEntryComplete(int result); 378 int OnWriteResponseInfoToEntryComplete(int result);
377 379
380 // Releases the cache entry. The |entry_state| parameter specifies the state
381 // of the entry following the release.
382 void ReleaseCacheEntry(EntryState entry_state);
383
378 // Called when we are done writing to the cache entry. 384 // Called when we are done writing to the cache entry.
379 void DoneWritingToEntry(bool success); 385 void DoneWritingToEntry(bool success);
380 386
381 // Returns an error to signal the caller that the current read failed. The 387 // Returns an error to signal the caller that the current read failed. The
382 // current operation |result| is also logged. If |restart| is true, the 388 // current operation |result| is also logged. If |restart| is true, the
383 // transaction should be restarted. 389 // transaction should be restarted.
384 int OnCacheReadError(int result, bool restart); 390 int OnCacheReadError(int result, bool restart);
385 391
386 // Called when the cache lock timeout fires. 392 // Called when the cache lock timeout fires.
387 void OnAddToEntryTimeout(base::TimeTicks start_time); 393 void OnAddToEntryTimeout(base::TimeTicks start_time);
388 394
389 // Deletes the current partial cache entry (sparse), and optionally removes 395 // Deletes the current partial cache entry (sparse), and optionally removes
390 // the control object (partial_). 396 // the control object (partial_).
391 void DoomPartialEntry(bool delete_object); 397 void DoomPartialEntry(bool delete_object);
392 398
393 // Performs the needed work after receiving data from the network, when 399 // Performs the needed work after receiving data from the network, when
394 // working with range requests. 400 // working with range requests.
395 int DoPartialNetworkReadCompleted(int result); 401 int DoPartialNetworkReadCompleted(int result);
396 402
397 // Performs the needed work after receiving data from the cache, when 403 // Performs the needed work after receiving data from the cache, when
398 // working with range requests. 404 // working with range requests.
399 int DoPartialCacheReadCompleted(int result); 405 int DoPartialCacheReadCompleted(int result);
400 406
401 // Restarts this transaction after deleting the cached data. It is meant to 407 // Restarts this transaction after deleting the cached data. It is meant to
402 // be used when the current request cannot be fulfilled due to conflicts 408 // be used when the current request cannot be fulfilled due to conflicts
403 // between the byte range request and the cached entry. 409 // between the byte range request and the cached entry.
404 int DoRestartPartialRequest(); 410 int DoRestartPartialRequest();
405 411
412 void OnCacheReleaseComplete(const base::Closure& closure, int result);
413
406 // Resets the relavant internal state to remove traces of internal processing 414 // Resets the relavant internal state to remove traces of internal processing
407 // related to range requests. Deletes |partial_| if |delete_object| is true. 415 // related to range requests. Deletes |partial_| if |delete_object| is true.
408 void ResetPartialState(bool delete_object); 416 void ResetPartialState(bool delete_object);
409 417
410 // Resets |network_trans_|, which must be non-NULL. Also updates 418 // Resets |network_trans_|, which must be non-NULL. Also updates
411 // |old_network_trans_load_timing_|, which must be NULL when this is called. 419 // |old_network_trans_load_timing_|, which must be NULL when this is called.
412 void ResetNetworkTransaction(); 420 void ResetNetworkTransaction();
413 421
414 // Returns true if we should bother attempting to resume this request if it 422 // Returns true if we should bother attempting to resume this request if it
415 // is aborted while in progress. If |has_data| is true, the size of the stored 423 // is aborted while in progress. If |has_data| is true, the size of the stored
416 // data is considered for the result. 424 // data is considered for the result.
417 bool CanResume(bool has_data); 425 bool CanResume(bool has_data);
418 426
419 void UpdateTransactionPattern(TransactionPattern new_transaction_pattern); 427 void UpdateTransactionPattern(TransactionPattern new_transaction_pattern);
420 void RecordHistograms(); 428 void RecordHistograms();
421 429
422 // Called to signal completion of asynchronous IO. 430 // Called to signal completion of asynchronous IO.
423 void OnIOComplete(int result); 431 void OnIOComplete(int result);
424 432
433 // Abandons a cache entry.
434 //
435 // This should be called when the transaction abnormally terminates writing to
436 // a cache entry. Once called, the cache entry could be either retained or
437 // truncated or destroyed depending on whether the full response entity was
438 // written to the cache or whether the partial cache entry can be fulfiled
439 // later by resuming the network request.
440 //
441 // If any asynchronous operations are pending, returns ERR_IO_PENDING and
442 // invokes |callback| when the opearations are complete. entry_ is always
443 // released upon completion.
444 //
445 // If |callback| is empty, then releases the cache entry synchronously. It is
446 // possible for the cache entry to be in an indeterminate state in this case.
447 int AbandonCacheEntry(const CompletionCallback& callback);
448
449 // Called to signal IO completion for AbandonCacheEntry().
450 void OnAbandonCacheEntryIOComplete(int result);
451
425 State next_state_; 452 State next_state_;
426 const HttpRequestInfo* request_; 453 const HttpRequestInfo* request_;
427 RequestPriority priority_; 454 RequestPriority priority_;
428 BoundNetLog net_log_; 455 BoundNetLog net_log_;
429 scoped_ptr<HttpRequestInfo> custom_request_; 456 scoped_ptr<HttpRequestInfo> custom_request_;
430 HttpRequestHeaders request_headers_copy_; 457 HttpRequestHeaders request_headers_copy_;
431 // If extra_headers specified a "if-modified-since" or "if-none-match", 458 // If extra_headers specified a "if-modified-since" or "if-none-match",
432 // |external_validation_| contains the value of those headers. 459 // |external_validation_| contains the value of those headers.
433 ValidationHeaders external_validation_; 460 ValidationHeaders external_validation_;
434 base::WeakPtr<HttpCache> cache_; 461 base::WeakPtr<HttpCache> cache_;
435 HttpCache::ActiveEntry* entry_; 462 HttpCache::ActiveEntry* entry_;
436 HttpCache::ActiveEntry* new_entry_; 463 HttpCache::ActiveEntry* new_entry_;
437 scoped_ptr<HttpTransaction> network_trans_; 464 scoped_ptr<HttpTransaction> network_trans_;
438 CompletionCallback callback_; // Consumer's callback. 465 CompletionCallback callback_; // Consumer's callback.
439 HttpResponseInfo response_; 466 HttpResponseInfo response_;
440 HttpResponseInfo auth_response_; 467 HttpResponseInfo auth_response_;
441 const HttpResponseInfo* new_response_; 468 const HttpResponseInfo* new_response_;
442 std::string cache_key_; 469 std::string cache_key_;
443 Mode mode_; 470 Mode mode_;
444 bool reading_; // We are already reading. Never reverts to false once set. 471 bool reading_; // We are already reading. Never reverts to false once set.
445 bool invalid_range_; // We may bypass the cache for this request. 472 bool invalid_range_; // We may bypass the cache for this request.
446 bool truncated_; // We don't have all the response data. 473 bool truncated_; // We don't have all the response data.
447 bool is_sparse_; // The data is stored in sparse byte ranges. 474 bool is_sparse_; // The data is stored in sparse byte ranges.
448 bool range_requested_; // The user requested a byte range. 475 bool range_requested_; // The user requested a byte range.
449 bool handling_206_; // We must deal with this 206 response. 476 bool handling_206_; // We must deal with this 206 response.
450 bool cache_pending_; // We are waiting for the HttpCache. 477 bool cache_pending_; // We are waiting for the HttpCache.
451 bool done_reading_; // All available data was read. 478 bool done_reading_; // All available data was written to the cache entry.
452 bool vary_mismatch_; // The request doesn't match the stored vary data. 479 bool vary_mismatch_; // The request doesn't match the stored vary data.
453 bool couldnt_conditionalize_request_; 480 bool couldnt_conditionalize_request_;
481 bool stopped_caching_; // Avoid further writes to the cache.
454 bool bypass_lock_for_test_; // A test is exercising the cache lock. 482 bool bypass_lock_for_test_; // A test is exercising the cache lock.
455 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. 483 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest.
456 scoped_refptr<IOBuffer> read_buf_; 484 scoped_refptr<IOBuffer> read_buf_;
485 int read_buf_len_;
457 int io_buf_len_; 486 int io_buf_len_;
458 int read_offset_; 487 int read_offset_;
459 int effective_load_flags_; 488 int effective_load_flags_;
460 int write_len_; 489 int write_len_;
461 scoped_ptr<PartialData> partial_; // We are dealing with range requests. 490 scoped_ptr<PartialData> partial_; // We are dealing with range requests.
462 UploadProgress final_upload_progress_; 491 UploadProgress final_upload_progress_;
463 CompletionCallback io_callback_; 492 CompletionCallback io_callback_;
464 493
494 // Completion callback for AbandonCacheEntry().
495 CompletionCallback abandon_cache_entry_callback_;
496
465 // Members used to track data for histograms. 497 // Members used to track data for histograms.
466 TransactionPattern transaction_pattern_; 498 TransactionPattern transaction_pattern_;
467 base::TimeTicks entry_lock_waiting_since_; 499 base::TimeTicks entry_lock_waiting_since_;
468 base::TimeTicks first_cache_access_since_; 500 base::TimeTicks first_cache_access_since_;
469 base::TimeTicks send_request_since_; 501 base::TimeTicks send_request_since_;
470 502
471 int64 total_received_bytes_; 503 int64 total_received_bytes_;
472 504
473 // Load timing information for the last network request, if any. Set in the 505 // Load timing information for the last network request, if any. Set in the
474 // 304 and 206 response cases, as the network transaction may be destroyed 506 // 304 and 206 response cases, as the network transaction may be destroyed
(...skipping 13 matching lines...) Expand all
488 BeforeProxyHeadersSentCallback before_proxy_headers_sent_callback_; 520 BeforeProxyHeadersSentCallback before_proxy_headers_sent_callback_;
489 521
490 base::WeakPtrFactory<Transaction> weak_factory_; 522 base::WeakPtrFactory<Transaction> weak_factory_;
491 523
492 DISALLOW_COPY_AND_ASSIGN(Transaction); 524 DISALLOW_COPY_AND_ASSIGN(Transaction);
493 }; 525 };
494 526
495 } // namespace net 527 } // namespace net
496 528
497 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ 529 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698