summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_unittest.cc7
-rw-r--r--net/disk_cache/disk_cache.h23
-rw-r--r--net/disk_cache/entry_impl.cc51
-rw-r--r--net/disk_cache/entry_impl.h4
-rw-r--r--net/disk_cache/entry_unittest.cc99
-rw-r--r--net/disk_cache/histogram_macros.h3
-rw-r--r--net/disk_cache/mem_entry_impl.h8
7 files changed, 3 insertions, 192 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 2fbcfa9..bd510c0 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -1310,18 +1310,15 @@ TEST_F(DiskCacheTest, MultipleInstances) {
ScopedTestCache store2(L"cache_test2");
ScopedTestCache store3(L"cache_test3");
- const int kNumberOfCaches = 3;
+ const int kNumberOfCaches = 2;
scoped_ptr<disk_cache::Backend> cache[kNumberOfCaches];
cache[0].reset(disk_cache::CreateCacheBackend(store1.path_wstring(), false, 0,
net::DISK_CACHE));
cache[1].reset(disk_cache::CreateCacheBackend(store2.path_wstring(), false, 0,
net::MEDIA_CACHE));
- cache[2].reset(disk_cache::CreateCacheBackend(store3.path_wstring(), false, 0,
- net::TEMP_MEDIA_CACHE));
- ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL &&
- cache[2].get() != NULL);
+ ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL);
std::string key("the first key");
disk_cache::Entry* entry;
diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h
index 5eb6d2c..de40554 100644
--- a/net/disk_cache/disk_cache.h
+++ b/net/disk_cache/disk_cache.h
@@ -12,7 +12,6 @@
#include <vector>
#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"
@@ -155,28 +154,6 @@ class Entry {
net::CompletionCallback* completion_callback,
bool truncate) = 0;
- // Prepares a target stream as an external file, returns a corresponding
- // base::PlatformFile if successful, returns base::kInvalidPlatformFileValue
- // if fails. If this call returns a valid base::PlatformFile value (i.e.
- // not base::kInvalidPlatformFileValue), there is no guarantee that the file
- // is truncated. Implementor can always return base::kInvalidPlatformFileValue
- // if external file is not available in that particular implementation.
- // The caller should close the file handle returned by this method or there
- // will be a leak.
- // With a stream prepared as an external file, the stream would always be
- // kept in an external file since creation, even if the stream has 0 bytes.
- // So we need to be cautious about using this option for preparing a stream or
- // we will end up having a lot of empty cache files. Calling this method also
- // means that all data written to the stream will always be written to file
- // directly *without* buffering.
- virtual base::PlatformFile UseExternalFile(int index) = 0;
-
- // Returns an asynchronous read file handle for the cache stream referenced by
- // |index|. Values other than base::kInvalidPlatformFileValue are successful
- // and the file handle should be managed by the caller, i.e. the caller should
- // close the handle after use or there will be a leak.
- virtual base::PlatformFile GetPlatformFile(int index) = 0;
-
protected:
virtual ~Entry() {}
};
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index a000785..e0853b7 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -81,7 +81,6 @@ EntryImpl::EntryImpl(BackendImpl* backend, Addr address)
backend_ = backend;
for (int i = 0; i < NUM_STREAMS; i++) {
unreported_size_[i] = 0;
- need_file_[i] = false;
}
}
@@ -303,9 +302,7 @@ int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
backend_->OnEvent(Stats::WRITE_DATA);
- // If we have prepared the cache as an external file, we should never use
- // user_buffers_ and always write to file directly.
- if (!need_file_[index] && user_buffers_[index].get()) {
+ if (user_buffers_[index].get()) {
// Complete the operation locally.
if (!buf_len)
return 0;
@@ -354,43 +351,6 @@ int EntryImpl::WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
return (completed || !completion_callback) ? buf_len : net::ERR_IO_PENDING;
}
-base::PlatformFile EntryImpl::UseExternalFile(int index) {
- DCHECK(index >= 0 && index < NUM_STREAMS);
-
- Addr address(entry_.Data()->data_addr[index]);
-
- // We will not prepare the cache file since the entry is already initialized,
- // just return the platform file backing the cache.
- if (address.is_initialized())
- return GetPlatformFile(index);
-
- if (!backend_->CreateExternalFile(&address))
- return base::kInvalidPlatformFileValue;
-
- entry_.Data()->data_addr[index] = address.value();
- entry_.Store();
-
- // Set the flag for this stream so we never use user_buffer_.
- // TODO(hclam): do we need to save this information to EntryStore?
- need_file_[index] = true;
-
- return GetPlatformFile(index);
-}
-
-base::PlatformFile EntryImpl::GetPlatformFile(int index) {
- DCHECK(index >= 0 && index < NUM_STREAMS);
-
- Addr address(entry_.Data()->data_addr[index]);
- if (!address.is_initialized() || !address.is_separate_file())
- return base::kInvalidPlatformFileValue;
-
- return base::CreatePlatformFile(backend_->GetFileName(address),
- base::PLATFORM_FILE_OPEN |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_ASYNC,
- NULL);
-}
-
uint32 EntryImpl::GetHash() {
return entry_.Data()->hash;
}
@@ -675,15 +635,6 @@ bool EntryImpl::PrepareTarget(int index, int offset, int buf_len,
bool truncate) {
Addr address(entry_.Data()->data_addr[index]);
- // If we are instructed to use an external file, we should never buffer when
- // writing. We are done with preparation of the target automatically, since
- // we have already created the external file for writing.
- if (need_file_[index]) {
- // Make sure the stream is initialized and is kept in an external file.
- DCHECK(address.is_initialized() && address.is_separate_file());
- return true;
- }
-
if (address.is_initialized() || user_buffers_[index].get())
return GrowUserBuffer(index, offset, buf_len, truncate);
diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h
index 71a960a..39ba186 100644
--- a/net/disk_cache/entry_impl.h
+++ b/net/disk_cache/entry_impl.h
@@ -33,8 +33,6 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
net::CompletionCallback* completion_callback,
bool truncate);
- virtual base::PlatformFile UseExternalFile(int index);
- virtual base::PlatformFile GetPlatformFile(int index);
inline CacheEntryBlock* entry() {
return &entry_;
@@ -146,8 +144,6 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
// data and key.
int unreported_size_[NUM_STREAMS]; // Bytes not reported yet to the backend.
bool doomed_; // True if this entry was removed from the cache.
- bool need_file_[NUM_STREAMS]; // True if stream is prepared as an external
- // file.
DISALLOW_EVIL_CONSTRUCTORS(EntryImpl);
};
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index a79b3f7..e48acb5 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -832,102 +832,3 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyDoomedEntry) {
InitCache();
DoomEntry();
}
-
-// Check that we can hint an entry to use external file and the return value
-// is a valid file handle.
-TEST_F(DiskCacheEntryTest, UseExternalFile) {
- InitCache();
-
- disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry("key", &entry));
- base::PlatformFile cache_file = entry->UseExternalFile(0);
-
- // We should have a valid file handle.
- EXPECT_NE(base::kInvalidPlatformFileValue, cache_file);
- scoped_refptr<disk_cache::File> file(new disk_cache::File(cache_file));
-
- // 4KB.
- size_t kDataSize = 0x1000;
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kDataSize);
-
- CacheTestFillBuffer(buffer->data(), kDataSize, false);
- ASSERT_EQ(0U, file->GetLength());
- ASSERT_EQ(kDataSize, static_cast<size_t>(
- entry->WriteData(0, 0, buffer, kDataSize, NULL, false)));
- ASSERT_EQ(kDataSize, file->GetLength());
- entry->Close();
-}
-
-// Make sure we can use Entry::GetPlatformFile on an entry stored in an external
-// file and get a valid file handle.
-TEST_F(DiskCacheEntryTest, GetPlatformFile) {
- InitCache();
-
- disk_cache::Entry* entry;
- ASSERT_TRUE(cache_->CreateEntry("key", &entry));
- EXPECT_NE(base::kInvalidPlatformFileValue, entry->UseExternalFile(0));
-
- size_t kDataSize = 50;
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kDataSize);
-
- // Fill the data buffer and write it to cache.
- CacheTestFillBuffer(buffer->data(), kDataSize, false);
- ASSERT_EQ(kDataSize,static_cast<size_t>(
- entry->WriteData(0, 0, buffer, kDataSize, NULL, false)));
-
- // Close the entry.
- entry->Close();
-
- // Open the entry again and get it's file handle.
- ASSERT_TRUE(cache_->OpenEntry("key", &entry));
- base::PlatformFile cache_file = entry->GetPlatformFile(0);
-
- // Make sure it's a valid file handle and verify the size of the file.
- scoped_refptr<disk_cache::File> file(new disk_cache::File(cache_file));
- ASSERT_EQ(kDataSize, file->GetLength());
-
- entry->Close();
-}
-
-// Test the behavior of EntryImpl that small entries are kept in block files
-// or buffer, and only entries above certain size would be stored in an
-// external file, make sure GetPlatformFile() works with both cases without
-// using UseExternalFile().
-TEST_F(DiskCacheEntryTest, GetPlatformFileVariableEntrySize) {
- InitCache();
-
- disk_cache::Entry* entry;
-
- // Make the buffer just larger than disk_cache::kMaxBlockSize.
- const size_t kLargeDataSize = disk_cache::kMaxBlockSize + 1;
- const size_t kSmallDataSize = kLargeDataSize / 2;
- scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(kLargeDataSize);
-
- // 1. First test with small entry.
- ASSERT_TRUE(cache_->CreateEntry("small_entry", &entry));
-
- CacheTestFillBuffer(buffer->data(), kSmallDataSize, false);
- ASSERT_EQ(kSmallDataSize, static_cast<size_t>(
- entry->WriteData(0, 0, buffer, kSmallDataSize, NULL, false)));
-
- // Make sure we don't get an external file.
- ASSERT_EQ(base::kInvalidPlatformFileValue, entry->GetPlatformFile(0));
-
- entry->Close();
-
- // 2. Test with large entry.
- ASSERT_TRUE(cache_->CreateEntry("large_entry", &entry));
-
- CacheTestFillBuffer(buffer->data(), kLargeDataSize, false);
- ASSERT_EQ(kLargeDataSize, static_cast<size_t>(
- entry->WriteData(0, 0, buffer, kLargeDataSize, NULL, false)));
-
- base::PlatformFile cache_file = entry->GetPlatformFile(0);
- EXPECT_NE(base::kInvalidPlatformFileValue, cache_file);
-
- // Make sure it's a valid file handle and verify the size of the file.
- scoped_refptr<disk_cache::File> file(new disk_cache::File(cache_file));
- ASSERT_EQ(kLargeDataSize, file->GetLength());
-
- entry->Close();
-}
diff --git a/net/disk_cache/histogram_macros.h b/net/disk_cache/histogram_macros.h
index ef88ccf..6ff66ea 100644
--- a/net/disk_cache/histogram_macros.h
+++ b/net/disk_cache/histogram_macros.h
@@ -56,9 +56,6 @@
case net::MEDIA_CACHE:\
UMA_HISTOGRAM_##type(my_name.data(), sample);\
break;\
- case net::TEMP_MEDIA_CACHE:\
- UMA_HISTOGRAM_##type(my_name.data(), sample);\
- break;\
default:\
NOTREACHED();\
break;\
diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h
index f51bf601..42fad96 100644
--- a/net/disk_cache/mem_entry_impl.h
+++ b/net/disk_cache/mem_entry_impl.h
@@ -29,14 +29,6 @@ class MemEntryImpl : public Entry {
virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
net::CompletionCallback* completion_callback,
bool truncate);
- virtual base::PlatformFile UseExternalFile(int index) {
- // MemEntryImpl doesn't support caching to an external file.
- return base::kInvalidPlatformFileValue;
- }
- virtual base::PlatformFile GetPlatformFile(int index) {
- // MemEntryImpl doesn't support caching to an external file.
- return base::kInvalidPlatformFileValue;
- }
// Performs the initialization of a EntryImpl that will be added to the
// cache.