diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 01:14:44 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 01:14:44 +0000 |
commit | 0a0fd01fcb4e8a7562df3970e5e3c6932ddb7d81 (patch) | |
tree | e981102c92e154687c4888b588db12ed5b157d21 /net/http | |
parent | aca93f29bcb36a07157714ddf127d13fafc803a7 (diff) | |
download | chromium_src-0a0fd01fcb4e8a7562df3970e5e3c6932ddb7d81.zip chromium_src-0a0fd01fcb4e8a7562df3970e5e3c6932ddb7d81.tar.gz chromium_src-0a0fd01fcb4e8a7562df3970e5e3c6932ddb7d81.tar.bz2 |
Make HttpResponseInfo pickle'able, just moves some code from HttpCache to HttpResponseInfo.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/269012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28363 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache.cc | 126 | ||||
-rw-r--r-- | net/http/http_response_info.cc | 138 | ||||
-rw-r--r-- | net/http/http_response_info.h | 10 |
3 files changed, 150 insertions, 124 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index ffc941c..7fb9703 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -43,35 +43,6 @@ enum { kResponseContentIndex }; -// These values can be bit-wise combined to form the flags field of the -// serialized HttpResponseInfo. -enum { - // The version of the response info used when persisting response info. - RESPONSE_INFO_VERSION = 1, - - // We reserve up to 8 bits for the version number. - RESPONSE_INFO_VERSION_MASK = 0xFF, - - // This bit is set if the response info has a cert at the end. - RESPONSE_INFO_HAS_CERT = 1 << 8, - - // This bit is set if the response info has a security-bits field (security - // strength, in bits, of the SSL connection) at the end. - RESPONSE_INFO_HAS_SECURITY_BITS = 1 << 9, - - // This bit is set if the response info has a cert status at the end. - RESPONSE_INFO_HAS_CERT_STATUS = 1 << 10, - - // This bit is set if the response info has vary header data. - RESPONSE_INFO_HAS_VARY_DATA = 1 << 11, - - // This bit is set if the request was cancelled before completion. - RESPONSE_INFO_TRUNCATED = 1 << 12, - - // TODO(darin): Add other bits to indicate alternate request methods. - // For now, we don't support storing those. -}; - //----------------------------------------------------------------------------- struct HeaderNameAndValue { @@ -1695,61 +1666,7 @@ bool HttpCache::ParseResponseInfo(const char* data, int len, HttpResponseInfo* response_info, bool* response_truncated) { Pickle pickle(data, len); - void* iter = NULL; - - // read flags and verify version - int flags; - if (!pickle.ReadInt(&iter, &flags)) - return false; - int version = flags & RESPONSE_INFO_VERSION_MASK; - if (version != RESPONSE_INFO_VERSION) { - DLOG(ERROR) << "unexpected response info version: " << version; - return false; - } - - // read request-time - int64 time_val; - if (!pickle.ReadInt64(&iter, &time_val)) - return false; - response_info->request_time = Time::FromInternalValue(time_val); - response_info->was_cached = true; // Set status to show cache resurrection. - - // read response-time - if (!pickle.ReadInt64(&iter, &time_val)) - return false; - response_info->response_time = Time::FromInternalValue(time_val); - - // read response-headers - response_info->headers = new HttpResponseHeaders(pickle, &iter); - DCHECK_NE(response_info->headers->response_code(), -1); - - // read ssl-info - if (flags & RESPONSE_INFO_HAS_CERT) { - response_info->ssl_info.cert = - X509Certificate::CreateFromPickle(pickle, &iter); - } - if (flags & RESPONSE_INFO_HAS_CERT_STATUS) { - int cert_status; - if (!pickle.ReadInt(&iter, &cert_status)) - return false; - response_info->ssl_info.cert_status = cert_status; - } - if (flags & RESPONSE_INFO_HAS_SECURITY_BITS) { - int security_bits; - if (!pickle.ReadInt(&iter, &security_bits)) - return false; - response_info->ssl_info.security_bits = security_bits; - } - - // read vary-data - if (flags & RESPONSE_INFO_HAS_VARY_DATA) { - if (!response_info->vary_data.InitFromPickle(pickle, &iter)) - return false; - } - - *response_truncated = (flags & RESPONSE_INFO_TRUNCATED) ? true : false; - - return true; + return response_info->InitFromPickle(pickle, response_truncated); } // static @@ -1774,46 +1691,9 @@ bool HttpCache::WriteResponseInfo(disk_cache::Entry* disk_entry, const HttpResponseInfo* response_info, bool skip_transient_headers, bool response_truncated) { - int flags = RESPONSE_INFO_VERSION; - if (response_info->ssl_info.cert) { - flags |= RESPONSE_INFO_HAS_CERT; - flags |= RESPONSE_INFO_HAS_CERT_STATUS; - } - if (response_info->ssl_info.security_bits != -1) - flags |= RESPONSE_INFO_HAS_SECURITY_BITS; - if (response_info->vary_data.is_valid()) - flags |= RESPONSE_INFO_HAS_VARY_DATA; - if (response_truncated) - flags |= RESPONSE_INFO_TRUNCATED; - Pickle pickle; - pickle.WriteInt(flags); - pickle.WriteInt64(response_info->request_time.ToInternalValue()); - pickle.WriteInt64(response_info->response_time.ToInternalValue()); - - net::HttpResponseHeaders::PersistOptions persist_options = - net::HttpResponseHeaders::PERSIST_RAW; - - if (skip_transient_headers) { - persist_options = - net::HttpResponseHeaders::PERSIST_SANS_COOKIES | - net::HttpResponseHeaders::PERSIST_SANS_CHALLENGES | - net::HttpResponseHeaders::PERSIST_SANS_HOP_BY_HOP | - net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE | - net::HttpResponseHeaders::PERSIST_SANS_RANGES; - } - - response_info->headers->Persist(&pickle, persist_options); - - if (response_info->ssl_info.cert) { - response_info->ssl_info.cert->Persist(&pickle); - pickle.WriteInt(response_info->ssl_info.cert_status); - } - if (response_info->ssl_info.security_bits != -1) - pickle.WriteInt(response_info->ssl_info.security_bits); - - if (response_info->vary_data.is_valid()) - response_info->vary_data.Persist(&pickle); + response_info->Persist( + &pickle, skip_transient_headers, response_truncated); scoped_refptr<WrappedIOBuffer> data = new WrappedIOBuffer( reinterpret_cast<const char*>(pickle.data())); diff --git a/net/http/http_response_info.cc b/net/http/http_response_info.cc index 0db95b5..cf6a363 100644 --- a/net/http/http_response_info.cc +++ b/net/http/http_response_info.cc @@ -4,11 +4,44 @@ #include "net/http/http_response_info.h" -#include "net/base/ssl_cert_request_info.h" +#include "base/logging.h" +#include "base/pickle.h" +#include "base/time.h" #include "net/http/http_response_headers.h" +using base::Time; + namespace net { +// These values can be bit-wise combined to form the flags field of the +// serialized HttpResponseInfo. +enum { + // The version of the response info used when persisting response info. + RESPONSE_INFO_VERSION = 1, + + // We reserve up to 8 bits for the version number. + RESPONSE_INFO_VERSION_MASK = 0xFF, + + // This bit is set if the response info has a cert at the end. + RESPONSE_INFO_HAS_CERT = 1 << 8, + + // This bit is set if the response info has a security-bits field (security + // strength, in bits, of the SSL connection) at the end. + RESPONSE_INFO_HAS_SECURITY_BITS = 1 << 9, + + // This bit is set if the response info has a cert status at the end. + RESPONSE_INFO_HAS_CERT_STATUS = 1 << 10, + + // This bit is set if the response info has vary header data. + RESPONSE_INFO_HAS_VARY_DATA = 1 << 11, + + // This bit is set if the request was cancelled before completion. + RESPONSE_INFO_TRUNCATED = 1 << 12, + + // TODO(darin): Add other bits to indicate alternate request methods. + // For now, we don't support storing those. +}; + HttpResponseInfo::HttpResponseInfo() : was_cached(false) { } @@ -16,4 +49,107 @@ HttpResponseInfo::HttpResponseInfo() HttpResponseInfo::~HttpResponseInfo() { } +bool HttpResponseInfo::InitFromPickle(const Pickle& pickle, + bool* response_truncated) { + void* iter = NULL; + + // read flags and verify version + int flags; + if (!pickle.ReadInt(&iter, &flags)) + return false; + int version = flags & RESPONSE_INFO_VERSION_MASK; + if (version != RESPONSE_INFO_VERSION) { + DLOG(ERROR) << "unexpected response info version: " << version; + return false; + } + + // read request-time + int64 time_val; + if (!pickle.ReadInt64(&iter, &time_val)) + return false; + request_time = Time::FromInternalValue(time_val); + was_cached = true; // Set status to show cache resurrection. + + // read response-time + if (!pickle.ReadInt64(&iter, &time_val)) + return false; + response_time = Time::FromInternalValue(time_val); + + // read response-headers + headers = new HttpResponseHeaders(pickle, &iter); + DCHECK_NE(headers->response_code(), -1); + + // read ssl-info + if (flags & RESPONSE_INFO_HAS_CERT) { + ssl_info.cert = + X509Certificate::CreateFromPickle(pickle, &iter); + } + if (flags & RESPONSE_INFO_HAS_CERT_STATUS) { + int cert_status; + if (!pickle.ReadInt(&iter, &cert_status)) + return false; + ssl_info.cert_status = cert_status; + } + if (flags & RESPONSE_INFO_HAS_SECURITY_BITS) { + int security_bits; + if (!pickle.ReadInt(&iter, &security_bits)) + return false; + ssl_info.security_bits = security_bits; + } + + // read vary-data + if (flags & RESPONSE_INFO_HAS_VARY_DATA) { + if (!vary_data.InitFromPickle(pickle, &iter)) + return false; + } + + *response_truncated = (flags & RESPONSE_INFO_TRUNCATED) ? true : false; + + return true; +} + +void HttpResponseInfo::Persist(Pickle* pickle, + bool skip_transient_headers, + bool response_truncated) const { + int flags = RESPONSE_INFO_VERSION; + if (ssl_info.cert) { + flags |= RESPONSE_INFO_HAS_CERT; + flags |= RESPONSE_INFO_HAS_CERT_STATUS; + } + if (ssl_info.security_bits != -1) + flags |= RESPONSE_INFO_HAS_SECURITY_BITS; + if (vary_data.is_valid()) + flags |= RESPONSE_INFO_HAS_VARY_DATA; + if (response_truncated) + flags |= RESPONSE_INFO_TRUNCATED; + + pickle->WriteInt(flags); + pickle->WriteInt64(request_time.ToInternalValue()); + pickle->WriteInt64(response_time.ToInternalValue()); + + net::HttpResponseHeaders::PersistOptions persist_options = + net::HttpResponseHeaders::PERSIST_RAW; + + if (skip_transient_headers) { + persist_options = + net::HttpResponseHeaders::PERSIST_SANS_COOKIES | + net::HttpResponseHeaders::PERSIST_SANS_CHALLENGES | + net::HttpResponseHeaders::PERSIST_SANS_HOP_BY_HOP | + net::HttpResponseHeaders::PERSIST_SANS_NON_CACHEABLE | + net::HttpResponseHeaders::PERSIST_SANS_RANGES; + } + + headers->Persist(pickle, persist_options); + + if (ssl_info.cert) { + ssl_info.cert->Persist(pickle); + pickle->WriteInt(ssl_info.cert_status); + } + if (ssl_info.security_bits != -1) + pickle->WriteInt(ssl_info.security_bits); + + if (vary_data.is_valid()) + vary_data.Persist(pickle); +} + } // namespace net diff --git a/net/http/http_response_info.h b/net/http/http_response_info.h index ef6343b..432ad87 100644 --- a/net/http/http_response_info.h +++ b/net/http/http_response_info.h @@ -12,6 +12,8 @@ #include "net/http/http_response_headers.h" #include "net/http/http_vary_data.h" +class Pickle; + namespace net { class HttpResponseInfo { @@ -55,6 +57,14 @@ class HttpResponseInfo { // The "Vary" header data for this response. HttpVaryData vary_data; + + // Initializes from the representation stored in the given pickle. + bool InitFromPickle(const Pickle& pickle, bool* response_truncated); + + // Call this method to persist the response info. + void Persist(Pickle* pickle, + bool skip_transient_headers, + bool response_truncated) const; }; } // namespace net |