summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-25 23:44:20 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-25 23:44:20 +0000
commit6192f73a9dd17c950ef1ca97db086e8bc4eaf05e (patch)
tree7af372f9670e74b144d17f1f7c009a9eb13a74a2 /net/http
parent1ba590018ad58ea18ec3079f089feb64fd951d87 (diff)
downloadchromium_src-6192f73a9dd17c950ef1ca97db086e8bc4eaf05e.zip
chromium_src-6192f73a9dd17c950ef1ca97db086e8bc4eaf05e.tar.gz
chromium_src-6192f73a9dd17c950ef1ca97db086e8bc4eaf05e.tar.bz2
Disk cache: First pass to make it possible to have
multiple instances of BackendImpl. We need multiple objects to be able to support media files on the cache. After this change, histograms will be the only thing that get messed up by multiple disk caches. Review URL: http://codereview.chromium.org/49027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_cache.cc16
-rw-r--r--net/http/http_cache.h18
-rw-r--r--net/http/http_cache_unittest.cc4
3 files changed, 14 insertions, 24 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc
index be1347c..38a8f23 100644
--- a/net/http/http_cache.cc
+++ b/net/http/http_cache.cc
@@ -583,7 +583,7 @@ void HttpCache::Transaction::SetRequest(const HttpRequestInfo* request) {
// If HttpCache has type MEDIA make sure LOAD_ENABLE_DOWNLOAD_FILE is set,
// otherwise make sure LOAD_ENABLE_DOWNLOAD_FILE is not set when HttpCache
// has type other than MEDIA.
- if (cache_->type() == HttpCache::MEDIA) {
+ if (cache_->type() == MEDIA_CACHE) {
DCHECK(effective_load_flags_ & LOAD_ENABLE_DOWNLOAD_FILE);
} else {
DCHECK(!(effective_load_flags_ & LOAD_ENABLE_DOWNLOAD_FILE));
@@ -782,7 +782,7 @@ int HttpCache::Transaction::ReadResponseInfoFromEntry() {
// If the cache object is used for media file, we want the file handle of
// response data.
- if (cache_->type() == HttpCache::MEDIA) {
+ if (cache_->type() == MEDIA_CACHE) {
response_.response_data_file =
entry_->disk_entry->GetPlatformFile(kResponseContentIndex);
}
@@ -856,7 +856,7 @@ void HttpCache::Transaction::TruncateResponseData() {
// if we get a valid response from server, i.e. 200. We don't want empty
// cache files for redirection or external files for erroneous requests.
response_.response_data_file = base::kInvalidPlatformFileValue;
- if (cache_->type() == HttpCache::MEDIA) {
+ if (cache_->type() == MEDIA_CACHE) {
response_.response_data_file =
entry_->disk_entry->UseExternalFile(kResponseContentIndex);
}
@@ -977,7 +977,7 @@ HttpCache::HttpCache(ProxyService* proxy_service,
int cache_size)
: disk_cache_dir_(cache_dir),
mode_(NORMAL),
- type_(COMMON),
+ type_(DISK_CACHE),
network_layer_(HttpNetworkLayer::CreateFactory(proxy_service)),
ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
in_memory_cache_(false),
@@ -989,7 +989,7 @@ HttpCache::HttpCache(HttpNetworkSession* session,
int cache_size)
: disk_cache_dir_(cache_dir),
mode_(NORMAL),
- type_(COMMON),
+ type_(DISK_CACHE),
network_layer_(HttpNetworkLayer::CreateFactory(session)),
ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
in_memory_cache_(false),
@@ -998,7 +998,7 @@ HttpCache::HttpCache(HttpNetworkSession* session,
HttpCache::HttpCache(ProxyService* proxy_service, int cache_size)
: mode_(NORMAL),
- type_(COMMON),
+ type_(MEMORY_CACHE),
network_layer_(HttpNetworkLayer::CreateFactory(proxy_service)),
ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
in_memory_cache_(true),
@@ -1008,7 +1008,7 @@ HttpCache::HttpCache(ProxyService* proxy_service, int cache_size)
HttpCache::HttpCache(HttpTransactionFactory* network_layer,
disk_cache::Backend* disk_cache)
: mode_(NORMAL),
- type_(COMMON),
+ type_(DISK_CACHE),
network_layer_(network_layer),
disk_cache_(disk_cache),
ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
@@ -1046,7 +1046,7 @@ HttpTransaction* HttpCache::CreateTransaction() {
disk_cache_.reset(disk_cache::CreateInMemoryCacheBackend(cache_size_));
} else if (!disk_cache_dir_.empty()) {
disk_cache_.reset(disk_cache::CreateCacheBackend(disk_cache_dir_, true,
- cache_size_));
+ cache_size_, type_));
disk_cache_dir_.clear(); // Reclaim memory.
}
}
diff --git a/net/http/http_cache.h b/net/http/http_cache.h
index eb47b44..af2d83a 100644
--- a/net/http/http_cache.h
+++ b/net/http/http_cache.h
@@ -21,6 +21,7 @@
#include "base/hash_tables.h"
#include "base/scoped_ptr.h"
#include "base/task.h"
+#include "net/base/cache_type.h"
#include "net/http/http_transaction_factory.h"
namespace disk_cache {
@@ -50,17 +51,6 @@ class HttpCache : public HttpTransactionFactory {
PLAYBACK
};
- // The type of an HttpCache object, essentially describe what an HttpCache
- // object is for.
- enum Type {
- // An HttpCache object for common objects, e.g. html pages, images, fonts,
- // css files, js files and other common web resources.
- COMMON = 0,
- // A cache system for media file, e.g. video and audio files. These files
- // are huge and has special requirement for access.
- MEDIA
- };
-
// Initialize the cache from the directory where its data is stored. The
// disk cache is initialized lazily (by CreateTransaction) in this case. If
// |cache_size| is zero, a default value will be calculated automatically.
@@ -110,8 +100,8 @@ class HttpCache : public HttpTransactionFactory {
void set_mode(Mode value) { mode_ = value; }
Mode mode() { return mode_; }
- void set_type(Type type) { type_ = type; }
- Type type() { return type_; }
+ void set_type(CacheType type) { type_ = type; }
+ CacheType type() { return type_; }
private:
@@ -169,7 +159,7 @@ class HttpCache : public HttpTransactionFactory {
std::wstring disk_cache_dir_;
Mode mode_;
- Type type_;
+ CacheType type_;
scoped_ptr<HttpTransactionFactory> network_layer_;
scoped_ptr<disk_cache::Backend> disk_cache_;
diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
index 2d343f8..7f84a36 100644
--- a/net/http/http_cache_unittest.cc
+++ b/net/http/http_cache_unittest.cc
@@ -1263,9 +1263,9 @@ TEST(HttpCache, OutlivedTransactions) {
// when an entry is loaded from a HttpCache with MEDIA type. Also confirm we
// will receive a file handle in ResponseInfo from a media cache.
TEST(HttpCache, SimpleGET_MediaCache) {
- // Initialize the HttpCache with MEDIA type.
+ // Initialize the HttpCache with MEDIA_CACHE type.
MockHttpCache cache;
- cache.http_cache()->set_type(net::HttpCache::MEDIA);
+ cache.http_cache()->set_type(net::MEDIA_CACHE);
// Define some fake file handles for testing.
base::PlatformFile kFakePlatformFile1, kFakePlatformFile2;