summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc13
-rw-r--r--chrome/browser/net/chrome_url_request_context.h2
-rw-r--r--net/base/cache_type.h20
-rw-r--r--net/disk_cache/backend_impl.cc34
-rw-r--r--net/disk_cache/backend_impl.h18
-rw-r--r--net/disk_cache/backend_unittest.cc11
-rw-r--r--net/disk_cache/disk_cache.h3
-rw-r--r--net/disk_cache/disk_cache_perftest.cc6
-rw-r--r--net/disk_cache/disk_cache_test_base.cc3
-rw-r--r--net/disk_cache/eviction.cc6
-rw-r--r--net/disk_cache/eviction.h3
-rw-r--r--net/disk_cache/stress_cache.cc3
-rw-r--r--net/disk_cache/trace.cc26
-rw-r--r--net/disk_cache/trace.h15
-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
-rw-r--r--net/net.gyp1
-rw-r--r--net/tools/crash_cache/crash_cache.cc9
19 files changed, 135 insertions, 76 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 40050b0..81af0d4 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -108,7 +108,7 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginal(
ChromeURLRequestContext* ChromeURLRequestContext::CreateOriginalForMedia(
Profile* profile, const FilePath& disk_cache_path) {
DCHECK(!profile->IsOffTheRecord());
- return CreateRequestContextForMedia(profile, disk_cache_path);
+ return CreateRequestContextForMedia(profile, disk_cache_path, false);
}
// static
@@ -137,12 +137,12 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateOffTheRecordForMedia(
// for media files in OTR mode, we create a request context just like the
// original one.
DCHECK(profile->IsOffTheRecord());
- return CreateRequestContextForMedia(profile, disk_cache_path);
+ return CreateRequestContextForMedia(profile, disk_cache_path, true);
}
// static
ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
- Profile* profile, const FilePath& disk_cache_path) {
+ Profile* profile, const FilePath& disk_cache_path, bool off_the_record) {
URLRequestContext* original_context =
profile->GetOriginalProfile()->GetRequestContext();
ChromeURLRequestContext* context = new ChromeURLRequestContext(profile);
@@ -172,8 +172,13 @@ ChromeURLRequestContext* ChromeURLRequestContext::CreateRequestContextForMedia(
cache = new net::HttpCache(original_context->proxy_service(),
disk_cache_path.ToWStringHack(), kint32max);
}
+
// Set the cache type to media.
- cache->set_type(net::HttpCache::MEDIA);
+ if (off_the_record) {
+ cache->set_type(net::TEMP_MEDIA_CACHE);
+ } else {
+ cache->set_type(net::MEDIA_CACHE);
+ }
context->http_transaction_factory_ = cache;
return context;
diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h
index 2215199..7f31ef2 100644
--- a/chrome/browser/net/chrome_url_request_context.h
+++ b/chrome/browser/net/chrome_url_request_context.h
@@ -65,7 +65,7 @@ class ChromeURLRequestContext : public URLRequestContext,
// context. This helper method is called from CreateOriginalForMedia and
// CreateOffTheRecordForMedia.
static ChromeURLRequestContext* CreateRequestContextForMedia(Profile* profile,
- const FilePath& disk_cache_path);
+ const FilePath& disk_cache_path, bool off_the_record);
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
diff --git a/net/base/cache_type.h b/net/base/cache_type.h
new file mode 100644
index 0000000..4ba487f
--- /dev/null
+++ b/net/base/cache_type.h
@@ -0,0 +1,20 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_BASE_CACHE_TYPE_H_
+#define NET_BASE_CACHE_TYPE_H_
+
+namespace net {
+
+// The types of caches that can be created.
+enum CacheType {
+ DISK_CACHE, // Disk is used as the backing storage.
+ MEMORY_CACHE, // Data is stored only in memory.
+ MEDIA_CACHE, // Optimized to handle media files.
+ TEMP_MEDIA_CACHE // Optimized for media files while off the record.
+};
+
+} // namespace disk_cache
+
+#endif // NET_BASE_CACHE_TYPE_H_
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index f106534..ac68ec9 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -159,9 +159,10 @@ namespace disk_cache {
// a sharing violation), and in that case a cache for this profile (on the
// desired path) cannot be created.
Backend* CreateCacheBackend(const std::wstring& full_path, bool force,
- int max_bytes) {
+ int max_bytes, net::CacheType type) {
BackendImpl* cache = new BackendImpl(full_path);
cache->SetMaxSize(max_bytes);
+ cache->SetType(type);
if (cache->Init())
return cache;
@@ -176,6 +177,7 @@ Backend* CreateCacheBackend(const std::wstring& full_path, bool force,
// is not there anymore... let's create a new set of files.
cache = new BackendImpl(full_path);
cache->SetMaxSize(max_bytes);
+ cache->SetType(type);
if (cache->Init())
return cache;
@@ -204,6 +206,7 @@ bool BackendImpl::Init() {
num_refs_ = num_pending_io_ = max_refs_ = 0;
if (!restarted_) {
+ trace_object_ = TraceObject::GetTraceObject();
// Create a recurrent timer of 30 secs.
int timer_delay = unit_test_ ? 1000 : 30000;
timer_.Start(TimeDelta::FromMilliseconds(timer_delay), this,
@@ -528,6 +531,11 @@ bool BackendImpl::SetMaxSize(int max_bytes) {
return true;
}
+void BackendImpl::SetType(net::CacheType type) {
+ DCHECK(type != net::MEMORY_CACHE);
+ cache_type_ = type;
+}
+
std::wstring BackendImpl::GetFileName(Addr address) const {
if (!address.is_separate_file() || !address.is_initialized()) {
NOTREACHED();
@@ -683,18 +691,15 @@ void BackendImpl::TooMuchStorageRequested(int32 size) {
// We want to remove biases from some histograms so we only send data once per
// week.
bool BackendImpl::ShouldReportAgain() {
- static bool first_time = true;
- static bool should_send = false;
-
- if (!first_time)
- return should_send;
+ if (uma_report_)
+ return uma_report_ == 2;
- first_time = false;
+ uma_report_++;
int64 last_report = stats_.GetCounter(Stats::LAST_REPORT);
Time last_time = Time::FromInternalValue(last_report);
if (!last_report || (Time::Now() - last_time).InDays() >= 7) {
stats_.SetCounter(Stats::LAST_REPORT, Time::Now().ToInternalValue());
- should_send = true;
+ uma_report_++;
return true;
}
return false;
@@ -706,7 +711,7 @@ void BackendImpl::FirstEviction() {
Time create_time = Time::FromInternalValue(data_->header.create_time);
UMA_HISTOGRAM_HOURS("DiskCache.FillupAge",
(Time::Now() - create_time).InHours());
-
+
int64 use_hours = stats_.GetCounter(Stats::TIMER) / 120;
UMA_HISTOGRAM_HOURS("DiskCache.FillupTime", static_cast<int>(use_hours));
UMA_HISTOGRAM_PERCENTAGE("DiskCache.FirstHitRatio", stats_.GetHitRatio());
@@ -760,11 +765,10 @@ void BackendImpl::OnStatsTimer() {
stats_.SetCounter(Stats::OPEN_ENTRIES, current);
stats_.SetCounter(Stats::MAX_ENTRIES, max_refs_);
- static bool first_time = true;
if (!data_)
- first_time = false;
- if (first_time) {
- first_time = false;
+ first_timer_ = false;
+ if (first_timer_) {
+ first_timer_ = false;
if (ShouldReportAgain())
ReportStats();
}
@@ -1307,12 +1311,12 @@ void BackendImpl::ReportStats() {
int64 total_hours = stats_.GetCounter(Stats::TIMER) / 120;
UMA_HISTOGRAM_HOURS("DiskCache.TotalTime", static_cast<int>(total_hours));
-
+
int64 use_hours = stats_.GetCounter(Stats::LAST_REPORT_TIMER) / 120;
if (!use_hours || !GetEntryCount() || !data_->header.num_bytes)
return;
- UMA_HISTOGRAM_HOURS("DiskCache.UseTime", static_cast<int>(use_hours));
+ UMA_HISTOGRAM_HOURS("DiskCache.UseTime", static_cast<int>(use_hours));
UMA_HISTOGRAM_PERCENTAGE("DiskCache.HitRatio", stats_.GetHitRatio());
UMA_HISTOGRAM_PERCENTAGE("DiskCache.ResurrectRatio",
stats_.GetResurrectRatio());
diff --git a/net/disk_cache/backend_impl.h b/net/disk_cache/backend_impl.h
index fd1f9be..b66ab2f 100644
--- a/net/disk_cache/backend_impl.h
+++ b/net/disk_cache/backend_impl.h
@@ -23,14 +23,16 @@ class BackendImpl : public Backend {
friend class Eviction;
public:
explicit BackendImpl(const std::wstring& path)
- : path_(path), block_files_(path), mask_(0), max_size_(0), init_(false),
+ : path_(path), block_files_(path), mask_(0), max_size_(0),
+ cache_type_(net::DISK_CACHE), uma_report_(0), init_(false),
restarted_(false), unit_test_(false), read_only_(false),
- new_eviction_(false) {}
+ new_eviction_(false), first_timer_(true) {}
// mask can be used to limit the usable size of the hash table, for testing.
BackendImpl(const std::wstring& path, uint32 mask)
: path_(path), block_files_(path), mask_(mask), max_size_(0),
- init_(false), restarted_(false), unit_test_(false), read_only_(false),
- new_eviction_(false) {}
+ cache_type_(net::DISK_CACHE), uma_report_(0), init_(false),
+ restarted_(false), unit_test_(false), read_only_(false),
+ new_eviction_(false), first_timer_(true) {}
~BackendImpl();
// Performs general initialization for this current instance of the cache.
@@ -52,6 +54,9 @@ class BackendImpl : public Backend {
// Sets the maximum size for the total amount of data stored by this instance.
bool SetMaxSize(int max_bytes);
+ // Sets the cache type for this backend.
+ void SetType(net::CacheType type);
+
// Returns the full name for an external storage file.
std::wstring GetFileName(Addr address) const;
@@ -216,16 +221,19 @@ class BackendImpl : public Backend {
int num_refs_; // Number of referenced cache entries.
int max_refs_; // Max number of referenced cache entries.
int num_pending_io_; // Number of pending IO operations.
+ net::CacheType cache_type_;
+ int uma_report_; // Controls transmision of UMA data.
bool init_; // controls the initialization of the system.
bool restarted_;
bool unit_test_;
bool read_only_; // Prevents updates of the rankings data (used by tools).
bool disabled_;
bool new_eviction_; // What eviction algorithm should be used.
+ bool first_timer_; // True if the timer has not been called.
Stats stats_; // Usage statistcs.
base::RepeatingTimer<BackendImpl> timer_; // Usage timer.
- TraceObject trace_object_; // Inits and destroys internal tracing.
+ scoped_refptr<TraceObject> trace_object_; // Inits internal tracing.
DISALLOW_EVIL_CONSTRUCTORS(BackendImpl);
};
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 3de09c4..1562621 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -43,7 +43,8 @@ int TestTransaction(const std::wstring& name, int num_entries, bool load) {
scoped_ptr<disk_cache::Backend> cache;
if (!load) {
- cache.reset(disk_cache::CreateCacheBackend(path, false, 0));
+ cache.reset(disk_cache::CreateCacheBackend(path, false, 0,
+ net::DISK_CACHE));
} else {
disk_cache::BackendImpl* cache2 = new disk_cache::BackendImpl(path, 0xf);
if (!cache2 || !cache2->SetMaxSize(0x100000) || !cache2->Init())
@@ -787,7 +788,7 @@ TEST_F(DiskCacheTest, Backend_DeleteOld) {
ASSERT_TRUE(CopyTestCache(L"wrong_version"));
std::wstring path = GetCachePath();
scoped_ptr<disk_cache::Backend> cache;
- cache.reset(disk_cache::CreateCacheBackend(path, true, 0));
+ cache.reset(disk_cache::CreateCacheBackend(path, true, 0, net::DISK_CACHE));
MessageLoopHelper helper;
@@ -803,7 +804,8 @@ TEST_F(DiskCacheTest, Backend_DeleteOld) {
TEST_F(DiskCacheTest, Backend_InvalidEntry) {
ASSERT_TRUE(CopyTestCache(L"bad_entry"));
std::wstring path = GetCachePath();
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0);
+ disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
+ net::DISK_CACHE);
ASSERT_TRUE(NULL != cache);
disk_cache::Entry *entry1, *entry2;
@@ -819,7 +821,8 @@ TEST_F(DiskCacheTest, Backend_InvalidEntry) {
TEST_F(DiskCacheTest, Backend_InvalidRankings) {
ASSERT_TRUE(CopyTestCache(L"bad_rankings"));
std::wstring path = GetCachePath();
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0);
+ disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
+ net::DISK_CACHE);
ASSERT_TRUE(NULL != cache);
disk_cache::Entry *entry1, *entry2;
diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h
index 50f50c5..5eb6d2c 100644
--- a/net/disk_cache/disk_cache.h
+++ b/net/disk_cache/disk_cache.h
@@ -14,6 +14,7 @@
#include "base/basictypes.h"
#include "base/platform_file.h"
#include "base/time.h"
+#include "net/base/cache_type.h"
#include "net/base/completion_callback.h"
namespace net {
@@ -35,7 +36,7 @@ class Backend;
// based on the available disk space. The returned pointer can be NULL if a
// fatal error is found.
Backend* CreateCacheBackend(const std::wstring& path, bool force,
- int max_bytes);
+ int max_bytes, net::CacheType type);
// Returns an instance of a Backend implemented only in memory. The returned
// object should be deleted when not needed anymore. max_bytes is the maximum
diff --git a/net/disk_cache/disk_cache_perftest.cc b/net/disk_cache/disk_cache_perftest.cc
index 0abbc5b..e6bc88d 100644
--- a/net/disk_cache/disk_cache_perftest.cc
+++ b/net/disk_cache/disk_cache_perftest.cc
@@ -159,7 +159,8 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
ScopedTestCache test_cache;
disk_cache::Backend* cache =
- disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0);
+ disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0,
+ net::DISK_CACHE);
ASSERT_TRUE(NULL != cache);
int seed = static_cast<int>(Time::Now().ToInternalValue());
@@ -185,7 +186,8 @@ TEST_F(DiskCacheTest, CacheBackendPerformance) {
ASSERT_TRUE(file_util::EvictFileFromSystemCache(
test_cache.path().AppendASCII("data_3")));
- cache = disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0);
+ cache = disk_cache::CreateCacheBackend(test_cache.path_wstring(), false, 0,
+ net::DISK_CACHE);
ASSERT_TRUE(NULL != cache);
ret = TimeRead(num_entries, cache, entries, true);
diff --git a/net/disk_cache/disk_cache_test_base.cc b/net/disk_cache/disk_cache_test_base.cc
index 942420b..8992ca8 100644
--- a/net/disk_cache/disk_cache_test_base.cc
+++ b/net/disk_cache/disk_cache_test_base.cc
@@ -57,7 +57,8 @@ void DiskCacheTestWithCache::InitDiskCache() {
ASSERT_TRUE(DeleteCache(path.c_str()));
if (!implementation_) {
- cache_ = disk_cache::CreateCacheBackend(path, force_creation_, size_);
+ cache_ = disk_cache::CreateCacheBackend(path, force_creation_, size_,
+ net::DISK_CACHE);
return;
}
diff --git a/net/disk_cache/eviction.cc b/net/disk_cache/eviction.cc
index 3706260..76af8db 100644
--- a/net/disk_cache/eviction.cc
+++ b/net/disk_cache/eviction.cc
@@ -67,6 +67,7 @@ void Eviction::Init(BackendImpl* backend) {
header_ = &backend_->data_->header;
max_size_ = LowWaterAdjust(backend_->max_size_);
new_eviction_ = backend->new_eviction_;
+ first_trim_ = true;
}
void Eviction::TrimCache(bool empty) {
@@ -141,9 +142,8 @@ void Eviction::OnDestroyEntry(EntryImpl* entry) {
}
void Eviction::ReportTrimTimes(EntryImpl* entry) {
- static bool first_time = true;
- if (first_time) {
- first_time = false;
+ if (first_trim_) {
+ first_trim_ = false;
if (backend_->ShouldReportAgain()) {
std::string name(StringPrintf("DiskCache.TrimAge_%d",
header_->experiment));
diff --git a/net/disk_cache/eviction.h b/net/disk_cache/eviction.h
index 56b8439..55fbee7 100644
--- a/net/disk_cache/eviction.h
+++ b/net/disk_cache/eviction.h
@@ -56,7 +56,7 @@ class Eviction {
Rankings::List GetListForEntryV2(EntryImpl* entry);
void TrimDeleted(bool empty);
bool RemoveDeletedNode(CacheRankingsBlock* node);
-
+
bool NodeIsOldEnough(CacheRankingsBlock* node, int list);
int SelectListByLenght();
@@ -65,6 +65,7 @@ class Eviction {
IndexHeader* header_;
int max_size_;
bool new_eviction_;
+ bool first_trim_;
ScopedRunnableMethodFactory<Eviction> factory_;
DISALLOW_COPY_AND_ASSIGN(Eviction);
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc
index aa79a86..bf12d30 100644
--- a/net/disk_cache/stress_cache.cc
+++ b/net/disk_cache/stress_cache.cc
@@ -77,7 +77,8 @@ void StressTheCache(int iteration) {
std::wstring path = GetCachePath();
path.append(L"_stress");
disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false,
- cache_size);
+ cache_size,
+ net::DISK_CACHE);
if (NULL == cache) {
printf("Unable to initialize cache.\n");
return;
diff --git a/net/disk_cache/trace.cc b/net/disk_cache/trace.cc
index 958f9e0..da97c40 100644
--- a/net/disk_cache/trace.cc
+++ b/net/disk_cache/trace.cc
@@ -42,24 +42,37 @@ void DebugOutput(const char* msg) {
namespace disk_cache {
+// s_trace_buffer and s_trace_object are not singletons because I want the
+// buffer to be destroyed and re-created when the last user goes away, and it
+// must be straightforward to access the buffer from the debugger.
+static TraceObject* s_trace_object = NULL;
+
+// Static.
+TraceObject* TraceObject::GetTraceObject() {
+ if (s_trace_object)
+ return s_trace_object;
+
+ s_trace_object = new TraceObject();
+ return s_trace_object;
+}
+
#if ENABLE_TRACING
static TraceBuffer* s_trace_buffer = NULL;
-bool InitTrace(void) {
- DCHECK(!s_trace_buffer);
+void InitTrace(void) {
if (s_trace_buffer)
- return false;
+ return;
s_trace_buffer = new TraceBuffer;
memset(s_trace_buffer, 0, sizeof(*s_trace_buffer));
- return true;
}
void DestroyTrace(void) {
DCHECK(s_trace_buffer);
delete s_trace_buffer;
s_trace_buffer = NULL;
+ s_trace_object = NULL;
}
void Trace(const char* format, ...) {
@@ -118,11 +131,12 @@ void DumpTrace(int num_traces) {
#else // ENABLE_TRACING
-bool InitTrace(void) {
- return true;
+void InitTrace(void) {
+ return;
}
void DestroyTrace(void) {
+ s_trace_object = NULL;
}
void Trace(const char* format, ...) {
diff --git a/net/disk_cache/trace.h b/net/disk_cache/trace.h
index 50dda3c..be50417 100644
--- a/net/disk_cache/trace.h
+++ b/net/disk_cache/trace.h
@@ -13,24 +13,29 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/ref_counted.h"
namespace disk_cache {
// Create and destroy the tracing buffer.
-bool InitTrace(void);
+void InitTrace(void);
void DestroyTrace(void);
-// Simple class to handle the trace buffer lifetime.
-class TraceObject {
+// Simple class to handle the trace buffer lifetime. Any object interested in
+// tracing should keep a reference to the object returned by GetTraceObject().
+class TraceObject : public base::RefCounted<TraceObject> {
+ friend class base::RefCounted<TraceObject>;
public:
+ static TraceObject* GetTraceObject();
+
+ private:
TraceObject() {
InitTrace();
}
+
~TraceObject() {
DestroyTrace();
}
-
- private:
DISALLOW_EVIL_CONSTRUCTORS(TraceObject);
};
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;
diff --git a/net/net.gyp b/net/net.gyp
index 80631c3..9bb54d0 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -34,6 +34,7 @@
'base/base64.h',
'base/bzip2_filter.cc',
'base/bzip2_filter.h',
+ 'base/cache_type.h',
'base/cert_status_flags.cc',
'base/cert_status_flags.h',
'base/cert_verifier.cc',
diff --git a/net/tools/crash_cache/crash_cache.cc b/net/tools/crash_cache/crash_cache.cc
index ee688c3..34cff08 100644
--- a/net/tools/crash_cache/crash_cache.cc
+++ b/net/tools/crash_cache/crash_cache.cc
@@ -119,7 +119,8 @@ bool CreateTargetFolder(const std::wstring& path, RankCrashes action,
// Generates the files for an empty and one item cache.
int SimpleInsert(const std::wstring& path, RankCrashes action) {
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0);
+ disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
+ net::DISK_CACHE);
if (!cache || cache->GetEntryCount())
return GENERIC;
@@ -151,7 +152,8 @@ int SimpleRemove(const std::wstring& path, RankCrashes action) {
DCHECK(action >= disk_cache::REMOVE_ONE_1);
DCHECK(action <= disk_cache::REMOVE_TAIL_3);
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0);
+ disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
+ net::DISK_CACHE);
if (!cache || cache->GetEntryCount())
return GENERIC;
@@ -182,7 +184,8 @@ int HeadRemove(const std::wstring& path, RankCrashes action) {
DCHECK(action >= disk_cache::REMOVE_HEAD_1);
DCHECK(action <= disk_cache::REMOVE_HEAD_4);
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0);
+ disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
+ net::DISK_CACHE);
if (!cache || cache->GetEntryCount())
return GENERIC;