summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 07:14:15 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-05 07:14:15 +0000
commit98179700f91d242ce6a4edb5f0865e12d3a662c6 (patch)
treed0aba9403ec40c447e4adeecf030d9c37e6952fa /net
parentd96700fe4b8aa342d48c47aa3b1765760738bb47 (diff)
downloadchromium_src-98179700f91d242ce6a4edb5f0865e12d3a662c6.zip
chromium_src-98179700f91d242ce6a4edb5f0865e12d3a662c6.tar.gz
chromium_src-98179700f91d242ce6a4edb5f0865e12d3a662c6.tar.bz2
Add two small features to the HttpCache for benchmarking/debugging.
The first exposes a method to close all idle sockets. This allows me to create benchmark tests in the app which can close connections before starting the test for better simulations. The second change is to expose cache modes for cache disabled and cache bypassed. DISABLE sets the LOAD_DISABLE_CACHE on every request; BYPASS sets the LOAD_BYPASS_CACHE on every request. TEST=http_cache_unittest.cc BUG=6754 Review URL: http://codereview.chromium.org/119189 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17720 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_cache.cc38
-rw-r--r--net/http/http_cache.h8
-rw-r--r--net/http/http_cache_unittest.cc20
3 files changed, 55 insertions, 11 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index 48178a6..497e141 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -22,6 +22,7 @@
#include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache.h"
#include "net/http/http_network_layer.h"
+#include "net/http/http_network_session.h"
#include "net/http/http_request_info.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
@@ -576,16 +577,23 @@ void HttpCache::Transaction::SetRequest(const HttpRequestInfo* request) {
request_ = request;
effective_load_flags_ = request_->load_flags;
- // When in playback mode, we want to load exclusively from the cache.
- if (cache_->mode() == PLAYBACK)
- effective_load_flags_ |= LOAD_ONLY_FROM_CACHE;
-
- // When in record mode, we want to NEVER load from the cache.
- // The reason for this is beacuse we save the Set-Cookie headers
- // (intentionally). If we read from the cache, we replay them
- // prematurely.
- if (cache_->mode() == RECORD)
- effective_load_flags_ |= LOAD_BYPASS_CACHE;
+ switch(cache_->mode()) {
+ case NORMAL:
+ break;
+ case RECORD:
+ // When in record mode, we want to NEVER load from the cache.
+ // The reason for this is beacuse we save the Set-Cookie headers
+ // (intentionally). If we read from the cache, we replay them
+ // prematurely.
+ effective_load_flags_ |= LOAD_BYPASS_CACHE;
+ case PLAYBACK:
+ // When in playback mode, we want to load exclusively from the cache.
+ effective_load_flags_ |= LOAD_ONLY_FROM_CACHE;
+ break;
+ case DISABLE:
+ effective_load_flags_ |= LOAD_DISABLE_CACHE;
+ break;
+ }
// Some headers imply load flags. The order here is significant.
//
@@ -1165,6 +1173,7 @@ std::string HttpCache::GenerateCacheKey(const HttpRequestInfo* request) {
if (request->url.has_ref())
url.erase(url.find_last_of('#'));
+ DCHECK(mode_ != DISABLE);
if (mode_ == NORMAL) {
// No valid URL can begin with numerals, so we should not have to worry
// about collisions with normal URLs.
@@ -1461,6 +1470,15 @@ void HttpCache::OnProcessPendingQueue(ActiveEntry* entry) {
AddTransactionToEntry(entry, next);
}
+void HttpCache::CloseIdleConnections() {
+ net::HttpNetworkLayer* network =
+ static_cast<net::HttpNetworkLayer*>(network_layer_.get());
+ HttpNetworkSession* session = network->GetSession();
+ if (session) {
+ session->connection_pool()->CloseIdleSockets();
+ }
+}
+
//-----------------------------------------------------------------------------
} // namespace net
diff --git a/net/http/http_cache.h b/net/http/http_cache.h
index af2d83a..70aaf0d 100644
--- a/net/http/http_cache.h
+++ b/net/http/http_cache.h
@@ -48,7 +48,10 @@ class HttpCache : public HttpTransactionFactory {
RECORD,
// Playback mode replays from a cache without considering any
// standard invalidations.
- PLAYBACK
+ PLAYBACK,
+ // Disables reads and writes from the cache.
+ // Equivalent to setting LOAD_DISABLE_CACHE on every request.
+ DISABLE
};
// Initialize the cache from the directory where its data is stored. The
@@ -103,6 +106,9 @@ class HttpCache : public HttpTransactionFactory {
void set_type(CacheType type) { type_ = type; }
CacheType type() { return type_; }
+ // Close All Idle Sockets. This is for debugging.
+ void CloseIdleConnections();
+
private:
// Types --------------------------------------------------------------------
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index b58eb44..ae1ecaa 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -1314,3 +1314,23 @@ TEST(HttpCache, OutlivedTransactions) {
delete cache;
delete trans;
}
+
+// Test that the disabled mode works.
+TEST(HttpCache, CacheDisabledMode) {
+ MockHttpCache cache;
+
+ // write to the cache
+ RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
+
+ // go into disabled mode
+ cache.http_cache()->set_mode(net::HttpCache::DISABLE);
+
+ // force this transaction to write to the cache again
+ MockTransaction transaction(kSimpleGET_Transaction);
+
+ RunTransactionTest(cache.http_cache(), transaction);
+
+ EXPECT_EQ(2, cache.network_layer()->transaction_count());
+ EXPECT_EQ(0, cache.disk_cache()->open_count());
+ EXPECT_EQ(1, cache.disk_cache()->create_count());
+}