| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 READ_WRITE = READ | WRITE, | 73 READ_WRITE = READ | WRITE, |
| 74 UPDATE = READ_META | WRITE, // READ_WRITE & ~READ_DATA | 74 UPDATE = READ_META | WRITE, // READ_WRITE & ~READ_DATA |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 Transaction(RequestPriority priority, | 77 Transaction(RequestPriority priority, |
| 78 HttpCache* cache); | 78 HttpCache* cache); |
| 79 ~Transaction() override; | 79 ~Transaction() override; |
| 80 | 80 |
| 81 Mode mode() const { return mode_; } | 81 Mode mode() const { return mode_; } |
| 82 | 82 |
| 83 std::string& method() { return method_; } |
| 84 |
| 83 const std::string& key() const { return cache_key_; } | 85 const std::string& key() const { return cache_key_; } |
| 84 | 86 |
| 85 // Writes |buf_len| bytes of meta-data from the provided buffer |buf|. to the | 87 // Writes |buf_len| bytes of meta-data from the provided buffer |buf|. to the |
| 86 // HTTP cache entry that backs this transaction (if any). | 88 // HTTP cache entry that backs this transaction (if any). |
| 87 // Returns the number of bytes actually written, or a net error code. If the | 89 // Returns the number of bytes actually written, or a net error code. If the |
| 88 // operation cannot complete immediately, returns ERR_IO_PENDING, grabs a | 90 // operation cannot complete immediately, returns ERR_IO_PENDING, grabs a |
| 89 // reference to the buffer (until completion), and notifies the caller using | 91 // reference to the buffer (until completion), and notifies the caller using |
| 90 // the provided |callback| when the operation finishes. | 92 // the provided |callback| when the operation finishes. |
| 91 // | 93 // |
| 92 // The first time this method is called for a given transaction, previous | 94 // The first time this method is called for a given transaction, previous |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 void SetPriority(RequestPriority priority) override; | 159 void SetPriority(RequestPriority priority) override; |
| 158 void SetWebSocketHandshakeStreamCreateHelper( | 160 void SetWebSocketHandshakeStreamCreateHelper( |
| 159 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; | 161 WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; |
| 160 void SetBeforeNetworkStartCallback( | 162 void SetBeforeNetworkStartCallback( |
| 161 const BeforeNetworkStartCallback& callback) override; | 163 const BeforeNetworkStartCallback& callback) override; |
| 162 void SetBeforeHeadersSentCallback( | 164 void SetBeforeHeadersSentCallback( |
| 163 const BeforeHeadersSentCallback& callback) override; | 165 const BeforeHeadersSentCallback& callback) override; |
| 164 int ResumeNetworkStart() override; | 166 int ResumeNetworkStart() override; |
| 165 void GetConnectionAttempts(ConnectionAttempts* out) const override; | 167 void GetConnectionAttempts(ConnectionAttempts* out) const override; |
| 166 | 168 |
| 169 // Invoked when parallel validation cannot proceed due to response failure |
| 170 // and this transaction needs to be restarted. |
| 171 void SetValidatingCannotProceed(); |
| 172 |
| 167 // Returns the estimate of dynamically allocated memory in bytes. | 173 // Returns the estimate of dynamically allocated memory in bytes. |
| 168 size_t EstimateMemoryUsage() const; | 174 size_t EstimateMemoryUsage() const; |
| 169 | 175 |
| 170 private: | 176 private: |
| 171 static const size_t kNumValidationHeaders = 2; | 177 static const size_t kNumValidationHeaders = 2; |
| 172 // Helper struct to pair a header name with its value, for | 178 // Helper struct to pair a header name with its value, for |
| 173 // headers used to validate cache entries. | 179 // headers used to validate cache entries. |
| 174 struct ValidationHeaders { | 180 struct ValidationHeaders { |
| 175 ValidationHeaders() : initialized(false) {} | 181 ValidationHeaders() : initialized(false) {} |
| 176 | 182 |
| 177 std::string values[kNumValidationHeaders]; | 183 std::string values[kNumValidationHeaders]; |
| 178 bool initialized; | 184 bool initialized; |
| 179 }; | 185 }; |
| 180 | 186 |
| 187 // Used when restarting the transaction. |
| 188 struct RestartInfo { |
| 189 Mode mode = NONE; |
| 190 HttpResponseInfo::CacheEntryStatus cache_entry_status = |
| 191 HttpResponseInfo::CacheEntryStatus::ENTRY_UNDEFINED; |
| 192 }; |
| 193 |
| 181 enum State { | 194 enum State { |
| 182 STATE_UNSET, | 195 STATE_UNSET, |
| 183 | 196 |
| 184 // Normally, states are traversed in approximately this order. | 197 // Normally, states are traversed in approximately this order. |
| 185 STATE_NONE, | 198 STATE_NONE, |
| 186 STATE_GET_BACKEND, | 199 STATE_GET_BACKEND, |
| 187 STATE_GET_BACKEND_COMPLETE, | 200 STATE_GET_BACKEND_COMPLETE, |
| 188 STATE_INIT_ENTRY, | 201 STATE_INIT_ENTRY, |
| 189 STATE_OPEN_ENTRY, | 202 STATE_OPEN_ENTRY, |
| 190 STATE_OPEN_ENTRY_COMPLETE, | 203 STATE_OPEN_ENTRY_COMPLETE, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 213 STATE_OVERWRITE_CACHED_RESPONSE, | 226 STATE_OVERWRITE_CACHED_RESPONSE, |
| 214 STATE_CACHE_WRITE_RESPONSE, | 227 STATE_CACHE_WRITE_RESPONSE, |
| 215 STATE_CACHE_WRITE_RESPONSE_COMPLETE, | 228 STATE_CACHE_WRITE_RESPONSE_COMPLETE, |
| 216 STATE_TRUNCATE_CACHED_DATA, | 229 STATE_TRUNCATE_CACHED_DATA, |
| 217 STATE_TRUNCATE_CACHED_DATA_COMPLETE, | 230 STATE_TRUNCATE_CACHED_DATA_COMPLETE, |
| 218 STATE_TRUNCATE_CACHED_METADATA, | 231 STATE_TRUNCATE_CACHED_METADATA, |
| 219 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, | 232 STATE_TRUNCATE_CACHED_METADATA_COMPLETE, |
| 220 STATE_PARTIAL_HEADERS_RECEIVED, | 233 STATE_PARTIAL_HEADERS_RECEIVED, |
| 221 STATE_CACHE_READ_METADATA, | 234 STATE_CACHE_READ_METADATA, |
| 222 STATE_CACHE_READ_METADATA_COMPLETE, | 235 STATE_CACHE_READ_METADATA_COMPLETE, |
| 236 STATE_HEADERS_PHASE_CANNOT_PROCEED, |
| 237 STATE_FINISH_HEADERS, |
| 238 STATE_FINISH_HEADERS_COMPLETE, |
| 223 | 239 |
| 224 // These states are entered from Read/AddTruncatedFlag. | 240 // These states are entered from Read/AddTruncatedFlag. |
| 225 STATE_NETWORK_READ, | 241 STATE_NETWORK_READ, |
| 226 STATE_NETWORK_READ_COMPLETE, | 242 STATE_NETWORK_READ_COMPLETE, |
| 227 STATE_CACHE_READ_DATA, | 243 STATE_CACHE_READ_DATA, |
| 228 STATE_CACHE_READ_DATA_COMPLETE, | 244 STATE_CACHE_READ_DATA_COMPLETE, |
| 229 STATE_CACHE_WRITE_DATA, | 245 STATE_CACHE_WRITE_DATA, |
| 230 STATE_CACHE_WRITE_DATA_COMPLETE, | 246 STATE_CACHE_WRITE_DATA_COMPLETE, |
| 231 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, | 247 STATE_CACHE_WRITE_TRUNCATED_RESPONSE, |
| 232 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE | 248 STATE_CACHE_WRITE_TRUNCATED_RESPONSE_COMPLETE |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 int DoOverwriteCachedResponse(); | 297 int DoOverwriteCachedResponse(); |
| 282 int DoCacheWriteResponse(); | 298 int DoCacheWriteResponse(); |
| 283 int DoCacheWriteResponseComplete(int result); | 299 int DoCacheWriteResponseComplete(int result); |
| 284 int DoTruncateCachedData(); | 300 int DoTruncateCachedData(); |
| 285 int DoTruncateCachedDataComplete(int result); | 301 int DoTruncateCachedDataComplete(int result); |
| 286 int DoTruncateCachedMetadata(); | 302 int DoTruncateCachedMetadata(); |
| 287 int DoTruncateCachedMetadataComplete(int result); | 303 int DoTruncateCachedMetadataComplete(int result); |
| 288 int DoPartialHeadersReceived(); | 304 int DoPartialHeadersReceived(); |
| 289 int DoCacheReadMetadata(); | 305 int DoCacheReadMetadata(); |
| 290 int DoCacheReadMetadataComplete(int result); | 306 int DoCacheReadMetadataComplete(int result); |
| 307 int DoHeadersPhaseCannotProceed(); |
| 308 int DoFinishHeaders(int result); |
| 309 int DoFinishHeadersComplete(int result); |
| 291 int DoNetworkRead(); | 310 int DoNetworkRead(); |
| 292 int DoNetworkReadComplete(int result); | 311 int DoNetworkReadComplete(int result); |
| 293 int DoCacheReadData(); | 312 int DoCacheReadData(); |
| 294 int DoCacheReadDataComplete(int result); | 313 int DoCacheReadDataComplete(int result); |
| 295 int DoCacheWriteData(int num_bytes); | 314 int DoCacheWriteData(int num_bytes); |
| 296 int DoCacheWriteDataComplete(int result); | 315 int DoCacheWriteDataComplete(int result); |
| 297 int DoCacheWriteTruncatedResponse(); | 316 int DoCacheWriteTruncatedResponse(); |
| 298 int DoCacheWriteTruncatedResponseComplete(int result); | 317 int DoCacheWriteTruncatedResponseComplete(int result); |
| 299 | 318 |
| 300 // Sets request_ and fields derived from it. | 319 // Sets request_ and fields derived from it. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 void SetResponse(const HttpResponseInfo& new_response); | 442 void SetResponse(const HttpResponseInfo& new_response); |
| 424 void SetAuthResponse(const HttpResponseInfo& new_response); | 443 void SetAuthResponse(const HttpResponseInfo& new_response); |
| 425 | 444 |
| 426 void UpdateCacheEntryStatus( | 445 void UpdateCacheEntryStatus( |
| 427 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); | 446 HttpResponseInfo::CacheEntryStatus new_cache_entry_status); |
| 428 | 447 |
| 429 // Sets the response.cache_entry_status to the current cache_entry_status_. | 448 // Sets the response.cache_entry_status to the current cache_entry_status_. |
| 430 void SyncCacheEntryStatusToResponse(); | 449 void SyncCacheEntryStatusToResponse(); |
| 431 void RecordHistograms(); | 450 void RecordHistograms(); |
| 432 | 451 |
| 433 // Called to signal completion of asynchronous IO. | 452 // Called to signal completion of asynchronous IO. Note that this callback is |
| 453 // used in the conventional sense where one layer calls the callback of the |
| 454 // layer above it e.g. this callback gets called from the network transaction |
| 455 // layer. In addition, it is also used for HttpCache layer to let this |
| 456 // transaction know when it is out of a queued state in ActiveEntry and can |
| 457 // continue its processing. |
| 434 void OnIOComplete(int result); | 458 void OnIOComplete(int result); |
| 435 | 459 |
| 436 // When in a DoLoop, use this to set the next state as it verifies that the | 460 // When in a DoLoop, use this to set the next state as it verifies that the |
| 437 // state isn't set twice. | 461 // state isn't set twice. |
| 438 void TransitionToState(State state); | 462 void TransitionToState(State state); |
| 439 | 463 |
| 440 State next_state_; | 464 State next_state_; |
| 441 const HttpRequestInfo* request_; | 465 const HttpRequestInfo* request_; |
| 466 std::string method_; |
| 442 RequestPriority priority_; | 467 RequestPriority priority_; |
| 443 NetLogWithSource net_log_; | 468 NetLogWithSource net_log_; |
| 444 std::unique_ptr<HttpRequestInfo> custom_request_; | 469 std::unique_ptr<HttpRequestInfo> custom_request_; |
| 445 HttpRequestHeaders request_headers_copy_; | 470 HttpRequestHeaders request_headers_copy_; |
| 446 // If extra_headers specified a "if-modified-since" or "if-none-match", | 471 // If extra_headers specified a "if-modified-since" or "if-none-match", |
| 447 // |external_validation_| contains the value of those headers. | 472 // |external_validation_| contains the value of those headers. |
| 448 ValidationHeaders external_validation_; | 473 ValidationHeaders external_validation_; |
| 449 base::WeakPtr<HttpCache> cache_; | 474 base::WeakPtr<HttpCache> cache_; |
| 450 HttpCache::ActiveEntry* entry_; | 475 HttpCache::ActiveEntry* entry_; |
| 451 HttpCache::ActiveEntry* new_entry_; | 476 HttpCache::ActiveEntry* new_entry_; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 // case the transaction does not exist yet. | 532 // case the transaction does not exist yet. |
| 508 WebSocketHandshakeStreamBase::CreateHelper* | 533 WebSocketHandshakeStreamBase::CreateHelper* |
| 509 websocket_handshake_stream_base_create_helper_; | 534 websocket_handshake_stream_base_create_helper_; |
| 510 | 535 |
| 511 BeforeNetworkStartCallback before_network_start_callback_; | 536 BeforeNetworkStartCallback before_network_start_callback_; |
| 512 BeforeHeadersSentCallback before_headers_sent_callback_; | 537 BeforeHeadersSentCallback before_headers_sent_callback_; |
| 513 | 538 |
| 514 // True if the Transaction is currently processing the DoLoop. | 539 // True if the Transaction is currently processing the DoLoop. |
| 515 bool in_do_loop_; | 540 bool in_do_loop_; |
| 516 | 541 |
| 542 RestartInfo restart_info_; |
| 543 |
| 517 base::WeakPtrFactory<Transaction> weak_factory_; | 544 base::WeakPtrFactory<Transaction> weak_factory_; |
| 518 | 545 |
| 519 DISALLOW_COPY_AND_ASSIGN(Transaction); | 546 DISALLOW_COPY_AND_ASSIGN(Transaction); |
| 520 }; | 547 }; |
| 521 | 548 |
| 522 } // namespace net | 549 } // namespace net |
| 523 | 550 |
| 524 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ | 551 #endif // NET_HTTP_HTTP_CACHE_TRANSACTION_H_ |
| OLD | NEW |