summaryrefslogtreecommitdiff
path: root/net/disk_cache
diff options
context:
space:
mode:
authorIain Merrick <husky@google.com>2010-11-01 12:19:54 +0000
committerIain Merrick <husky@google.com>2010-11-03 10:21:10 +0000
commit731df977c0511bca2206b5f333555b1205ff1f43 (patch)
tree0e750b949b3f00a1ac11fda25d3c2de512f2b465 /net/disk_cache
parent5add15e10e7bb80512f2c597ca57221314abe577 (diff)
downloadchromium-731df977c0511bca2206b5f333555b1205ff1f43.tar.gz
Merge Chromium at r63472 : Initial merge by git.
Change-Id: Ifb9ee821af006a5f2211e81471be93ae440a1f5a
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc58
-rw-r--r--net/disk_cache/block_files.cc4
-rw-r--r--net/disk_cache/cache_util.h6
-rw-r--r--net/disk_cache/cache_util_posix.cc28
-rw-r--r--net/disk_cache/cache_util_unittest.cc90
-rw-r--r--net/disk_cache/cache_util_win.cc7
-rw-r--r--net/disk_cache/disk_cache_test_util.cc4
-rw-r--r--net/disk_cache/disk_cache_test_util.h4
-rw-r--r--net/disk_cache/disk_format.cc21
-rw-r--r--net/disk_cache/disk_format.h14
-rw-r--r--net/disk_cache/entry_impl.cc13
-rw-r--r--net/disk_cache/file.cc16
-rw-r--r--net/disk_cache/file.h4
-rw-r--r--net/disk_cache/file_posix.cc5
-rw-r--r--net/disk_cache/histogram_macros.h25
-rw-r--r--net/disk_cache/in_flight_backend_io.cc2
-rw-r--r--net/disk_cache/in_flight_backend_io.h2
-rw-r--r--net/disk_cache/mapped_file_unittest.cc22
-rw-r--r--net/disk_cache/mem_backend_impl.cc2
-rw-r--r--net/disk_cache/mem_backend_impl.h2
-rw-r--r--net/disk_cache/rankings.cc4
-rw-r--r--net/disk_cache/sparse_control.cc11
-rw-r--r--net/disk_cache/sparse_control.h7
-rw-r--r--net/disk_cache/stats_histogram.cc3
-rw-r--r--net/disk_cache/stats_histogram.h6
-rw-r--r--net/disk_cache/trace.cc2
26 files changed, 251 insertions, 111 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 7a0f9b34..07092388 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -1,14 +1,14 @@
-// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
#include "net/disk_cache/backend_impl.h"
-#include "base/field_trial.h"
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/histogram.h"
#include "base/message_loop.h"
+#include "base/metrics/field_trial.h"
+#include "base/metrics/histogram.h"
#include "base/rand_util.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
@@ -133,7 +133,7 @@ bool DelayedCacheCleanup(const FilePath& full_path) {
}
if (!disk_cache::MoveCache(full_path, to_delete)) {
- LOG(ERROR) << "Unable to rename cache folder";
+ LOG(ERROR) << "Unable to move cache folder";
return false;
}
@@ -143,7 +143,7 @@ bool DelayedCacheCleanup(const FilePath& full_path) {
// Sets group for the current experiment. Returns false if the files should be
// discarded.
-bool InitExperiment(disk_cache::IndexHeader* header, uint32 mask) {
+bool InitExperiment(disk_cache::IndexHeader* header) {
if (header->experiment == disk_cache::EXPERIMENT_OLD_FILE1 ||
header->experiment == disk_cache::EXPERIMENT_OLD_FILE2) {
// Discard current cache.
@@ -154,31 +154,8 @@ bool InitExperiment(disk_cache::IndexHeader* header, uint32 mask) {
if (header->experiment >= disk_cache::EXPERIMENT_DELETED_LIST_OUT)
return true;
- if (!header->create_time || !header->lru.filled) {
- // Only for users with a full cache.
- header->experiment = disk_cache::EXPERIMENT_DELETED_LIST_OUT;
- return true;
- }
-
- int index_load = header->num_entries * 100 / (mask + 1);
- if (index_load > 20) {
- // Out of the experiment (~ 35% users).
- header->experiment = disk_cache::EXPERIMENT_DELETED_LIST_OUT;
- return true;
- }
-
- int option = base::RandInt(0, 5);
- if (option > 1) {
- // 60% out (39% of the total).
- header->experiment = disk_cache::EXPERIMENT_DELETED_LIST_OUT;
- } else if (!option) {
- // About 13% of the total.
- header->experiment = disk_cache::EXPERIMENT_DELETED_LIST_CONTROL;
- } else {
- // About 13% of the total.
- header->experiment = disk_cache::EXPERIMENT_DELETED_LIST_IN;
- }
-
+ // The experiment is closed.
+ header->experiment = disk_cache::EXPERIMENT_DELETED_LIST_OUT;
return true;
}
@@ -192,11 +169,13 @@ bool SetFieldTrialInfo(int size_group) {
// Field trials involve static objects so we have to do this only once.
first = false;
- scoped_refptr<FieldTrial> trial1 = new FieldTrial("CacheSize", 10);
+ scoped_refptr<base::FieldTrial> trial1 =
+ new base::FieldTrial("CacheSize", 10);
std::string group1 = base::StringPrintf("CacheSizeGroup_%d", size_group);
- trial1->AppendGroup(group1, FieldTrial::kAllRemainingProbability);
+ trial1->AppendGroup(group1, base::FieldTrial::kAllRemainingProbability);
- scoped_refptr<FieldTrial> trial2 = new FieldTrial("CacheThrottle", 100);
+ scoped_refptr<base::FieldTrial> trial2 =
+ new base::FieldTrial("CacheThrottle", 100);
int group2a = trial2->AppendGroup("CacheThrottle_On", 10); // 10 % in.
trial2->AppendGroup("CacheThrottle_Off", 10); // 10 % control.
@@ -582,7 +561,7 @@ int BackendImpl::SyncInit() {
if (!(user_flags_ & disk_cache::kNoRandom) &&
cache_type_ == net::DISK_CACHE &&
- !InitExperiment(&data_->header, mask_))
+ !InitExperiment(&data_->header))
return net::ERR_FAILED;
// We don't care if the value overflows. The only thing we care about is that
@@ -1235,9 +1214,9 @@ void BackendImpl::OnOperationCompleted(base::TimeDelta elapsed_time) {
if (cache_type() != net::DISK_CACHE)
return;
- UMA_HISTOGRAM_TIMES(
- FieldTrial::MakeName("DiskCache.TotalIOTime", "CacheThrottle").data(),
- elapsed_time);
+ UMA_HISTOGRAM_TIMES(base::FieldTrial::MakeName("DiskCache.TotalIOTime",
+ "CacheThrottle").data(),
+ elapsed_time);
if (!throttle_requests_)
return;
@@ -1860,9 +1839,8 @@ void BackendImpl::LogStats() {
StatsItems stats;
GetStats(&stats);
- for (size_t index = 0; index < stats.size(); index++) {
- LOG(INFO) << stats[index].first << ": " << stats[index].second;
- }
+ for (size_t index = 0; index < stats.size(); index++)
+ VLOG(1) << stats[index].first << ": " << stats[index].second;
}
void BackendImpl::ReportStats() {
diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc
index a0fc6b68..9d5de62e 100644
--- a/net/disk_cache/block_files.cc
+++ b/net/disk_cache/block_files.cc
@@ -5,7 +5,7 @@
#include "net/disk_cache/block_files.h"
#include "base/file_util.h"
-#include "base/histogram.h"
+#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/thread_checker.h"
@@ -122,6 +122,7 @@ void DeleteMapBlock(int index, int size, disk_cache::BlockFileHeader* header) {
HISTOGRAM_TIMES("DiskCache.DeleteBlock", TimeTicks::Now() - start);
}
+#ifndef NDEBUG
// Returns true if the specified block is used. Note that this is a simplified
// version of DeleteMapBlock().
bool UsedMapBlock(int index, int size, disk_cache::BlockFileHeader* header) {
@@ -140,6 +141,7 @@ bool UsedMapBlock(int index, int size, disk_cache::BlockFileHeader* header) {
uint8 to_clear = ((1 << size) - 1) << (index % 8);
return ((byte_map[byte_index] & to_clear) == to_clear);
}
+#endif // NDEBUG
// Restores the "empty counters" and allocation hints.
void FixAllocationCounters(disk_cache::BlockFileHeader* header) {
diff --git a/net/disk_cache/cache_util.h b/net/disk_cache/cache_util.h
index 455bf305..04b9a070 100644
--- a/net/disk_cache/cache_util.h
+++ b/net/disk_cache/cache_util.h
@@ -13,7 +13,11 @@ class FilePath;
namespace disk_cache {
// Moves the cache files from the given path to another location.
-// Returns true if successful, false otherwise.
+// Fails if the destination exists already, or if it doesn't have
+// permission for the operation. This is basically a rename operation
+// for the cache directory. Returns true if successful. On ChromeOS,
+// this moves the cache contents, and leaves the empty cache
+// directory.
bool MoveCache(const FilePath& from_path, const FilePath& to_path);
// Deletes the cache files stored on |path|, and optionally also attempts to
diff --git a/net/disk_cache/cache_util_posix.cc b/net/disk_cache/cache_util_posix.cc
index b3937473..bc877461 100644
--- a/net/disk_cache/cache_util_posix.cc
+++ b/net/disk_cache/cache_util_posix.cc
@@ -11,8 +11,34 @@
namespace disk_cache {
bool MoveCache(const FilePath& from_path, const FilePath& to_path) {
- // Just use the version from base.
+#if defined(OS_CHROMEOS)
+ // For ChromeOS, we don't actually want to rename the cache
+ // directory, because if we do, then it'll get recreated through the
+ // encrypted filesystem (with encrypted names), and we won't be able
+ // to see these directories anymore in an unmounted encrypted
+ // filesystem, so we just move each item in the cache to a new
+ // directory.
+ if (!file_util::CreateDirectory(to_path)) {
+ LOG(ERROR) << "Unable to create destination cache directory.";
+ return false;
+ }
+ file_util::FileEnumerator iter(
+ from_path,
+ /* recursive */ false,
+ static_cast<file_util::FileEnumerator::FILE_TYPE>(
+ file_util::FileEnumerator::DIRECTORIES |
+ file_util::FileEnumerator::FILES));
+ for (FilePath name = iter.Next(); !name.value().empty(); name = iter.Next()) {
+ FilePath destination = to_path.Append(name.BaseName());
+ if (!file_util::Move(name, destination)) {
+ LOG(ERROR) << "Unable to move cache item.";
+ return false;
+ }
+ }
+ return true;
+#else
return file_util::Move(from_path, to_path);
+#endif
}
void DeleteCache(const FilePath& path, bool remove_folder) {
diff --git a/net/disk_cache/cache_util_unittest.cc b/net/disk_cache/cache_util_unittest.cc
new file mode 100644
index 00000000..e6164804
--- /dev/null
+++ b/net/disk_cache/cache_util_unittest.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2010 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.
+
+#include "net/disk_cache/cache_util.h"
+#include "base/file_util.h"
+#include "base/scoped_temp_dir.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace disk_cache {
+
+class CacheUtilTest : public PlatformTest {
+ public:
+ void SetUp() {
+ PlatformTest::SetUp();
+ ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir());
+ cache_dir_ = tmp_dir_.path().Append(FILE_PATH_LITERAL("Cache"));
+ file1_ = FilePath(cache_dir_.Append(FILE_PATH_LITERAL("file01")));
+ file2_ = FilePath(cache_dir_.Append(FILE_PATH_LITERAL(".file02")));
+ dir1_ = FilePath(cache_dir_.Append(FILE_PATH_LITERAL("dir01")));
+ ASSERT_TRUE(file_util::CreateDirectory(cache_dir_));
+ FILE *fp = file_util::OpenFile(file1_, "w");
+ ASSERT_TRUE(fp != NULL);
+ file_util::CloseFile(fp);
+ fp = file_util::OpenFile(file2_, "w");
+ ASSERT_TRUE(fp != NULL);
+ file_util::CloseFile(fp);
+ ASSERT_TRUE(file_util::CreateDirectory(dir1_));
+ dest_dir_ = tmp_dir_.path().Append(FILE_PATH_LITERAL("old_Cache_001"));
+ dest_file1_ = FilePath(dest_dir_.Append(FILE_PATH_LITERAL("file01")));
+ dest_file2_ = FilePath(dest_dir_.Append(FILE_PATH_LITERAL(".file02")));
+ dest_dir1_ = FilePath(dest_dir_.Append(FILE_PATH_LITERAL("dir01")));
+ }
+
+ protected:
+ ScopedTempDir tmp_dir_;
+ FilePath cache_dir_;
+ FilePath file1_;
+ FilePath file2_;
+ FilePath dir1_;
+ FilePath dest_dir_;
+ FilePath dest_file1_;
+ FilePath dest_file2_;
+ FilePath dest_dir1_;
+};
+
+TEST_F(CacheUtilTest, MoveCache) {
+ EXPECT_TRUE(disk_cache::MoveCache(cache_dir_, dest_dir_));
+ EXPECT_TRUE(file_util::PathExists(dest_dir_));
+ EXPECT_TRUE(file_util::PathExists(dest_file1_));
+ EXPECT_TRUE(file_util::PathExists(dest_file2_));
+ EXPECT_TRUE(file_util::PathExists(dest_dir1_));
+#if defined(OS_CHROMEOS)
+ EXPECT_TRUE(file_util::PathExists(cache_dir_)); // old cache dir stays
+#else
+ EXPECT_FALSE(file_util::PathExists(cache_dir_)); // old cache is gone
+#endif
+ EXPECT_FALSE(file_util::PathExists(file1_));
+ EXPECT_FALSE(file_util::PathExists(file2_));
+ EXPECT_FALSE(file_util::PathExists(dir1_));
+}
+
+TEST_F(CacheUtilTest, DeleteCache) {
+ // DeleteCache won't delete subdirs, so let's not start with this
+ // one around.
+ file_util::Delete(dir1_, false);
+ disk_cache::DeleteCache(cache_dir_, false);
+ EXPECT_TRUE(file_util::PathExists(cache_dir_)); // cache dir stays
+ EXPECT_FALSE(file_util::PathExists(file1_));
+ EXPECT_FALSE(file_util::PathExists(file2_));
+}
+
+TEST_F(CacheUtilTest, DeleteCacheAndDir) {
+ // DeleteCache won't delete subdirs, so let's not start with this
+ // one around.
+ file_util::Delete(dir1_, false);
+ disk_cache::DeleteCache(cache_dir_, true);
+ EXPECT_FALSE(file_util::PathExists(cache_dir_)); // cache dir is gone
+ EXPECT_FALSE(file_util::PathExists(file1_));
+ EXPECT_FALSE(file_util::PathExists(file2_));
+}
+
+TEST_F(CacheUtilTest, DeleteCacheFile) {
+ EXPECT_TRUE(disk_cache::DeleteCacheFile(file1_));
+ EXPECT_FALSE(file_util::PathExists(file1_));
+ EXPECT_TRUE(file_util::PathExists(cache_dir_)); // cache dir stays
+}
+
+} // namespace disk_cache
diff --git a/net/disk_cache/cache_util_win.cc b/net/disk_cache/cache_util_win.cc
index 3e1d6730..cbe6b870 100644
--- a/net/disk_cache/cache_util_win.cc
+++ b/net/disk_cache/cache_util_win.cc
@@ -8,7 +8,6 @@
#include "base/logging.h"
#include "base/message_loop.h"
-#include "base/scoped_handle.h"
#include "base/file_util.h"
namespace {
@@ -19,8 +18,8 @@ void DeleteFiles(const wchar_t* path, const wchar_t* search_name) {
file_util::AppendToPath(&name, search_name);
WIN32_FIND_DATA data;
- ScopedFindFileHandle handle(FindFirstFile(name.c_str(), &data));
- if (!handle.IsValid())
+ HANDLE handle = FindFirstFile(name.c_str(), &data);
+ if (handle == INVALID_HANDLE_VALUE)
return;
std::wstring adjusted_path(path);
@@ -33,6 +32,8 @@ void DeleteFiles(const wchar_t* path, const wchar_t* search_name) {
current += data.cFileName;
DeleteFile(current.c_str());
} while (FindNextFile(handle, &data));
+
+ FindClose(handle);
}
} // namespace
diff --git a/net/disk_cache/disk_cache_test_util.cc b/net/disk_cache/disk_cache_test_util.cc
index 7dd618a7..76690e66 100644
--- a/net/disk_cache/disk_cache_test_util.cc
+++ b/net/disk_cache/disk_cache_test_util.cc
@@ -125,6 +125,10 @@ ScopedTestCache::~ScopedTestCache() {
volatile int g_cache_tests_received = 0;
volatile bool g_cache_tests_error = 0;
+CallbackTest::CallbackTest(bool reuse) : result_(-1), reuse_(reuse ? 0 : 1) {}
+
+CallbackTest::~CallbackTest() {}
+
// On the actual callback, increase the number of tests received and check for
// errors (an unexpected test received)
void CallbackTest::RunWithParams(const Tuple1<int>& params) {
diff --git a/net/disk_cache/disk_cache_test_util.h b/net/disk_cache/disk_cache_test_util.h
index f6348e9a..a0dbf21c 100644
--- a/net/disk_cache/disk_cache_test_util.h
+++ b/net/disk_cache/disk_cache_test_util.h
@@ -58,8 +58,8 @@ class ScopedTestCache {
// with multiple simultaneous IO operations.
class CallbackTest : public CallbackRunner< Tuple1<int> > {
public:
- explicit CallbackTest(bool reuse) : result_(-1), reuse_(reuse ? 0 : 1) {}
- ~CallbackTest() {}
+ explicit CallbackTest(bool reuse);
+ virtual ~CallbackTest();
virtual void RunWithParams(const Tuple1<int>& params);
int result() const { return result_; }
diff --git a/net/disk_cache/disk_format.cc b/net/disk_cache/disk_format.cc
new file mode 100644
index 00000000..5216b502
--- /dev/null
+++ b/net/disk_cache/disk_format.cc
@@ -0,0 +1,21 @@
+// Copyright (c) 2010 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.
+
+#include "net/disk_cache/disk_format.h"
+
+namespace disk_cache {
+
+IndexHeader::IndexHeader() {
+ memset(this, 0, sizeof(*this));
+ magic = kIndexMagic;
+ version = kCurrentVersion;
+}
+
+BlockFileHeader::BlockFileHeader() {
+ memset(this, 0, sizeof(BlockFileHeader));
+ magic = kBlockMagic;
+ version = kCurrentVersion;
+}
+
+} // namespace disk_cache
diff --git a/net/disk_cache/disk_format.h b/net/disk_cache/disk_format.h
index ac4c6348..ffe36aed 100644
--- a/net/disk_cache/disk_format.h
+++ b/net/disk_cache/disk_format.h
@@ -80,6 +80,8 @@ struct LruData {
// Header for the master index file.
struct IndexHeader {
+ IndexHeader();
+
uint32 magic;
uint32 version;
int32 num_entries; // Number of entries currently stored.
@@ -93,11 +95,6 @@ struct IndexHeader {
uint64 create_time; // Creation time for this set of files.
int32 pad[52];
LruData lru; // Eviction control data.
- IndexHeader() {
- memset(this, 0, sizeof(*this));
- magic = kIndexMagic;
- version = kCurrentVersion;
- };
};
// The structure of the whole index file.
@@ -177,6 +174,8 @@ typedef uint32 AllocBitmap[kMaxBlocks / 32];
// from the beginning every time).
// This Structure is the header of a block-file:
struct BlockFileHeader {
+ BlockFileHeader();
+
uint32 magic;
uint32 version;
int16 this_file; // Index of this file.
@@ -189,11 +188,6 @@ struct BlockFileHeader {
volatile int32 updating; // Keep track of updates to the header.
int32 user[5];
AllocBitmap allocation_map;
- BlockFileHeader() {
- memset(this, 0, sizeof(BlockFileHeader));
- magic = kBlockMagic;
- version = kCurrentVersion;
- };
};
COMPILE_ASSERT(sizeof(BlockFileHeader) == kBlockHeaderSize, bad_header);
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index 0655b28d..7fabbe57 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -4,8 +4,8 @@
#include "net/disk_cache/entry_impl.h"
-#include "base/histogram.h"
#include "base/message_loop.h"
+#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
@@ -593,8 +593,10 @@ int EntryImpl::WriteDataImpl(int index, int offset, net::IOBuffer* buf,
}
Addr address(entry_.Data()->data_addr[index]);
- if (truncate && offset + buf_len == 0) {
- DCHECK(!address.is_initialized());
+ if (offset + buf_len == 0) {
+ if (truncate) {
+ DCHECK(!address.is_initialized());
+ }
return 0;
}
@@ -1010,6 +1012,9 @@ bool EntryImpl::PrepareTarget(int index, int offset, int buf_len,
if (truncate)
return HandleTruncation(index, offset, buf_len);
+ if (!offset && !buf_len)
+ return true;
+
Addr address(entry_.Data()->data_addr[index]);
if (address.is_initialized()) {
if (address.is_block_file() && !MoveToLocalBuffer(index))
@@ -1169,7 +1174,7 @@ bool EntryImpl::Flush(int index, int min_len) {
DCHECK(!address.is_initialized() || address.is_separate_file());
int size = std::max(entry_.Data()->data_size[index], min_len);
- if (!address.is_initialized() && !CreateDataBlock(index, size))
+ if (size && !address.is_initialized() && !CreateDataBlock(index, size))
return false;
if (!entry_.Data()->data_size[index]) {
diff --git a/net/disk_cache/file.cc b/net/disk_cache/file.cc
new file mode 100644
index 00000000..6b569518
--- /dev/null
+++ b/net/disk_cache/file.cc
@@ -0,0 +1,16 @@
+// Copyright (c) 2010 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.
+
+#include "net/disk_cache/file.h"
+
+namespace disk_cache {
+
+// Cross platform constructors. Platform specific code is in
+// file_{win,posix}.cc.
+
+File::File() : init_(false), mixed_(false) {}
+
+File::File(bool mixed_mode) : init_(false), mixed_(mixed_mode) {}
+
+} // namespace disk_cache
diff --git a/net/disk_cache/file.h b/net/disk_cache/file.h
index 43ba5c1b..c2663113 100644
--- a/net/disk_cache/file.h
+++ b/net/disk_cache/file.h
@@ -29,9 +29,9 @@ class FileIOCallback {
class File : public base::RefCounted<File> {
friend class base::RefCounted<File>;
public:
- File() : init_(false), mixed_(false) {}
+ File();
// mixed_mode set to true enables regular synchronous operations for the file.
- explicit File(bool mixed_mode) : init_(false), mixed_(mixed_mode) {}
+ explicit File(bool mixed_mode);
// Initializes the object to use the passed in file instead of opening it with
// the Init() call. No asynchronous operations can be performed with this
diff --git a/net/disk_cache/file_posix.cc b/net/disk_cache/file_posix.cc
index 44d74e73..9d810c7c 100644
--- a/net/disk_cache/file_posix.cc
+++ b/net/disk_cache/file_posix.cc
@@ -250,7 +250,10 @@ void InFlightIO::InvokeCallback(BackgroundIO* operation, bool cancel_task) {
namespace disk_cache {
File::File(base::PlatformFile file)
- : init_(true), mixed_(true), platform_file_(file) {
+ : init_(true),
+ mixed_(true),
+ platform_file_(file),
+ sync_platform_file_(base::kInvalidPlatformFileValue) {
}
bool File::Init(const FilePath& name) {
diff --git a/net/disk_cache/histogram_macros.h b/net/disk_cache/histogram_macros.h
index 2505a8a7..044302c6 100644
--- a/net/disk_cache/histogram_macros.h
+++ b/net/disk_cache/histogram_macros.h
@@ -20,10 +20,11 @@
#define CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \
do { \
- static scoped_refptr<Histogram> counter; \
+ static scoped_refptr<base::Histogram> counter; \
if (!counter || name != counter->histogram_name()) \
- counter = Histogram::FactoryGet(name, min, max, bucket_count, \
- Histogram::kUmaTargetedHistogramFlag); \
+ counter = base::Histogram::FactoryGet( \
+ name, min, max, bucket_count, \
+ base::Histogram::kUmaTargetedHistogramFlag); \
counter->Add(sample); \
} while (0)
@@ -38,10 +39,11 @@
#define CACHE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \
do { \
- static scoped_refptr<Histogram> counter; \
+ static scoped_refptr<base::Histogram> counter; \
if (!counter || name != counter->histogram_name()) \
- counter = Histogram::FactoryTimeGet(name, min, max, bucket_count, \
- Histogram::kUmaTargetedHistogramFlag); \
+ counter = base::Histogram::FactoryTimeGet( \
+ name, min, max, bucket_count, \
+ base::Histogram::kUmaTargetedHistogramFlag); \
counter->AddTime(sample); \
} while (0)
@@ -50,11 +52,11 @@
base::TimeDelta::FromSeconds(10), 50)
#define CACHE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \
- static scoped_refptr<Histogram> counter; \
+ static scoped_refptr<base::Histogram> counter; \
if (!counter || name != counter->histogram_name()) \
- counter = LinearHistogram::FactoryGet( \
+ counter = base::LinearHistogram::FactoryGet( \
name, 1, boundary_value, boundary_value + 1, \
- Histogram::kUmaTargetedHistogramFlag); \
+ base::Histogram::kUmaTargetedHistogramFlag); \
counter->Add(sample); \
} while (0)
@@ -70,12 +72,13 @@
// HISTOGRAM_AGE will collect time elapsed since |initial_time|, with a
// granularity of hours and normal values of a few months.
#define CACHE_HISTOGRAM_AGE(name, initial_time) \
- CACHE_HISTOGRAM_COUNTS_10000(name, (Time::Now() - initial_time).InHours())
+ CACHE_HISTOGRAM_COUNTS_10000(name, \
+ (base::Time::Now() - initial_time).InHours())
// HISTOGRAM_AGE_MS will collect time elapsed since |initial_time|, with the
// normal resolution of the UMA_HISTOGRAM_TIMES.
#define CACHE_HISTOGRAM_AGE_MS(name, initial_time)\
- CACHE_HISTOGRAM_TIMES(name, TimeTicks::Now() - initial_time)
+ CACHE_HISTOGRAM_TIMES(name, base::TimeTicks::Now() - initial_time)
#define CACHE_HISTOGRAM_CACHE_ERROR(name, sample) \
CACHE_HISTOGRAM_ENUMERATION(name, sample, 50)
diff --git a/net/disk_cache/in_flight_backend_io.cc b/net/disk_cache/in_flight_backend_io.cc
index e400ac3b..fe538292 100644
--- a/net/disk_cache/in_flight_backend_io.cc
+++ b/net/disk_cache/in_flight_backend_io.cc
@@ -181,6 +181,8 @@ void BackendIO::ReadyForSparseIO(EntryImpl* entry) {
entry_ = entry;
}
+BackendIO::~BackendIO() {}
+
// Runs on the background thread.
void BackendIO::ExecuteBackendOperation() {
switch (operation_) {
diff --git a/net/disk_cache/in_flight_backend_io.h b/net/disk_cache/in_flight_backend_io.h
index 889fb201..5eba1311 100644
--- a/net/disk_cache/in_flight_backend_io.h
+++ b/net/disk_cache/in_flight_backend_io.h
@@ -104,7 +104,7 @@ class BackendIO : public BackgroundIO {
OP_IS_READY
};
- ~BackendIO() {}
+ ~BackendIO();
void ExecuteBackendOperation();
void ExecuteEntryOperation();
diff --git a/net/disk_cache/mapped_file_unittest.cc b/net/disk_cache/mapped_file_unittest.cc
index 8b01a7d4..58026713 100644
--- a/net/disk_cache/mapped_file_unittest.cc
+++ b/net/disk_cache/mapped_file_unittest.cc
@@ -36,28 +36,6 @@ void FileCallbackTest::OnFileIOComplete(int bytes_copied) {
g_cache_tests_received++;
}
-// Wait up to 2 secs without callbacks, or until we receive expected callbacks.
-void WaitForCallbacks(int expected) {
- if (!expected)
- return;
-
-#if defined(OS_WIN)
- int iterations = 0;
- int last = 0;
- while (iterations < 40) {
- SleepEx(50, TRUE);
- if (expected == g_cache_tests_received)
- return;
- if (last == g_cache_tests_received)
- iterations++;
- else
- iterations = 0;
- }
-#elif defined(OS_POSIX)
- // TODO(rvargas): Do something when async IO is implemented.
-#endif
-}
-
} // namespace
TEST_F(DiskCacheTest, MappedFile_SyncIO) {
diff --git a/net/disk_cache/mem_backend_impl.cc b/net/disk_cache/mem_backend_impl.cc
index b5064b27..96c615e3 100644
--- a/net/disk_cache/mem_backend_impl.cc
+++ b/net/disk_cache/mem_backend_impl.cc
@@ -65,6 +65,8 @@ bool MemBackendImpl::Init() {
return true;
}
+MemBackendImpl::MemBackendImpl() : max_size_(0), current_size_(0) {}
+
MemBackendImpl::~MemBackendImpl() {
EntryMap::iterator it = entries_.begin();
while (it != entries_.end()) {
diff --git a/net/disk_cache/mem_backend_impl.h b/net/disk_cache/mem_backend_impl.h
index 62ed3c50..c78c6701 100644
--- a/net/disk_cache/mem_backend_impl.h
+++ b/net/disk_cache/mem_backend_impl.h
@@ -21,7 +21,7 @@ class MemEntryImpl;
// the operations of the cache without writing to disk.
class MemBackendImpl : public Backend {
public:
- MemBackendImpl() : max_size_(0), current_size_(0) {}
+ MemBackendImpl();
~MemBackendImpl();
// Returns an instance of a Backend implemented only in memory. The returned
diff --git a/net/disk_cache/rankings.cc b/net/disk_cache/rankings.cc
index e7c67361..1e9e06b6 100644
--- a/net/disk_cache/rankings.cc
+++ b/net/disk_cache/rankings.cc
@@ -4,7 +4,7 @@
#include "net/disk_cache/rankings.h"
-#include "base/histogram.h"
+#include "base/metrics/histogram.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/entry_impl.h"
#include "net/disk_cache/errors.h"
@@ -65,6 +65,7 @@ enum CrashLocation {
ON_REMOVE_3, ON_REMOVE_4, ON_REMOVE_5, ON_REMOVE_6, ON_REMOVE_7, ON_REMOVE_8
};
+#ifndef NDEBUG
void TerminateSelf() {
#if defined(OS_WIN)
// Windows does more work on _exit() than we would like, so we force exit.
@@ -75,6 +76,7 @@ void TerminateSelf() {
_exit(0);
#endif
}
+#endif // NDEBUG
// Generates a crash on debug builds, acording to the value of g_rankings_crash.
// This used by crash_cache.exe to generate unit-test files.
diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc
index 2934184e..e94a1bc9 100644
--- a/net/disk_cache/sparse_control.cc
+++ b/net/disk_cache/sparse_control.cc
@@ -142,6 +142,17 @@ void ChildrenDeleter::DeleteChildren() {
namespace disk_cache {
+SparseControl::SparseControl(EntryImpl* entry)
+ : entry_(entry),
+ child_(NULL),
+ operation_(kNoOperation),
+ init_(false),
+ child_map_(child_data_.bitmap, kNumSparseBits, kNumSparseBits / 32),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ child_callback_(this, &SparseControl::OnChildIOCompleted)),
+ user_callback_(NULL) {
+}
+
SparseControl::~SparseControl() {
if (child_)
CloseChild();
diff --git a/net/disk_cache/sparse_control.h b/net/disk_cache/sparse_control.h
index 88a012b5..15704df0 100644
--- a/net/disk_cache/sparse_control.h
+++ b/net/disk_cache/sparse_control.h
@@ -40,12 +40,7 @@ class SparseControl {
kGetRangeOperation
};
- explicit SparseControl(EntryImpl* entry)
- : entry_(entry), child_(NULL), operation_(kNoOperation), init_(false),
- child_map_(child_data_.bitmap, kNumSparseBits, kNumSparseBits / 32),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- child_callback_(this, &SparseControl::OnChildIOCompleted)),
- user_callback_(NULL) {}
+ explicit SparseControl(EntryImpl* entry);
~SparseControl();
// Initializes the object for the current entry. If this entry already stores
diff --git a/net/disk_cache/stats_histogram.cc b/net/disk_cache/stats_histogram.cc
index e6eaf902..06ed1b32 100644
--- a/net/disk_cache/stats_histogram.cc
+++ b/net/disk_cache/stats_histogram.cc
@@ -9,6 +9,9 @@
namespace disk_cache {
+using base::Histogram;
+using base::StatisticsRecorder;
+
// Static.
const Stats* StatsHistogram::stats_ = NULL;
diff --git a/net/disk_cache/stats_histogram.h b/net/disk_cache/stats_histogram.h
index 1c2e15a9..cbd8f03e 100644
--- a/net/disk_cache/stats_histogram.h
+++ b/net/disk_cache/stats_histogram.h
@@ -8,7 +8,7 @@
#include <string>
-#include "base/histogram.h"
+#include "base/metrics/histogram.h"
namespace disk_cache {
@@ -21,7 +21,7 @@ class Stats;
// Class derivation of Histogram "deprecated," and should not be copied, and
// may eventually go away.
//
-class StatsHistogram : public Histogram {
+class StatsHistogram : public base::Histogram {
public:
class StatsSamples : public SampleSet {
public:
@@ -46,8 +46,6 @@ class StatsHistogram : public Histogram {
virtual void SnapshotSample(SampleSet* sample) const;
private:
- friend class Histogram;
-
bool init_;
static const Stats* stats_;
DISALLOW_COPY_AND_ASSIGN(StatsHistogram);
diff --git a/net/disk_cache/trace.cc b/net/disk_cache/trace.cc
index 9578339c..c16068a6 100644
--- a/net/disk_cache/trace.cc
+++ b/net/disk_cache/trace.cc
@@ -31,6 +31,7 @@ struct TraceBuffer {
char buffer[kNumberOfEntries][kEntrySize];
};
+#if ENABLE_TRACING
void DebugOutput(const char* msg) {
#if defined(OS_WIN)
OutputDebugStringA(msg);
@@ -38,6 +39,7 @@ void DebugOutput(const char* msg) {
NOTIMPLEMENTED();
#endif
}
+#endif // ENABLE_TRACING
} // namespace