summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 17:16:48 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-11 17:16:48 +0000
commit034740aad9bf9e187d92b048a3c5c269673a3741 (patch)
treea7a5201619749081305e94c901405093935fb804 /net/disk_cache
parent183e2f015c27f84cba7972ba978ee96447abd3fc (diff)
downloadchromium_src-034740aad9bf9e187d92b048a3c5c269673a3741.zip
chromium_src-034740aad9bf9e187d92b048a3c5c269673a3741.tar.gz
chromium_src-034740aad9bf9e187d92b048a3c5c269673a3741.tar.bz2
Http Cache: Remove blocking calls to GetAvailableRange.
This seems to be the last piece of the http cache code that should be upgraded to non-blocking APIs. BUG=26729 TEST=unittests Review URL: http://codereview.chromium.org/2663003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49542 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/disk_cache.h10
-rw-r--r--net/disk_cache/entry_impl.cc11
-rw-r--r--net/disk_cache/entry_impl.h3
-rw-r--r--net/disk_cache/entry_unittest.cc48
-rw-r--r--net/disk_cache/mem_entry_impl.cc7
-rw-r--r--net/disk_cache/mem_entry_impl.h3
-rw-r--r--net/disk_cache/sparse_control.cc12
-rw-r--r--net/disk_cache/sparse_control.h6
8 files changed, 94 insertions, 6 deletions
diff --git a/net/disk_cache/disk_cache.h b/net/disk_cache/disk_cache.h
index fab9c91..36151ad 100644
--- a/net/disk_cache/disk_cache.h
+++ b/net/disk_cache/disk_cache.h
@@ -331,6 +331,16 @@ class Entry {
virtual int GetAvailableRange(int64 offset, int len, int64* start,
CompletionCallback* callback) = 0;
+ // Returns true if this entry could be a sparse entry or false otherwise. This
+ // is a quick test that may return true even if the entry is not really
+ // sparse. This method doesn't modify the state of this entry (it will not
+ // create sparse tracking data). GetAvailableRange or ReadSparseData can be
+ // used to perfom a definitive test of wether an existing entry is sparse or
+ // not, but that method may modify the current state of the entry (making it
+ // sparse, for instance). The purpose of this method is to test an existing
+ // entry, but without generating actual IO to perform a thorough check.
+ virtual bool CouldBeSparse() const = 0;
+
// Cancels any pending sparse IO operation (if any). The completion callback
// of the operation in question will still be called when the operation
// finishes, but the operation will finish sooner when this method is used.
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index e643910..1c041d2 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-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.
@@ -391,6 +391,15 @@ int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
return GetAvailableRange(offset, len, start);
}
+bool EntryImpl::CouldBeSparse() const {
+ if (sparse_.get())
+ return true;
+
+ scoped_ptr<SparseControl> sparse;
+ sparse.reset(new SparseControl(const_cast<EntryImpl*>(this)));
+ return sparse->CouldBeSparse();
+}
+
void EntryImpl::CancelSparseIO() {
if (!sparse_.get())
return;
diff --git a/net/disk_cache/entry_impl.h b/net/disk_cache/entry_impl.h
index 294f52fc..9c39223 100644
--- a/net/disk_cache/entry_impl.h
+++ b/net/disk_cache/entry_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-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.
@@ -50,6 +50,7 @@ class EntryImpl : public Entry, public base::RefCounted<EntryImpl> {
virtual int GetAvailableRange(int64 offset, int len, int64* start);
virtual int GetAvailableRange(int64 offset, int len, int64* start,
CompletionCallback* callback);
+ virtual bool CouldBeSparse() const;
virtual void CancelSparseIO();
virtual int ReadyForSparseIO(net::CompletionCallback* completion_callback);
diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc
index c96469a..e2a17b0 100644
--- a/net/disk_cache/entry_unittest.cc
+++ b/net/disk_cache/entry_unittest.cc
@@ -39,6 +39,7 @@ class DiskCacheEntryTest : public DiskCacheTestWithCache {
void BasicSparseIO(bool async);
void HugeSparseIO(bool async);
void GetAvailableRange();
+ void CouldBeSparse();
void DoomSparseEntry();
void PartialSparseEntry();
};
@@ -1063,6 +1064,53 @@ TEST_F(DiskCacheEntryTest, MemoryOnlyGetAvailableRange) {
GetAvailableRange();
}
+void DiskCacheEntryTest::CouldBeSparse() {
+ std::string key("the first key");
+ disk_cache::Entry* entry;
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+
+ const int kSize = 16 * 1024;
+ scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize);
+ CacheTestFillBuffer(buf->data(), kSize, false);
+
+ // Write at offset 0x20F0000 (33 MB - 64 KB).
+ EXPECT_EQ(kSize, entry->WriteSparseData(0x20F0000, buf, kSize, NULL));
+
+ EXPECT_TRUE(entry->CouldBeSparse());
+ entry->Close();
+
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
+ EXPECT_TRUE(entry->CouldBeSparse());
+ entry->Close();
+
+ // Now verify a regular entry.
+ key.assign("another key");
+ ASSERT_EQ(net::OK, CreateEntry(key, &entry));
+ EXPECT_FALSE(entry->CouldBeSparse());
+
+ EXPECT_EQ(kSize, entry->WriteData(0, 0, buf, kSize, NULL, false));
+ EXPECT_EQ(kSize, entry->WriteData(1, 0, buf, kSize, NULL, false));
+ EXPECT_EQ(kSize, entry->WriteData(2, 0, buf, kSize, NULL, false));
+
+ EXPECT_FALSE(entry->CouldBeSparse());
+ entry->Close();
+
+ ASSERT_EQ(net::OK, OpenEntry(key, &entry));
+ EXPECT_FALSE(entry->CouldBeSparse());
+ entry->Close();
+}
+
+TEST_F(DiskCacheEntryTest, CouldBeSparse) {
+ InitCache();
+ CouldBeSparse();
+}
+
+TEST_F(DiskCacheEntryTest, MemoryCouldBeSparse) {
+ SetMemoryOnlyMode();
+ InitCache();
+ CouldBeSparse();
+}
+
TEST_F(DiskCacheEntryTest, MemoryOnlyMisalignedSparseIO) {
SetMemoryOnlyMode();
InitCache();
diff --git a/net/disk_cache/mem_entry_impl.cc b/net/disk_cache/mem_entry_impl.cc
index 002b514..645619e 100644
--- a/net/disk_cache/mem_entry_impl.cc
+++ b/net/disk_cache/mem_entry_impl.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-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.
@@ -312,6 +312,11 @@ int MemEntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
return GetAvailableRange(offset, len, start);
}
+bool MemEntryImpl::CouldBeSparse() const {
+ DCHECK_EQ(kParentEntry, type());
+ return (children_.get() != NULL);
+}
+
int MemEntryImpl::ReadyForSparseIO(
net::CompletionCallback* completion_callback) {
return net::OK;
diff --git a/net/disk_cache/mem_entry_impl.h b/net/disk_cache/mem_entry_impl.h
index cd793a4..8703585 100644
--- a/net/disk_cache/mem_entry_impl.h
+++ b/net/disk_cache/mem_entry_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-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.
@@ -70,6 +70,7 @@ class MemEntryImpl : public Entry {
virtual int GetAvailableRange(int64 offset, int len, int64* start);
virtual int GetAvailableRange(int64 offset, int len, int64* start,
CompletionCallback* callback);
+ virtual bool CouldBeSparse() const;
virtual void CancelSparseIO() {}
virtual int ReadyForSparseIO(net::CompletionCallback* completion_callback);
diff --git a/net/disk_cache/sparse_control.cc b/net/disk_cache/sparse_control.cc
index 612d06c..e521c3e 100644
--- a/net/disk_cache/sparse_control.cc
+++ b/net/disk_cache/sparse_control.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009-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.
@@ -166,6 +166,16 @@ int SparseControl::Init() {
return rv;
}
+bool SparseControl::CouldBeSparse() const {
+ DCHECK(!init_);
+
+ if (entry_->GetDataSize(kSparseData))
+ return false;
+
+ // We don't verify the data, just see if it could be there.
+ return (entry_->GetDataSize(kSparseIndex) != 0);
+}
+
int SparseControl::StartIO(SparseOperation op, int64 offset, net::IOBuffer* buf,
int buf_len, net::CompletionCallback* callback) {
DCHECK(init_);
diff --git a/net/disk_cache/sparse_control.h b/net/disk_cache/sparse_control.h
index 0005f58..ee77b4b 100644
--- a/net/disk_cache/sparse_control.h
+++ b/net/disk_cache/sparse_control.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009-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.
@@ -52,6 +52,10 @@ class SparseControl {
// on disk and returns net::OK. Otherwise it returns a net error code.
int Init();
+ // Performs a quick test to see if the entry is sparse or not, without
+ // generating disk IO (so the answer provided is only a best effort).
+ bool CouldBeSparse() const;
+
// Performs an actual sparse read or write operation for this entry. |op| is
// the operation to perform, |offset| is the desired sparse offset, |buf| and
// |buf_len| specify the actual data to use and |callback| is the callback