summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-27 00:04:24 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-27 00:04:24 +0000
commit9fde2a2f20e1cbd68d88ae5769bb8018b9b4422e (patch)
treea1a7c0a71e057b93275dd29f390cafa3d9dff630 /net/disk_cache
parentefc7057308ae81e69861d37aaca33b67d5187284 (diff)
downloadchromium_src-9fde2a2f20e1cbd68d88ae5769bb8018b9b4422e.zip
chromium_src-9fde2a2f20e1cbd68d88ae5769bb8018b9b4422e.tar.gz
chromium_src-9fde2a2f20e1cbd68d88ae5769bb8018b9b4422e.tar.bz2
Implement sync IO for the disk cache, and temporarily redirect
async IO to be performed synchronously. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/backend_impl.cc7
-rw-r--r--net/disk_cache/backend_unittest.cc41
-rw-r--r--net/disk_cache/cache_util_posix.cc5
-rw-r--r--net/disk_cache/entry_unittest.cc22
-rw-r--r--net/disk_cache/file_posix.cc48
-rw-r--r--net/disk_cache/mapped_file_posix.cc15
-rw-r--r--net/disk_cache/mapped_file_unittest.cc9
-rw-r--r--net/disk_cache/os_file_posix.cc47
-rw-r--r--net/disk_cache/stats.cc3
-rw-r--r--net/disk_cache/storage_block_unittest.cc6
-rw-r--r--net/disk_cache/trace.cc4
11 files changed, 150 insertions, 57 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 943e355..18025a1 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -123,7 +123,12 @@ bool DelayedCacheCleanup(const std::wstring& full_path) {
return false;
}
+#if defined(OS_WIN)
WorkerPool::PostTask(FROM_HERE, new CleanupTask(path, name), true);
+#elif defined(OS_POSIX)
+ // TODO(rvargas): Use the worker pool.
+ MessageLoop::current()->PostTask(FROM_HERE, new CleanupTask(path, name));
+#endif
return true;
}
@@ -757,7 +762,7 @@ bool BackendImpl::InitBackingStore(bool* file_created) {
bool ret = true;
if (*file_created)
ret = CreateBackingStore(file);
-
+
file = NULL;
if (!ret)
return false;
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc
index 754b4c4..bf4140a 100644
--- a/net/disk_cache/backend_unittest.cc
+++ b/net/disk_cache/backend_unittest.cc
@@ -4,6 +4,8 @@
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/platform_thread.h"
+#include "base/string_util.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/disk_cache_test_base.h"
@@ -158,17 +160,17 @@ void DiskCacheBackendTest::BackendKeying() {
entry2->Close();
char buffer[30];
- EXPECT_EQ(0, strcpy_s(buffer, kName1));
+ base::strlcpy(buffer, kName1, sizeof(buffer));
ASSERT_TRUE(cache_->OpenEntry(buffer, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
- EXPECT_EQ(0, strcpy_s(buffer + 1, sizeof(buffer) - 1 , kName1));
+ base::strlcpy(buffer + 1, kName1, sizeof(buffer) - 1);
ASSERT_TRUE(cache_->OpenEntry(buffer + 1, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
- EXPECT_EQ(0, strcpy_s(buffer + 3, sizeof(buffer) - 3, kName1));
+ base::strlcpy(buffer + 3, kName1, sizeof(buffer) - 3);
ASSERT_TRUE(cache_->OpenEntry(buffer + 3, &entry2));
EXPECT_TRUE(entry1 == entry2);
entry2->Close();
@@ -334,8 +336,8 @@ TEST_F(DiskCacheBackendTest, ValidEntry) {
ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
char data[] = "And the data to save";
- EXPECT_EQ(sizeof(data), entry1->WriteData(0, 0, data, sizeof(data), NULL,
- false));
+ EXPECT_TRUE(sizeof(data) == entry1->WriteData(0, 0, data, sizeof(data), NULL,
+ false));
entry1->Close();
SimulateCrash();
@@ -343,7 +345,8 @@ TEST_F(DiskCacheBackendTest, ValidEntry) {
char buffer[40];
memset(buffer, 0, sizeof(buffer));
- EXPECT_EQ(sizeof(data), entry1->ReadData(0, 0, buffer, sizeof(data), NULL));
+ EXPECT_TRUE(sizeof(data) == entry1->ReadData(0, 0, buffer, sizeof(data),
+ NULL));
entry1->Close();
EXPECT_STREQ(data, buffer);
}
@@ -361,8 +364,8 @@ TEST_F(DiskCacheBackendTest, InvalidEntry) {
ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
char data[] = "And the data to save";
- EXPECT_EQ(sizeof(data), entry1->WriteData(0, 0, data, sizeof(data), NULL,
- false));
+ EXPECT_TRUE(sizeof(data) == entry1->WriteData(0, 0, data, sizeof(data), NULL,
+ false));
SimulateCrash();
EXPECT_FALSE(cache_->OpenEntry(key, &entry1));
@@ -381,11 +384,11 @@ TEST_F(DiskCacheBackendTest, InvalidEntryRead) {
ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
char data[] = "And the data to save";
- EXPECT_EQ(sizeof(data), entry1->WriteData(0, 0, data, sizeof(data), NULL,
- false));
+ EXPECT_TRUE(sizeof(data) == entry1->WriteData(0, 0, data, sizeof(data), NULL,
+ false));
entry1->Close();
ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
- EXPECT_EQ(sizeof(data), entry1->ReadData(0, 0, data, sizeof(data), NULL));
+ EXPECT_TRUE(sizeof(data) == entry1->ReadData(0, 0, data, sizeof(data), NULL));
SimulateCrash();
@@ -544,11 +547,11 @@ TEST_F(DiskCacheBackendTest, InvalidEntryEnumeration) {
ASSERT_TRUE(cache_->CreateEntry(key, &entry1));
char data[] = "And the data to save";
- EXPECT_EQ(sizeof(data), entry1->WriteData(0, 0, data, sizeof(data), NULL,
- false));
+ EXPECT_TRUE(sizeof(data) == entry1->WriteData(0, 0, data, sizeof(data), NULL,
+ false));
entry1->Close();
ASSERT_TRUE(cache_->OpenEntry(key, &entry1));
- EXPECT_EQ(sizeof(data), entry1->ReadData(0, 0, data, sizeof(data), NULL));
+ EXPECT_TRUE(sizeof(data) == entry1->ReadData(0, 0, data, sizeof(data), NULL));
std::string key2("Another key");
ASSERT_TRUE(cache_->CreateEntry(key2, &entry2));
@@ -634,7 +637,7 @@ void DiskCacheBackendTest::BackendDoomRecent() {
ASSERT_TRUE(cache_->CreateEntry("second", &entry));
entry->Close();
- Sleep(20);
+ PlatformThread::Sleep(20);
Time middle = Time::Now();
ASSERT_TRUE(cache_->CreateEntry("third", &entry));
@@ -642,7 +645,7 @@ void DiskCacheBackendTest::BackendDoomRecent() {
ASSERT_TRUE(cache_->CreateEntry("fourth", &entry));
entry->Close();
- Sleep(20);
+ PlatformThread::Sleep(20);
Time final = Time::Now();
ASSERT_EQ(4, cache_->GetEntryCount());
@@ -663,7 +666,7 @@ void DiskCacheBackendTest::BackendDoomBetween() {
ASSERT_TRUE(cache_->CreateEntry("first", &entry));
entry->Close();
- Sleep(20);
+ PlatformThread::Sleep(20);
Time middle_start = Time::Now();
ASSERT_TRUE(cache_->CreateEntry("second", &entry));
@@ -671,13 +674,13 @@ void DiskCacheBackendTest::BackendDoomBetween() {
ASSERT_TRUE(cache_->CreateEntry("third", &entry));
entry->Close();
- Sleep(20);
+ PlatformThread::Sleep(20);
Time middle_end = Time::Now();
ASSERT_TRUE(cache_->CreateEntry("fourth", &entry));
entry->Close();
- Sleep(20);
+ PlatformThread::Sleep(20);
Time final = Time::Now();
ASSERT_EQ(4, cache_->GetEntryCount());
diff --git a/net/disk_cache/cache_util_posix.cc b/net/disk_cache/cache_util_posix.cc
index 7e7bc63..708f378 100644
--- a/net/disk_cache/cache_util_posix.cc
+++ b/net/disk_cache/cache_util_posix.cc
@@ -29,8 +29,9 @@ void DeleteCache(const std::wstring& path, bool remove_folder) {
file_util::Delete(path, false);
} else {
std::wstring name(path);
- file_util::AppendToPath(&name, L"*");
- file_util::Delete(name, false);
+ // TODO(rvargas): Fix this after file_util::delete is fixed.
+ // file_util::AppendToPath(&name, L"*");
+ file_util::Delete(name, true);
}
}
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index fd1c551..8d71c44 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/platform_thread.h"
#include "base/timer.h"
+#include "base/string_util.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache_test_base.h"
#include "net/disk_cache/disk_cache_test_util.h"
@@ -37,7 +39,7 @@ void DiskCacheEntryTest::InternalSyncIO() {
char buffer1[10];
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
- strcpy_s(buffer1, "the data");
+ base::strlcpy(buffer1, "the data", sizeof(buffer1));
EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, sizeof(buffer1), NULL, false));
memset(buffer1, 0, sizeof(buffer1));
EXPECT_EQ(10, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
@@ -46,7 +48,7 @@ void DiskCacheEntryTest::InternalSyncIO() {
char buffer2[5000];
char buffer3[10000] = {0};
CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
- strcpy_s(buffer2, "The really big data goes here");
+ base::strlcpy(buffer2, "The really big data goes here", sizeof(buffer2));
EXPECT_EQ(5000, entry1->WriteData(1, 1500, buffer2, sizeof(buffer2), NULL,
false));
memset(buffer2, 0, sizeof(buffer2));
@@ -112,7 +114,7 @@ void DiskCacheEntryTest::InternalAsyncIO() {
CacheTestFillBuffer(buffer3, sizeof(buffer3), false);
EXPECT_EQ(0, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), &callback1));
- strcpy_s(buffer1, "the data");
+ base::strlcpy(buffer1, "the data", sizeof(buffer1));
int expected = 0;
int ret = entry1->WriteData(0, 0, buffer1, sizeof(buffer1), &callback2,
false);
@@ -130,7 +132,7 @@ void DiskCacheEntryTest::InternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_STREQ("the data", buffer2);
- strcpy_s(buffer2, sizeof(buffer2), "The really big data goes here");
+ base::strlcpy(buffer2, "The really big data goes here", sizeof(buffer2));
ret = entry1->WriteData(1, 1500, buffer2, sizeof(buffer2), &callback4, false);
EXPECT_TRUE(5000 == ret || net::ERR_IO_PENDING == ret);
if (net::ERR_IO_PENDING == ret)
@@ -217,14 +219,14 @@ void DiskCacheEntryTest::ExternalSyncIO() {
char buffer1[17000], buffer2[25000];
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
- strcpy_s(buffer1, "the data");
+ base::strlcpy(buffer1, "the data", sizeof(buffer1));
EXPECT_EQ(17000, entry1->WriteData(0, 0, buffer1, sizeof(buffer1), NULL,
false));
memset(buffer1, 0, sizeof(buffer1));
EXPECT_EQ(17000, entry1->ReadData(0, 0, buffer1, sizeof(buffer1), NULL));
EXPECT_STREQ("the data", buffer1);
- strcpy_s(buffer2, "The really big data goes here");
+ base::strlcpy(buffer2, "The really big data goes here", sizeof(buffer2));
EXPECT_EQ(25000, entry1->WriteData(1, 10000, buffer2, sizeof(buffer2), NULL,
false));
memset(buffer2, 0, sizeof(buffer2));
@@ -282,7 +284,7 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
CacheTestFillBuffer(buffer2, sizeof(buffer2), false);
CacheTestFillBuffer(buffer3, sizeof(buffer3), false);
- strcpy_s(buffer1, "the data");
+ base::strlcpy(buffer1, "the data", sizeof(buffer1));
int ret = entry1->WriteData(0, 0, buffer1, sizeof(buffer1), &callback1,
false);
EXPECT_TRUE(17000 == ret || net::ERR_IO_PENDING == ret);
@@ -302,7 +304,7 @@ void DiskCacheEntryTest::ExternalAsyncIO() {
EXPECT_TRUE(helper.WaitUntilCacheIoFinished(expected));
EXPECT_STREQ("the data", buffer1);
- strcpy_s(buffer2, "The really big data goes here");
+ base::strlcpy(buffer2, "The really big data goes here", sizeof(buffer2));
ret = entry1->WriteData(1, 10000, buffer2, sizeof(buffer2), &callback3,
false);
EXPECT_TRUE(25000 == ret || net::ERR_IO_PENDING == ret);
@@ -425,7 +427,7 @@ void DiskCacheEntryTest::GrowData() {
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
memset(buffer2, 0, sizeof(buffer2));
- strcpy_s(buffer1, "the data");
+ base::strlcpy(buffer1, "the data", sizeof(buffer1));
EXPECT_EQ(10, entry1->WriteData(0, 0, buffer1, 10, NULL, false));
EXPECT_EQ(10, entry1->ReadData(0, 0, buffer2, 10, NULL));
EXPECT_STREQ("the data", buffer2);
@@ -722,7 +724,7 @@ void DiskCacheEntryTest::DoomedEntry() {
EXPECT_EQ(0, cache_->GetEntryCount());
Time initial = Time::Now();
- Sleep(20);
+ PlatformThread::Sleep(20);
char buffer1[2000];
char buffer2[2000];
diff --git a/net/disk_cache/file_posix.cc b/net/disk_cache/file_posix.cc
index bd2e779..33866ea 100644
--- a/net/disk_cache/file_posix.cc
+++ b/net/disk_cache/file_posix.cc
@@ -4,21 +4,35 @@
#include "net/disk_cache/file.h"
+#include <fcntl.h>
+
#include "base/logging.h"
#include "net/disk_cache/disk_cache.h"
namespace disk_cache {
File::File(OSFile file)
- : init_(true), os_file_(0) {
+ : init_(true), os_file_(file) {
}
bool File::Init(const std::wstring& name) {
- NOTIMPLEMENTED();
- return false;
+ if (init_)
+ return false;
+
+ os_file_ = CreateOSFile(name, OS_FILE_OPEN | OS_FILE_READ | OS_FILE_WRITE,
+ NULL);
+ if (os_file_ < 0) {
+ os_file_ = 0;
+ return false;
+ }
+
+ init_ = true;
+ return true;
}
File::~File() {
+ if (os_file_)
+ close(os_file_);
}
OSFile File::os_file() const {
@@ -36,8 +50,8 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset) {
if (buffer_len > ULONG_MAX || offset > LONG_MAX)
return false;
- NOTIMPLEMENTED();
- return false;
+ int ret = pread(os_file_, buffer, buffer_len, offset);
+ return (static_cast<size_t>(ret) == buffer_len);
}
bool File::Write(const void* buffer, size_t buffer_len, size_t offset) {
@@ -45,8 +59,8 @@ bool File::Write(const void* buffer, size_t buffer_len, size_t offset) {
if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
return false;
- NOTIMPLEMENTED();
- return false;
+ int ret = pwrite(os_file_, buffer, buffer_len, offset);
+ return (static_cast<size_t>(ret) == buffer_len);
}
// We have to increase the ref counter of the file before performing the IO to
@@ -58,8 +72,11 @@ bool File::Read(void* buffer, size_t buffer_len, size_t offset,
if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
return false;
- NOTIMPLEMENTED();
- return false;
+ // TODO: Implement async IO.
+ bool ret = Read(buffer, buffer_len, offset);
+ if (ret && completed)
+ *completed = true;
+ return ret;
}
bool File::Write(const void* buffer, size_t buffer_len, size_t offset,
@@ -79,8 +96,11 @@ bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset,
if (buffer_len > ULONG_MAX || offset > ULONG_MAX)
return false;
- NOTIMPLEMENTED();
- return false;
+ // TODO: Implement async IO.
+ bool ret = Write(buffer, buffer_len, offset);
+ if (ret && completed)
+ *completed = true;
+ return ret;
}
bool File::SetLength(size_t length) {
@@ -88,13 +108,13 @@ bool File::SetLength(size_t length) {
if (length > ULONG_MAX)
return false;
- NOTIMPLEMENTED();
- return false;
+ return 0 == ftruncate(os_file_, length);
}
size_t File::GetLength() {
DCHECK(init_);
- return 0;
+ size_t ret = lseek(os_file_, 0, SEEK_END);
+ return ret;
}
} // namespace disk_cache
diff --git a/net/disk_cache/mapped_file_posix.cc b/net/disk_cache/mapped_file_posix.cc
index d8f33506..fbcdbaa 100644
--- a/net/disk_cache/mapped_file_posix.cc
+++ b/net/disk_cache/mapped_file_posix.cc
@@ -4,6 +4,9 @@
#include "net/disk_cache/mapped_file.h"
+#include <errno.h>
+#include <sys/mman.h>
+
#include "net/disk_cache/disk_cache.h"
namespace disk_cache {
@@ -13,9 +16,17 @@ void* MappedFile::Init(const std::wstring name, size_t size) {
if (init_ || !File::Init(name))
return NULL;
- buffer_ = NULL;
+ if (!size)
+ size = GetLength();
+
+ buffer_ = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
+ os_file(), 0);
init_ = true;
+ DCHECK(reinterpret_cast<int>(buffer_) != -1);
+ if (reinterpret_cast<int>(buffer_) == -1)
+ buffer_ = 0;
+ view_size_ = size;
return buffer_;
}
@@ -24,6 +35,8 @@ MappedFile::~MappedFile() {
return;
if (buffer_) {
+ int ret = munmap(buffer_, view_size_);
+ DCHECK(0 == ret);
}
}
diff --git a/net/disk_cache/mapped_file_unittest.cc b/net/disk_cache/mapped_file_unittest.cc
index d626ee0..138f3cb 100644
--- a/net/disk_cache/mapped_file_unittest.cc
+++ b/net/disk_cache/mapped_file_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/file_util.h"
+#include "base/string_util.h"
#include "net/disk_cache/disk_cache_test_util.h"
#include "net/disk_cache/mapped_file.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -46,6 +47,7 @@ void WaitForCallbacks(int expected) {
if (!expected)
return;
+#if defined(OS_WIN)
int iterations = 0;
int last = 0;
while (iterations < 40) {
@@ -57,6 +59,9 @@ void WaitForCallbacks(int expected) {
else
iterations = 0;
}
+#elif defined(OS_POSIX)
+ // TODO(rvargas): Do something when async IO is implemented.
+#endif
}
} // namespace
@@ -71,7 +76,7 @@ TEST(DiskCacheTest, MappedFile_SyncIO) {
char buffer1[20];
char buffer2[20];
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
- strcpy_s(buffer1, "the data");
+ base::strlcpy(buffer1, "the data", sizeof(buffer1));
EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 8192));
EXPECT_TRUE(file->Read(buffer2, sizeof(buffer2), 8192));
EXPECT_STREQ(buffer1, buffer2);
@@ -92,7 +97,7 @@ TEST(DiskCacheTest, MappedFile_AsyncIO) {
char buffer1[20];
char buffer2[20];
CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
- strcpy_s(buffer1, "the data");
+ base::strlcpy(buffer1, "the data", sizeof(buffer1));
bool completed;
EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 1024 * 1024, &callback,
&completed));
diff --git a/net/disk_cache/os_file_posix.cc b/net/disk_cache/os_file_posix.cc
index 7b8fe0d..7b1da0b 100644
--- a/net/disk_cache/os_file_posix.cc
+++ b/net/disk_cache/os_file_posix.cc
@@ -4,13 +4,56 @@
#include "net/disk_cache/os_file.h"
+#include <fcntl.h>
+
#include "base/logging.h"
+#include "base/string_util.h"
namespace disk_cache {
OSFile CreateOSFile(const std::wstring& name, int flags, bool* created) {
- NOTIMPLEMENTED();
- return 0;
+ int open_flags = 0;
+ if (flags & OS_FILE_CREATE)
+ open_flags = O_CREAT | O_EXCL;
+
+ if (flags & OS_FILE_CREATE_ALWAYS) {
+ DCHECK(!open_flags);
+ open_flags = O_CREAT | O_TRUNC;
+ }
+
+ if (!open_flags && !(flags & OS_FILE_OPEN) &&
+ !(flags & OS_FILE_OPEN_ALWAYS)) {
+ NOTREACHED();
+ return -1;
+ }
+
+ if (flags & OS_FILE_WRITE && flags & OS_FILE_READ) {
+ open_flags |= O_RDWR;
+ } else if (flags & OS_FILE_WRITE) {
+ open_flags |= O_WRONLY;
+ } else if (!(flags & OS_FILE_READ)) {
+ NOTREACHED();
+ }
+
+ DCHECK(O_RDONLY == 0);
+
+ int descriptor = open(WideToUTF8(name).c_str(), open_flags,
+ S_IRUSR | S_IWUSR);
+
+ if (flags & OS_FILE_OPEN_ALWAYS) {
+ if (descriptor > 0) {
+ if (created)
+ *created = false;
+ } else {
+ open_flags |= O_CREAT;
+ descriptor = open(WideToUTF8(name).c_str(), open_flags,
+ S_IRUSR | S_IWUSR);
+ if (created && descriptor > 0)
+ *created = true;
+ }
+ }
+
+ return descriptor;
}
} // namespace disk_cache
diff --git a/net/disk_cache/stats.cc b/net/disk_cache/stats.cc
index 89062d8b..d57a0bb 100644
--- a/net/disk_cache/stats.cc
+++ b/net/disk_cache/stats.cc
@@ -107,8 +107,6 @@ bool CreateStats(BackendImpl* backend, Addr* address, OnDiskStats* stats) {
}
bool Stats::Init(BackendImpl* backend, uint32* storage_addr) {
- backend_ = backend;
-
OnDiskStats stats;
Addr address(*storage_addr);
if (address.is_initialized()) {
@@ -121,6 +119,7 @@ bool Stats::Init(BackendImpl* backend, uint32* storage_addr) {
}
storage_addr_ = address.value();
+ backend_ = backend;
memcpy(data_sizes_, stats.data_sizes, sizeof(data_sizes_));
memcpy(counters_, stats.counters, sizeof(counters_));
diff --git a/net/disk_cache/storage_block_unittest.cc b/net/disk_cache/storage_block_unittest.cc
index 9734394..fb89d36 100644
--- a/net/disk_cache/storage_block_unittest.cc
+++ b/net/disk_cache/storage_block_unittest.cc
@@ -42,7 +42,7 @@ TEST(DiskCacheTest, StorageBlock_SetData) {
disk_cache::CacheEntryBlock entry2(file, disk_cache::Addr(0xa0010002));
EXPECT_TRUE(entry2.Load());
EXPECT_TRUE(entry2.Data() != NULL);
- EXPECT_EQ(0, entry2.Data()->hash);
+ EXPECT_TRUE(0 == entry2.Data()->hash);
EXPECT_TRUE(entry2.Data() != entry1.Data());
entry2.SetData(entry1.Data());
@@ -60,13 +60,13 @@ TEST(DiskCacheTest, StorageBlock_SetModified) {
disk_cache::CacheEntryBlock* entry1 =
new disk_cache::CacheEntryBlock(file, disk_cache::Addr(0xa0010003));
EXPECT_TRUE(entry1->Load());
- EXPECT_EQ(0, entry1->Data()->hash);
+ EXPECT_TRUE(0 == entry1->Data()->hash);
entry1->Data()->hash = 0x45687912;
entry1->set_modified();
delete entry1;
disk_cache::CacheEntryBlock entry2(file, disk_cache::Addr(0xa0010003));
EXPECT_TRUE(entry2.Load());
- EXPECT_EQ(0x45687912, entry2.Data()->hash);
+ EXPECT_TRUE(0x45687912 == entry2.Data()->hash);
}
diff --git a/net/disk_cache/trace.cc b/net/disk_cache/trace.cc
index c656cef..3aba306 100644
--- a/net/disk_cache/trace.cc
+++ b/net/disk_cache/trace.cc
@@ -70,7 +70,9 @@ void Trace(const char* format, ...) {
#if defined(OS_WIN)
vsprintf_s(s_trace_buffer->buffer[s_trace_buffer->current], format, ap);
#else
- NOTIMPLEMENTED();
+ vsnprintf(s_trace_buffer->buffer[s_trace_buffer->current],
+ sizeof(s_trace_buffer->buffer[s_trace_buffer->current]), format,
+ ap);
#endif
s_trace_buffer->num_traces++;
s_trace_buffer->current++;