summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-12 17:52:47 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-12 17:52:47 +0000
commit5c04f72431dc072fded17be7a9620b724f314821 (patch)
treeb1aad621601276eaca1bd018454b29e9b9a9db52 /net/http
parent071162a96601d92c90feb60f75b74af07ec4934a (diff)
downloadchromium_src-5c04f72431dc072fded17be7a9620b724f314821.zip
chromium_src-5c04f72431dc072fded17be7a9620b724f314821.tar.gz
chromium_src-5c04f72431dc072fded17be7a9620b724f314821.tar.bz2
net: Notify the http job and cache transaction about a filter
completing the request (returning 0 bytes from a read). BUG=91898 TEST=net_unittests Review URL: http://codereview.chromium.org/7569027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96576 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_cache_transaction.cc9
-rw-r--r--net/http/http_cache_transaction.h1
-rw-r--r--net/http/http_cache_unittest.cc34
-rw-r--r--net/http/http_network_transaction.h1
-rw-r--r--net/http/http_transaction.h6
-rw-r--r--net/http/http_transaction_unittest.cc20
-rw-r--r--net/http/http_transaction_unittest.h13
7 files changed, 78 insertions, 6 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index 1e83f06..4b51cd5 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -365,6 +365,15 @@ int HttpCache::Transaction::Read(IOBuffer* buf, int buf_len,
void HttpCache::Transaction::StopCaching() {
}
+void HttpCache::Transaction::DoneReading() {
+ if (cache_ && entry_) {
+ DCHECK(reading_);
+ DCHECK_NE(mode_, UPDATE);
+ if (mode_ & WRITE)
+ DoneWritingToEntry(true);
+ }
+}
+
const HttpResponseInfo* HttpCache::Transaction::GetResponseInfo() const {
// Null headers means we encountered an error or haven't a response yet
if (auth_response_.headers)
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h
index 31dec94..ce6e79e 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -109,6 +109,7 @@ class HttpCache::Transaction : public HttpTransaction {
virtual bool IsReadyToRestartForAuth();
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual void StopCaching();
+ virtual void DoneReading();
virtual const HttpResponseInfo* GetResponseInfo() const;
virtual LoadState GetLoadState() const;
virtual uint64 GetUploadProgress(void) const;
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index b467dc5..9fbd49e 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -5101,3 +5101,37 @@ TEST(HttpCache, ReadMetadata) {
EXPECT_EQ(4, cache.disk_cache()->open_count());
EXPECT_EQ(1, cache.disk_cache()->create_count());
}
+
+// Tests that we don't mark entries as truncated when a filter detects the end
+// of the stream.
+TEST(HttpCache, FilterCompletion) {
+ MockHttpCache cache;
+ TestCompletionCallback callback;
+
+ {
+ scoped_ptr<net::HttpTransaction> trans;
+ int rv = cache.http_cache()->CreateTransaction(&trans);
+ EXPECT_EQ(net::OK, rv);
+
+ MockHttpRequest request(kSimpleGET_Transaction);
+ rv = trans->Start(&request, &callback, net::BoundNetLog());
+ EXPECT_EQ(net::OK, callback.GetResult(rv));
+
+ scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256));
+ rv = trans->Read(buf, 256, &callback);
+ EXPECT_GT(callback.GetResult(rv), 0);
+
+ // Now make sure that the entry is preserved.
+ trans->DoneReading();
+ }
+
+ // Make sure that teh ActiveEntry is gone.
+ MessageLoop::current()->RunAllPending();
+
+ // Read from the cache.
+ RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
+
+ EXPECT_EQ(1, cache.network_layer()->transaction_count());
+ EXPECT_EQ(1, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+}
diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h
index 6f6ba77..639d17d 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -54,6 +54,7 @@ class NET_EXPORT_PRIVATE HttpNetworkTransaction
virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual void StopCaching() {}
+ virtual void DoneReading() {}
virtual const HttpResponseInfo* GetResponseInfo() const;
virtual LoadState GetLoadState() const;
virtual uint64 GetUploadProgress() const;
diff --git a/net/http/http_transaction.h b/net/http/http_transaction.h
index 400c91f..3e702ea 100644
--- a/net/http/http_transaction.h
+++ b/net/http/http_transaction.h
@@ -96,6 +96,12 @@ class NET_EXPORT_PRIVATE HttpTransaction {
// Stops further caching of this request by the HTTP cache, if there is any.
virtual void StopCaching() = 0;
+ // Called to tell the transaction that we have successfully reached the end
+ // of the stream. This is equivalent to performing an extra Read() at the end
+ // that should return 0 bytes. This method should not be called if the
+ // transaction is busy processing a previous operation (like a pending Read).
+ virtual void DoneReading() = 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.cc b/net/http/http_transaction_unittest.cc
index cec930d..38347e0 100644
--- a/net/http/http_transaction_unittest.cc
+++ b/net/http/http_transaction_unittest.cc
@@ -212,8 +212,10 @@ void TestTransactionConsumer::RunWithParams(const Tuple1<int>& params) {
}
-MockNetworkTransaction::MockNetworkTransaction() :
- ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), data_cursor_(0) {
+MockNetworkTransaction::MockNetworkTransaction(MockNetworkLayer* factory)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
+ data_cursor_(0),
+ transaction_factory_(factory->AsWeakPtr()) {
}
MockNetworkTransaction::~MockNetworkTransaction() {}
@@ -295,6 +297,11 @@ int MockNetworkTransaction::Read(net::IOBuffer* buf, int buf_len,
void MockNetworkTransaction::StopCaching() {}
+void MockNetworkTransaction::DoneReading() {
+ if (transaction_factory_)
+ transaction_factory_->TransactionDoneReading();
+}
+
const net::HttpResponseInfo* MockNetworkTransaction::GetResponseInfo() const {
return &response_;
}
@@ -320,14 +327,19 @@ void MockNetworkTransaction::RunCallback(net::CompletionCallback* callback,
callback->Run(result);
}
-MockNetworkLayer::MockNetworkLayer() : transaction_count_(0) {}
+MockNetworkLayer::MockNetworkLayer()
+ : transaction_count_(0), done_reading_called_(false) {}
MockNetworkLayer::~MockNetworkLayer() {}
+void MockNetworkLayer::TransactionDoneReading() {
+ done_reading_called_ = true;
+}
+
int MockNetworkLayer::CreateTransaction(
scoped_ptr<net::HttpTransaction>* trans) {
transaction_count_++;
- trans->reset(new MockNetworkTransaction());
+ trans->reset(new MockNetworkTransaction(this));
return net::OK;
}
diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h
index 589133c..714f263 100644
--- a/net/http/http_transaction_unittest.h
+++ b/net/http/http_transaction_unittest.h
@@ -147,13 +147,15 @@ class TestTransactionConsumer : public CallbackRunner< Tuple1<int> > {
//-----------------------------------------------------------------------------
// mock network layer
+class MockNetworkLayer;
+
// This transaction class inspects the available set of mock transactions to
// find data for the request URL. It supports IO operations that complete
// synchronously or asynchronously to help exercise different code paths in the
// HttpCache implementation.
class MockNetworkTransaction : public net::HttpTransaction {
public:
- MockNetworkTransaction();
+ explicit MockNetworkTransaction(MockNetworkLayer* factory);
virtual ~MockNetworkTransaction();
virtual int Start(const net::HttpRequestInfo* request,
@@ -176,6 +178,8 @@ class MockNetworkTransaction : public net::HttpTransaction {
virtual void StopCaching();
+ virtual void DoneReading();
+
virtual const net::HttpResponseInfo* GetResponseInfo() const;
virtual net::LoadState GetLoadState() const;
@@ -191,14 +195,18 @@ class MockNetworkTransaction : public net::HttpTransaction {
std::string data_;
int data_cursor_;
int test_mode_;
+ base::WeakPtr<MockNetworkLayer> transaction_factory_;
};
-class MockNetworkLayer : public net::HttpTransactionFactory {
+class MockNetworkLayer : public net::HttpTransactionFactory,
+ public base::SupportsWeakPtr<MockNetworkLayer> {
public:
MockNetworkLayer();
virtual ~MockNetworkLayer();
int transaction_count() const { return transaction_count_; }
+ bool done_reading_called() const { return done_reading_called_; }
+ void TransactionDoneReading();
// net::HttpTransactionFactory:
virtual int CreateTransaction(scoped_ptr<net::HttpTransaction>* trans);
@@ -207,6 +215,7 @@ class MockNetworkLayer : public net::HttpTransactionFactory {
private:
int transaction_count_;
+ bool done_reading_called_;
};
//-----------------------------------------------------------------------------