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

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

Powered by Google App Engine
This is Rietveld 408576698