OLD | NEW |
---|---|
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 // in the middle. | 237 // in the middle. |
238 enum ValidationCause { | 238 enum ValidationCause { |
239 VALIDATION_CAUSE_UNDEFINED, | 239 VALIDATION_CAUSE_UNDEFINED, |
240 VALIDATION_CAUSE_VARY_MISMATCH, | 240 VALIDATION_CAUSE_VARY_MISMATCH, |
241 VALIDATION_CAUSE_VALIDATE_FLAG, | 241 VALIDATION_CAUSE_VALIDATE_FLAG, |
242 VALIDATION_CAUSE_STALE, | 242 VALIDATION_CAUSE_STALE, |
243 VALIDATION_CAUSE_ZERO_FRESHNESS, | 243 VALIDATION_CAUSE_ZERO_FRESHNESS, |
244 VALIDATION_CAUSE_MAX | 244 VALIDATION_CAUSE_MAX |
245 }; | 245 }; |
246 | 246 |
247 // What, if any, network confirmation for a cache entry is required. | |
248 enum EntryValidationStatus { | |
249 USABLE, // Can be used without server ok. | |
250 REQUIRES_VALIDATION, // Need to check with server. | |
251 REQUIRES_VALIDATION_VARY_MISMATCH, // Vary mismatch allows last-modified. | |
252 REQUIRES_REFETCH // Entry needs to be fetched. | |
shivanisha
2017/05/02 16:03:26
nit: prefer enum class for type safety.
| |
253 }; | |
254 | |
247 // Runs the state transition loop. Resets and calls |callback_| on exit, | 255 // Runs the state transition loop. Resets and calls |callback_| on exit, |
248 // unless the return value is ERR_IO_PENDING. | 256 // unless the return value is ERR_IO_PENDING. |
249 int DoLoop(int result); | 257 int DoLoop(int result); |
250 | 258 |
251 // Each of these methods corresponds to a State value. If there is an | 259 // Each of these methods corresponds to a State value. If there is an |
252 // argument, the value corresponds to the return of the previous state or | 260 // argument, the value corresponds to the return of the previous state or |
253 // corresponding callback. | 261 // corresponding callback. |
254 int DoGetBackend(); | 262 int DoGetBackend(); |
255 int DoGetBackendComplete(int result); | 263 int DoGetBackendComplete(int result); |
256 int DoInitEntry(); | 264 int DoInitEntry(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
331 | 339 |
332 // Called to restart a network transaction with a client certificate. | 340 // Called to restart a network transaction with a client certificate. |
333 // Returns network error code. | 341 // Returns network error code. |
334 int RestartNetworkRequestWithCertificate(X509Certificate* client_cert, | 342 int RestartNetworkRequestWithCertificate(X509Certificate* client_cert, |
335 SSLPrivateKey* client_private_key); | 343 SSLPrivateKey* client_private_key); |
336 | 344 |
337 // Called to restart a network transaction with authentication credentials. | 345 // Called to restart a network transaction with authentication credentials. |
338 // Returns network error code. | 346 // Returns network error code. |
339 int RestartNetworkRequestWithAuth(const AuthCredentials& credentials); | 347 int RestartNetworkRequestWithAuth(const AuthCredentials& credentials); |
340 | 348 |
341 // Called to determine if we need to validate the cache entry before using it. | 349 // Helper function for GetEntryValidationStatus(). |*vary_mismatch| will |
342 bool RequiresValidation(); | 350 // be set to false unless validation is required because of a vary mismatch. |
351 bool RequiresValidation(bool* vary_mismatch) const; | |
343 | 352 |
344 // Called to make the request conditional (to ask the server if the cached | 353 // Return the type of network validation required by the entry. |
345 // copy is valid). Returns true if able to make the request conditional. | 354 EntryValidationStatus GetEntryValidationStatus() const; |
346 bool ConditionalizeRequest(); | |
347 | 355 |
348 // Makes sure that a 206 response is expected. Returns true on success. | 356 // Makes sure that a 206 response is expected. Returns true on success. |
349 // On success, handling_206_ will be set to true if we are processing a | 357 // On success, handling_206_ will be set to true if we are processing a |
350 // partial entry. | 358 // partial entry. |
351 bool ValidatePartialResponse(); | 359 bool ValidatePartialResponse(); |
352 | 360 |
353 // Handles a response validation error by bypassing the cache. | 361 // Handles a response validation error by bypassing the cache. |
354 void IgnoreRangeRequest(); | 362 void IgnoreRangeRequest(); |
355 | 363 |
356 // Fixes the response headers to match expectations for a HEAD request. | 364 // Fixes the response headers to match expectations for a HEAD request. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 // Setter for response_ and auth_response_. It updates its cache entry status, | 429 // Setter for response_ and auth_response_. It updates its cache entry status, |
422 // if needed. | 430 // if needed. |
423 void SetResponse(const HttpResponseInfo& new_response); | 431 void SetResponse(const HttpResponseInfo& new_response); |
424 void SetAuthResponse(const HttpResponseInfo& new_response); | 432 void SetAuthResponse(const HttpResponseInfo& new_response); |
425 | 433 |
426 void UpdateCacheEntryStatus( | 434 void UpdateCacheEntryStatus( |
427 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); | 435 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); |
428 | 436 |
429 // Sets the response.cache_entry_status to the current cache_entry_status_. | 437 // Sets the response.cache_entry_status to the current cache_entry_status_. |
430 void SyncCacheEntryStatusToResponse(); | 438 void SyncCacheEntryStatusToResponse(); |
431 void RecordHistograms(); | 439 void RecordHistograms(); |
shivanisha
2017/05/02 16:03:26
Request: Can RecordHistograms be made const as wel
| |
432 | 440 |
433 // Called to signal completion of asynchronous IO. | 441 // Called to signal completion of asynchronous IO. |
434 void OnIOComplete(int result); | 442 void OnIOComplete(int result); |
435 | 443 |
436 // When in a DoLoop, use this to set the next state as it verifies that the | 444 // When in a DoLoop, use this to set the next state as it verifies that the |
437 // state isn't set twice. | 445 // state isn't set twice. |
438 void TransitionToState(State state); | 446 void TransitionToState(State state); |
439 | 447 |
440 State next_state_; | 448 State next_state_; |
441 const HttpRequestInfo* request_; | 449 const HttpRequestInfo* request_; |
(...skipping 15 matching lines...) Expand all Loading... | |
457 std::string cache_key_; | 465 std::string cache_key_; |
458 Mode mode_; | 466 Mode mode_; |
459 bool reading_; // We are already reading. Never reverts to false once set. | 467 bool reading_; // We are already reading. Never reverts to false once set. |
460 bool invalid_range_; // We may bypass the cache for this request. | 468 bool invalid_range_; // We may bypass the cache for this request. |
461 bool truncated_; // We don't have all the response data. | 469 bool truncated_; // We don't have all the response data. |
462 bool is_sparse_; // The data is stored in sparse byte ranges. | 470 bool is_sparse_; // The data is stored in sparse byte ranges. |
463 bool range_requested_; // The user requested a byte range. | 471 bool range_requested_; // The user requested a byte range. |
464 bool handling_206_; // We must deal with this 206 response. | 472 bool handling_206_; // We must deal with this 206 response. |
465 bool cache_pending_; // We are waiting for the HttpCache. | 473 bool cache_pending_; // We are waiting for the HttpCache. |
466 bool done_reading_; // All available data was read. | 474 bool done_reading_; // All available data was read. |
467 bool vary_mismatch_; // The request doesn't match the stored vary data. | |
468 bool couldnt_conditionalize_request_; | 475 bool couldnt_conditionalize_request_; |
469 bool bypass_lock_for_test_; // A test is exercising the cache lock. | 476 bool bypass_lock_for_test_; // A test is exercising the cache lock. |
470 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. | 477 bool fail_conditionalization_for_test_; // Fail ConditionalizeRequest. |
471 scoped_refptr<IOBuffer> read_buf_; | 478 scoped_refptr<IOBuffer> read_buf_; |
472 int io_buf_len_; | 479 int io_buf_len_; |
473 int read_offset_; | 480 int read_offset_; |
474 int effective_load_flags_; | 481 int effective_load_flags_; |
475 int write_len_; | 482 int write_len_; |
476 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. | 483 std::unique_ptr<PartialData> partial_; // We are dealing with range requests. |
477 CompletionCallback io_callback_; | 484 CompletionCallback io_callback_; |
478 | 485 |
479 // Members used to track data for histograms. | 486 // Members used to track data for histograms. The state of these fields |
487 // do not affect the behavior of the transaction, and hence can be changed | |
488 // in const methods. | |
480 // This cache_entry_status_ takes precedence over | 489 // This cache_entry_status_ takes precedence over |
481 // response_.cache_entry_status. In fact, response_.cache_entry_status must be | 490 // response_.cache_entry_status. In fact, response_.cache_entry_status must be |
482 // kept in sync with cache_entry_status_ (via SetResponse and | 491 // kept in sync with cache_entry_status_ (via SetResponse and |
483 // UpdateCacheEntryStatus). | 492 // UpdateCacheEntryStatus). |
484 HttpResponseInfo::CacheEntryStatus cache_entry_status_; | 493 HttpResponseInfo::CacheEntryStatus cache_entry_status_; |
485 ValidationCause validation_cause_; | 494 mutable ValidationCause validation_cause_; |
486 base::TimeTicks entry_lock_waiting_since_; | 495 base::TimeTicks entry_lock_waiting_since_; |
487 base::TimeTicks first_cache_access_since_; | 496 base::TimeTicks first_cache_access_since_; |
488 base::TimeTicks send_request_since_; | 497 base::TimeTicks send_request_since_; |
489 base::Time open_entry_last_used_; | 498 base::Time open_entry_last_used_; |
490 base::TimeDelta stale_entry_freshness_; | 499 mutable base::TimeDelta stale_entry_freshness_; |
491 base::TimeDelta stale_entry_age_; | 500 mutable base::TimeDelta stale_entry_age_; |
492 | 501 |
493 int64_t total_received_bytes_; | 502 int64_t total_received_bytes_; |
494 int64_t total_sent_bytes_; | 503 int64_t total_sent_bytes_; |
495 | 504 |
496 // 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 |
497 // 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 |
498 // before the caller requests load timing information. | 507 // before the caller requests load timing information. |
499 std::unique_ptr<LoadTimingInfo> old_network_trans_load_timing_; | 508 std::unique_ptr<LoadTimingInfo> old_network_trans_load_timing_; |
500 | 509 |
501 ConnectionAttempts old_connection_attempts_; | 510 ConnectionAttempts old_connection_attempts_; |
(...skipping 13 matching lines...) Expand all Loading... | |
515 bool in_do_loop_; | 524 bool in_do_loop_; |
516 | 525 |
517 base::WeakPtrFactory<Transaction> weak_factory_; | 526 base::WeakPtrFactory<Transaction> weak_factory_; |
518 | 527 |
519 DISALLOW_COPY_AND_ASSIGN(Transaction); | 528 DISALLOW_COPY_AND_ASSIGN(Transaction); |
520 }; | 529 }; |
521 | 530 |
522 } // namespace net | 531 } // namespace net |
523 | 532 |
524 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 533 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
OLD | NEW |