summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/http/http_cache.cc6
-rw-r--r--net/http/http_cache.h10
-rw-r--r--net/http/http_cache_transaction.cc13
-rw-r--r--net/http/http_cache_transaction.h26
-rw-r--r--net/http/http_network_transaction.h1
-rw-r--r--net/http/http_response_info.h4
-rw-r--r--net/http/http_transaction.h3
-rw-r--r--net/http/http_transaction_unittest.h2
-rw-r--r--net/spdy/spdy_network_transaction.h1
-rw-r--r--net/url_request/url_request.cc5
-rw-r--r--net/url_request/url_request.h7
-rw-r--r--net/url_request/url_request_http_job.cc5
-rw-r--r--net/url_request/url_request_http_job.h1
-rw-r--r--net/url_request/url_request_job.cc4
-rw-r--r--net/url_request/url_request_job.h6
15 files changed, 93 insertions, 1 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 5ae3fd1..cf95c10 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -281,6 +281,12 @@ bool HttpCache::WriteResponseInfo(disk_cache::Entry* disk_entry,
true) == len;
}
+void HttpCache::WriteMetadata(const GURL& url,
+ base::Time expected_response_time, IOBuffer* buf,
+ int buf_len) {
+ // TODO(rvargas): Implement me.
+}
+
// Generate a key that can be used inside the cache.
std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) {
// Strip out the reference, username, and password sections of the URL.
diff --git a/net/http/http_cache.h b/net/http/http_cache.h
index fd0c445..4cce67b 100644
--- a/net/http/http_cache.h
+++ b/net/http/http_cache.h
@@ -27,6 +27,8 @@
#include "net/base/completion_callback.h"
#include "net/http/http_transaction_factory.h"
+class GURL;
+
namespace disk_cache {
class Backend;
class Entry;
@@ -39,6 +41,7 @@ class HttpAuthHandlerFactory;
class HttpNetworkSession;
class HttpRequestInfo;
class HttpResponseInfo;
+class IOBuffer;
class NetworkChangeNotifier;
class ProxyService;
class SSLConfigService;
@@ -132,6 +135,13 @@ class HttpCache : public HttpTransactionFactory,
HttpResponseInfo* response_info,
bool* response_truncated);
+ // Writes |buf_len| bytes of metadata stored in |buf| to the cache entry
+ // referenced by |url|, as long as the entry's |expected_response_time| has
+ // not changed. This method returns without blocking, and the operation will
+ // be performed asynchronously without any completion notification.
+ void WriteMetadata(const GURL& url, base::Time expected_response_time,
+ IOBuffer* buf, int buf_len);
+
// Get/Set the cache's mode.
void set_mode(Mode value) { mode_ = value; }
Mode mode() { return mode_; }
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index e622b6f..528a6b7 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -356,6 +356,9 @@ int HttpCache::Transaction::Read(IOBuffer* buf, int buf_len,
return rv;
}
+void HttpCache::Transaction::StopCaching() {
+}
+
const HttpResponseInfo* HttpCache::Transaction::GetResponseInfo() const {
// Null headers means we encountered an error or haven't a response yet
if (auth_response_.headers)
@@ -378,6 +381,16 @@ uint64 HttpCache::Transaction::GetUploadProgress() const {
return final_upload_progress_;
}
+int HttpCache::Transaction::ReadMetadata(IOBuffer* buf, int buf_len,
+ CompletionCallback* callback) {
+ return ERR_NOT_IMPLEMENTED;
+}
+
+int HttpCache::Transaction::WriteMetadata(IOBuffer* buf, int buf_len,
+ CompletionCallback* callback) {
+ return ERR_NOT_IMPLEMENTED;
+}
+
int HttpCache::Transaction::AddToEntry() {
next_state_ = STATE_INIT_ENTRY;
cache_pending_ = false;
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h
index 9608093..7ea1ff0 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -34,6 +34,7 @@ class HttpCache::Transaction : public HttpTransaction {
CompletionCallback* callback);
virtual bool IsReadyToRestartForAuth();
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual void StopCaching();
virtual const HttpResponseInfo* GetResponseInfo() const;
virtual LoadState GetLoadState() const;
virtual uint64 GetUploadProgress(void) const;
@@ -71,6 +72,31 @@ class HttpCache::Transaction : public HttpTransaction {
const std::string& key() const { return cache_key_; }
+ // Reads up to |buf_len| bytes of meta-data into the provided buffer |buf|,
+ // from the HTTP cache entry that backs this transaction (if any).
+ // Returns the number of bytes actually read, or a net error code. If the
+ // operation cannot complete immediately, returns ERR_IO_PENDING, grabs a
+ // reference to the buffer (until completion), and notifies the caller using
+ // the provided |callback| when the operatiopn finishes.
+ int ReadMetadata(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+
+ // Writes |buf_len| bytes of meta-data from the provided buffer |buf|. to the
+ // HTTP cache entry that backs this transaction (if any).
+ // Returns the number of bytes actually written, or a net error code. If the
+ // operation cannot complete immediately, returns ERR_IO_PENDING, grabs a
+ // reference to the buffer (until completion), and notifies the caller using
+ // the provided |callback| when the operatiopn finishes.
+ //
+ // The first time this method is called for a given transaction, previous
+ // meta-data will be overwritten with the provided data, and subsequent
+ // invocations will keep appending to the cached entry.
+ //
+ // In order to guarantee that the metadata is set to the correct entry, the
+ // response (or response info) must be evaluated by the caller, for instance
+ // to make sure that the response_time is as expected, before calling this
+ // method.
+ int WriteMetadata(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+
// This transaction is being deleted and we are not done writing to the cache.
// We need to indicate that the response data was truncated. Returns true on
// success.
diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h
index 2269c28..756a413 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -58,6 +58,7 @@ class HttpNetworkTransaction : public HttpTransaction {
}
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual void StopCaching() {}
virtual const HttpResponseInfo* GetResponseInfo() const;
virtual LoadState GetLoadState() const;
virtual uint64 GetUploadProgress() const;
diff --git a/net/http/http_response_info.h b/net/http/http_response_info.h
index a3e0123f..201595c 100644
--- a/net/http/http_response_info.h
+++ b/net/http/http_response_info.h
@@ -7,6 +7,7 @@
#include "base/time.h"
#include "net/base/auth.h"
+#include "net/base/io_buffer.h"
#include "net/base/ssl_cert_request_info.h"
#include "net/base/ssl_info.h"
#include "net/http/http_response_headers.h"
@@ -61,6 +62,9 @@ class HttpResponseInfo {
// The "Vary" header data for this response.
HttpVaryData vary_data;
+ // Any metadata asociated with this resource's cached data.
+ scoped_refptr<IOBufferWithSize> metadata;
+
// Initializes from the representation stored in the given pickle.
bool InitFromPickle(const Pickle& pickle, bool* response_truncated);
diff --git a/net/http/http_transaction.h b/net/http/http_transaction.h
index 2f8ddba..8a0d25f 100644
--- a/net/http/http_transaction.h
+++ b/net/http/http_transaction.h
@@ -91,6 +91,9 @@ class HttpTransaction {
virtual int Read(IOBuffer* buf, int buf_len,
CompletionCallback* callback) = 0;
+ // Stops further caching of this request by the HTTP cache, if there is any.
+ virtual void StopCaching() = 0;
+
// Returns the response info for this transaction or NULL if the response
// info is not available.
virtual const HttpResponseInfo* GetResponseInfo() const = 0;
diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h
index a884a07..3499da4 100644
--- a/net/http/http_transaction_unittest.h
+++ b/net/http/http_transaction_unittest.h
@@ -283,6 +283,8 @@ class MockNetworkTransaction : public net::HttpTransaction {
return net::ERR_IO_PENDING;
}
+ virtual void StopCaching() {}
+
virtual const net::HttpResponseInfo* GetResponseInfo() const {
return &response_;
}
diff --git a/net/spdy/spdy_network_transaction.h b/net/spdy/spdy_network_transaction.h
index 28251ab..a9087e7 100644
--- a/net/spdy/spdy_network_transaction.h
+++ b/net/spdy/spdy_network_transaction.h
@@ -46,6 +46,7 @@ class SpdyNetworkTransaction : public HttpTransaction {
CompletionCallback* callback);
virtual bool IsReadyToRestartForAuth() { return false; }
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
+ virtual void StopCaching() {}
virtual const HttpResponseInfo* GetResponseInfo() const;
virtual LoadState GetLoadState() const;
virtual uint64 GetUploadProgress() const;
diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
index 7a09123..5c4566e 100644
--- a/net/url_request/url_request.cc
+++ b/net/url_request/url_request.cc
@@ -347,6 +347,11 @@ bool URLRequest::Read(net::IOBuffer* dest, int dest_size, int *bytes_read) {
return job_->Read(dest, dest_size, bytes_read);
}
+void URLRequest::StopCaching() {
+ DCHECK(job_);
+ job_->StopCaching();
+}
+
void URLRequest::ReceivedRedirect(const GURL& location, bool* defer_redirect) {
URLRequestJob* job = GetJobManager()->MaybeInterceptRedirect(this, location);
if (job) {
diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h
index b420cf8..c8bc2bf 100644
--- a/net/url_request/url_request.h
+++ b/net/url_request/url_request.h
@@ -464,6 +464,13 @@ class URLRequest {
// will be set to an error.
bool Read(net::IOBuffer* buf, int max_bytes, int *bytes_read);
+ // If this request is being cached by the HTTP cache, stop subsequent caching.
+ // Note that this method has no effect on other (simultaneous or not) requests
+ // for the same resource. The typical example is a request that results in
+ // the data being stored to disk (downloaded instead of rendered) so we don't
+ // want to store it twice.
+ void StopCaching();
+
// This method may be called to follow a redirect that was deferred in
// response to an OnReceivedRedirect call.
void FollowDeferredRedirect();
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index ef17774..1b11817 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -429,6 +429,11 @@ bool URLRequestHttpJob::ReadRawData(net::IOBuffer* buf, int buf_size,
return false;
}
+void URLRequestHttpJob::StopCaching() {
+ if (transaction_.get())
+ transaction_->StopCaching();
+}
+
void URLRequestHttpJob::OnCanGetCookiesCompleted(int policy) {
// If the request was destroyed, then there is no more work to do.
if (request_ && request_->delegate()) {
diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h
index e00e3c4..4233c6e 100644
--- a/net/url_request/url_request_http_job.h
+++ b/net/url_request/url_request_http_job.h
@@ -55,6 +55,7 @@ class URLRequestHttpJob : public URLRequestJob {
virtual void ContinueWithCertificate(net::X509Certificate* client_cert);
virtual void ContinueDespiteLastError();
virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read);
+ virtual void StopCaching();
// Shadows URLRequestJob's version of this method so we can grab cookies.
void NotifyHeadersComplete();
diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc
index 63611fd..75f357b 100644
--- a/net/url_request/url_request_job.cc
+++ b/net/url_request/url_request_job.cc
@@ -190,6 +190,10 @@ bool URLRequestJob::Read(net::IOBuffer* buf, int buf_size, int *bytes_read) {
return rv;
}
+void URLRequestJob::StopCaching() {
+ // Nothing to do here.
+}
+
bool URLRequestJob::ReadRawDataForFilter(int *bytes_read) {
bool rv = false;
diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h
index 2aeb8ff..0131428 100644
--- a/net/url_request/url_request_job.h
+++ b/net/url_request/url_request_job.h
@@ -90,7 +90,11 @@ class URLRequestJob : public base::RefCountedThreadSafe<URLRequestJob>,
// bytes read, 0 when there is no more data, or -1 if there was an error.
// This is just the backend for URLRequest::Read, see that function for more
// info.
- bool Read(net::IOBuffer* buf, int buf_size, int *bytes_read);
+ bool Read(net::IOBuffer* buf, int buf_size, int* bytes_read);
+
+ // Stops further caching of this request, if any. For more info, see
+ // URLRequest::StopCaching().
+ virtual void StopCaching();
// Called to fetch the current load state for the job.
virtual net::LoadState GetLoadState() const { return net::LOAD_STATE_IDLE; }