http_cache_transaction.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file declares HttpCache::Transaction, a private class of HttpCache so
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// it should only be included by http_cache.cc
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_HTTP_HTTP_CACHE_TRANSACTION_H_
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_HTTP_HTTP_CACHE_TRANSACTION_H_
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/time.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/completion_callback.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_log.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/request_priority.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_cache.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_response_info.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_request_headers.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_transaction.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PartialData;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct HttpRequestInfo;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HttpTransactionDelegate;
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct LoadTimingInfo;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is the transaction that is returned by the HttpCache transaction
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// factory.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HttpCache::Transaction : public HttpTransaction {
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The transaction has the following modes, which apply to how it may access
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // its cache entry.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  o If the mode of the transaction is NONE, then it is in "pass through"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    mode and all methods just forward to the inner network transaction.
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  o If the mode of the transaction is only READ, then it may only read from
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    the cache entry.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  o If the mode of the transaction is only WRITE, then it may only write to
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    the cache entry.
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  o If the mode of the transaction is READ_WRITE, then the transaction may
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    optionally modify the cache entry (e.g., possibly corresponding to
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    cache validation).
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  o If the mode of the transaction is UPDATE, then the transaction may
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    update existing cache entries, but will never create a new entry or
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    respond using the entry read from the cache.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Mode {
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NONE            = 0,
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    READ_META       = 1 << 0,
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    READ_DATA       = 1 << 1,
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    READ            = READ_META | READ_DATA,
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WRITE           = 1 << 2,
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    READ_WRITE      = READ | WRITE,
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UPDATE          = READ_META | WRITE,  // READ_WRITE & ~READ_DATA
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Transaction(RequestPriority priority,
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              HttpCache* cache,
64c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)              HttpTransactionDelegate* transaction_delegate);
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~Transaction();
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Mode mode() const { return mode_; }
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const std::string& key() const { return cache_key_; }
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Writes |buf_len| bytes of meta-data from the provided buffer |buf|. to the
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HTTP cache entry that backs this transaction (if any).
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the number of bytes actually written, or a net error code. If the
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // operation cannot complete immediately, returns ERR_IO_PENDING, grabs a
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // reference to the buffer (until completion), and notifies the caller using
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the provided |callback| when the operation finishes.
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The first time this method is called for a given transaction, previous
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // meta-data will be overwritten with the provided data, and subsequent
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // invocations will keep appending to the cached entry.
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // In order to guarantee that the metadata is set to the correct entry, the
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // response (or response info) must be evaluated by the caller, for instance
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to make sure that the response_time is as expected, before calling this
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // method.
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int WriteMetadata(IOBuffer* buf,
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    int buf_len,
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const CompletionCallback& callback);
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This transaction is being deleted and we are not done writing to the cache.
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We need to indicate that the response data was truncated.  Returns true on
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // success. Keep in mind that this operation may have side effects, such as
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // deleting the active entry.
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool AddTruncatedFlag();
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpCache::ActiveEntry* entry() { return entry_; }
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the LoadState of the writer transaction of a given ActiveEntry. In
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // other words, returns the LoadState of this transaction without asking the
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // http cache, because this transaction should be the one currently writing
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to the cache entry.
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  LoadState GetWriterLoadState() const;
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const CompletionCallback& io_callback() { return io_callback_; }
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const BoundNetLog& net_log() const;
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // HttpTransaction methods:
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual int Start(const HttpRequestInfo* request_info,
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    const CompletionCallback& callback,
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                    const BoundNetLog& net_log) OVERRIDE;
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int RestartIgnoringLastError(
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CompletionCallback& callback) OVERRIDE;
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int RestartWithCertificate(
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      X509Certificate* client_cert,
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CompletionCallback& callback) OVERRIDE;
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int RestartWithAuth(const AuthCredentials& credentials,
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              const CompletionCallback& callback) OVERRIDE;
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsReadyToRestartForAuth() OVERRIDE;
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int Read(IOBuffer* buf,
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   int buf_len,
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   const CompletionCallback& callback) OVERRIDE;
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StopCaching() OVERRIDE;
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DoneReading() OVERRIDE;
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual const HttpResponseInfo* GetResponseInfo() const OVERRIDE;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual LoadState GetLoadState() const OVERRIDE;
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual UploadProgress GetUploadProgress(void) const OVERRIDE;
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool GetLoadTimingInfo(
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      LoadTimingInfo* load_timing_info) const OVERRIDE;
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetPriority(RequestPriority priority) OVERRIDE;
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const size_t kNumValidationHeaders = 2;
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper struct to pair a header name with its value, for
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // headers used to validate cache entries.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct ValidationHeaders {
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ValidationHeaders() : initialized(false) {}
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::string values[kNumValidationHeaders];
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool initialized;
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum State {
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_NONE,
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_GET_BACKEND,
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_GET_BACKEND_COMPLETE,
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_SEND_REQUEST,
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_SEND_REQUEST_COMPLETE,
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_SUCCESSFUL_SEND_REQUEST,
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_NETWORK_READ,
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_NETWORK_READ_COMPLETE,
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_INIT_ENTRY,
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_OPEN_ENTRY,
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_OPEN_ENTRY_COMPLETE,
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CREATE_ENTRY,
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CREATE_ENTRY_COMPLETE,
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_DOOM_ENTRY,
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_DOOM_ENTRY_COMPLETE,
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_ADD_TO_ENTRY,
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_ADD_TO_ENTRY_COMPLETE,
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    STATE_ADD_TO_ENTRY_COMPLETE_AFTER_DELAY,
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_START_PARTIAL_CACHE_VALIDATION,
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_COMPLETE_PARTIAL_CACHE_VALIDATION,
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_UPDATE_CACHED_RESPONSE,
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_UPDATE_CACHED_RESPONSE_COMPLETE,
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_OVERWRITE_CACHED_RESPONSE,
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_TRUNCATE_CACHED_DATA,
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_TRUNCATE_CACHED_DATA_COMPLETE,
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_TRUNCATE_CACHED_METADATA,
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_TRUNCATE_CACHED_METADATA_COMPLETE,
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_PARTIAL_HEADERS_RECEIVED,
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_READ_RESPONSE,
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_READ_RESPONSE_COMPLETE,
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_WRITE_RESPONSE,
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_WRITE_TRUNCATED_RESPONSE,
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_WRITE_RESPONSE_COMPLETE,
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_READ_METADATA,
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_READ_METADATA_COMPLETE,
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_QUERY_DATA,
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_QUERY_DATA_COMPLETE,
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_READ_DATA,
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_READ_DATA_COMPLETE,
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_WRITE_DATA,
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_CACHE_WRITE_DATA_COMPLETE
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used for categorizing transactions for reporting in histograms. Patterns
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cover relatively common use cases being measured and considered for
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // optimization. Many use cases that are more complex or uncommon are binned
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // as PATTERN_NOT_COVERED, and details are not reported.
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // NOTE: This enumeration is used in histograms, so please do not add entries
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // in the middle.
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum TransactionPattern {
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PATTERN_UNDEFINED,
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PATTERN_NOT_COVERED,
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PATTERN_ENTRY_NOT_CACHED,
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PATTERN_ENTRY_USED,
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PATTERN_ENTRY_VALIDATED,
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    PATTERN_ENTRY_UPDATED,
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    PATTERN_ENTRY_CANT_CONDITIONALIZE,
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    PATTERN_MAX,
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This is a helper function used to trigger a completion callback.  It may
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // only be called if callback_ is non-null.
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DoCallback(int rv);
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This will trigger the completion callback if appropriate.
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int HandleResult(int rv);
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Runs the state transition loop.
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoLoop(int result);
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Each of these methods corresponds to a State value.  If there is an
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // argument, the value corresponds to the return of the previous state or
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // corresponding callback.
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoGetBackend();
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoGetBackendComplete(int result);
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoSendRequest();
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoSendRequestComplete(int result);
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoSuccessfulSendRequest();
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoNetworkRead();
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoNetworkReadComplete(int result);
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoInitEntry();
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoOpenEntry();
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoOpenEntryComplete(int result);
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCreateEntry();
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCreateEntryComplete(int result);
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoDoomEntry();
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoDoomEntryComplete(int result);
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoAddToEntry();
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoAddToEntryComplete(int result);
2332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int DoAddToEntryCompleteAfterDelay(int result);
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoStartPartialCacheValidation();
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCompletePartialCacheValidation(int result);
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoUpdateCachedResponse();
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoUpdateCachedResponseComplete(int result);
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoOverwriteCachedResponse();
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoTruncateCachedData();
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoTruncateCachedDataComplete(int result);
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoTruncateCachedMetadata();
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoTruncateCachedMetadataComplete(int result);
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoPartialHeadersReceived();
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheReadResponse();
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheReadResponseComplete(int result);
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheWriteResponse();
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheWriteTruncatedResponse();
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheWriteResponseComplete(int result);
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheReadMetadata();
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheReadMetadataComplete(int result);
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheQueryData();
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheQueryDataComplete(int result);
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheReadData();
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheReadDataComplete(int result);
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheWriteData(int num_bytes);
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoCacheWriteDataComplete(int result);
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets request_ and fields derived from it.
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetRequest(const BoundNetLog& net_log, const HttpRequestInfo* request);
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the request should be handled exclusively by the network
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // layer (skipping the cache entirely).
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ShouldPassThrough();
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to begin reading from the cache.  Returns network error code.
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int BeginCacheRead();
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to begin validating the cache entry.  Returns network error code.
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int BeginCacheValidation();
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to begin validating an entry that stores partial content.  Returns
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a network error code.
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int BeginPartialCacheValidation();
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Validates the entry headers against the requested range and continues with
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the validation of the rest of the entry.  Returns a network error code.
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int ValidateEntryHeadersAndContinue();
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to start requests which were given an "if-modified-since" or
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // "if-none-match" validation header by the caller (NOT when the request was
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // conditionalized internally in response to LOAD_VALIDATE_CACHE).
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a network error code.
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int BeginExternallyConditionalizedRequest();
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to restart a network transaction after an error.  Returns network
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // error code.
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int RestartNetworkRequest();
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to restart a network transaction with a client certificate.
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns network error code.
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int RestartNetworkRequestWithCertificate(X509Certificate* client_cert);
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to restart a network transaction with authentication credentials.
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns network error code.
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int RestartNetworkRequestWithAuth(const AuthCredentials& credentials);
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to determine if we need to validate the cache entry before using it.
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool RequiresValidation();
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to make the request conditional (to ask the server if the cached
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // copy is valid).  Returns true if able to make the request conditional.
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ConditionalizeRequest();
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Makes sure that a 206 response is expected.  Returns true on success.
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On success, handling_206_ will be set to true if we are processing a
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // partial entry.
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool ValidatePartialResponse();
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Handles a response validation error by bypassing the cache.
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void IgnoreRangeRequest();
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Changes the response code of a range request to be 416 (Requested range not
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // satisfiable).
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void FailRangeRequest();
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Setups the transaction for reading from the cache entry.
3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int SetupEntryForRead();
3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads data from the network.
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int ReadFromNetwork(IOBuffer* data, int data_len);
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Reads data from the cache entry.
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int ReadFromEntry(IOBuffer* data, int data_len);
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to write data to the cache entry.  If the write fails, then the
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cache entry is destroyed.  Future calls to this function will just do
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // nothing without side-effect.  Returns a network error code.
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int WriteToEntry(int index, int offset, IOBuffer* data, int data_len,
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                   const CompletionCallback& callback);
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to write response_ to the cache entry. |truncated| indicates if the
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // entry should be marked as incomplete.
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int WriteResponseInfoToEntry(bool truncated);
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to append response data to the cache entry.  Returns a network error
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // code.
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int AppendResponseDataToEntry(IOBuffer* data, int data_len,
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                const CompletionCallback& callback);
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when we are done writing to the cache entry.
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DoneWritingToEntry(bool success);
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns an error to signal the caller that the current read failed. The
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // current operation |result| is also logged. If |restart| is true, the
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // transaction should be restarted.
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int OnCacheReadError(int result, bool restart);
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Deletes the current partial cache entry (sparse), and optionally removes
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the control object (partial_).
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DoomPartialEntry(bool delete_object);
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Performs the needed work after receiving data from the network, when
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // working with range requests.
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoPartialNetworkReadCompleted(int result);
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Performs the needed work after receiving data from the cache, when
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // working with range requests.
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoPartialCacheReadCompleted(int result);
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Restarts this transaction after deleting the cached data. It is meant to
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // be used when the current request cannot be fulfilled due to conflicts
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // between the byte range request and the cached entry.
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DoRestartPartialRequest();
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if we should bother attempting to resume this request if it
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is aborted while in progress. If |has_data| is true, the size of the stored
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // data is considered for the result.
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanResume(bool has_data);
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to signal completion of asynchronous IO.
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void OnIOComplete(int result);
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ReportCacheActionStart();
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ReportCacheActionFinish();
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ReportNetworkActionStart();
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ReportNetworkActionFinish();
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UpdateTransactionPattern(TransactionPattern new_transaction_pattern);
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RecordHistograms();
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Resets cache_io_start_ to the current time, if |return_value| is
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ERR_IO_PENDING.
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns |return_value|.
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int ResetCacheIOStart(int return_value);
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void ScheduleDelayedLoop(base::TimeDelta delay, int result);
3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void RunDelayedLoop(base::TimeTicks delay_start_time,
3872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                      base::TimeDelta intended_delay, int result);
3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
38990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Resets |network_trans_|, which must be non-NULL.  Also updates
39090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // |old_network_trans_load_timing_|, which must be NULL when this is called.
39190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void ResetNetworkTransaction();
39290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  State next_state_;
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const HttpRequestInfo* request_;
3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RequestPriority priority_;
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BoundNetLog net_log_;
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<HttpRequestInfo> custom_request_;
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpRequestHeaders request_headers_copy_;
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If extra_headers specified a "if-modified-since" or "if-none-match",
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |external_validation_| contains the value of those headers.
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ValidationHeaders external_validation_;
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::WeakPtr<HttpCache> cache_;
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpCache::ActiveEntry* entry_;
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpCache::ActiveEntry* new_entry_;
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<HttpTransaction> network_trans_;
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CompletionCallback callback_;  // Consumer's callback.
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpResponseInfo response_;
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpResponseInfo auth_response_;
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const HttpResponseInfo* new_response_;
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string cache_key_;
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Mode mode_;
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  State target_state_;
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool reading_;  // We are already reading.
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool invalid_range_;  // We may bypass the cache for this request.
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool truncated_;  // We don't have all the response data.
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool is_sparse_;  // The data is stored in sparse byte ranges.
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool range_requested_;  // The user requested a byte range.
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool handling_206_;  // We must deal with this 206 response.
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool cache_pending_;  // We are waiting for the HttpCache.
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool done_reading_;
4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool vary_mismatch_;  // The request doesn't match the stored vary data.
4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool couldnt_conditionalize_request_;
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<IOBuffer> read_buf_;
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int io_buf_len_;
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int read_offset_;
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int effective_load_flags_;
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int write_len_;
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<PartialData> partial_;  // We are dealing with range requests.
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  UploadProgress final_upload_progress_;
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::WeakPtrFactory<Transaction> weak_factory_;
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CompletionCallback io_callback_;
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Members used to track data for histograms.
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TransactionPattern transaction_pattern_;
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeTicks entry_lock_waiting_since_;
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeTicks first_cache_access_since_;
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeTicks send_request_since_;
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For sensitivity analysis (field trials emulating longer cache IO times),
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the time at which a cache IO action has started, or base::TimeTicks()
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // if no cache IO action is currently in progress.
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::TimeTicks cache_io_start_;
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // For OpenEntry and CreateEntry, if sensitivity analysis would mandate
4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // a delay on return, we must defer that delay until AddToEntry has been
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // called, to avoid a race condition on the address returned.
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeDelta deferred_cache_sensitivity_delay_;
4482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool defer_cache_sensitivity_delay_;
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For sensitivity analysis, the simulated increase in cache service times,
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // in percent.
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int sensitivity_analysis_percent_increase_;
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HttpTransactionDelegate* transaction_delegate_;
45590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
45690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Load timing information for the last network request, if any.  Set in the
45790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // 304 and 206 response cases, as the network transaction may be destroyed
45890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // before the caller requests load timing information.
45990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<LoadTimingInfo> old_network_trans_load_timing_;
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_HTTP_HTTP_CACHE_TRANSACTION_H_
465