summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-17 01:03:10 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-17 01:03:10 +0000
commit2a5ee419abd76128acb21d5395393e3d70c17ae3 (patch)
treea5687fbbce310542b6641811cba7c7b4d99373ce
parent2bd930265ee663668e49d41eb35fddd94934eae2 (diff)
downloadchromium_src-2a5ee419abd76128acb21d5395393e3d70c17ae3.zip
chromium_src-2a5ee419abd76128acb21d5395393e3d70c17ae3.tar.gz
chromium_src-2a5ee419abd76128acb21d5395393e3d70c17ae3.tar.bz2
Disk cache: Final code cleanup from the thread switch.
No code change. BUG=26730 TEST=none Review URL: http://codereview.chromium.org/3005006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52792 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/disk_cache/backend_impl.cc278
-rw-r--r--net/disk_cache/entry_impl.cc16
2 files changed, 147 insertions, 147 deletions
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 92a4ae3..c8f4a25 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -334,6 +334,122 @@ int BackendImpl::CreateBackend(const FilePath& full_path, bool force,
return creator->Run();
}
+int BackendImpl::Init(CompletionCallback* callback) {
+ background_queue_.Init(callback);
+ return net::ERR_IO_PENDING;
+}
+
+BackendImpl::~BackendImpl() {
+ background_queue_.WaitForPendingIO();
+
+ if (background_queue_.BackgroundIsCurrentThread()) {
+ // Unit tests may use the same thread for everything.
+ CleanupCache();
+ } else {
+ background_queue_.background_thread()->PostTask(FROM_HERE,
+ new FinalCleanup(this));
+ done_.Wait();
+ }
+}
+
+// ------------------------------------------------------------------------
+
+int32 BackendImpl::GetEntryCount() const {
+ if (!index_)
+ return 0;
+ // num_entries includes entries already evicted.
+ int32 not_deleted = data_->header.num_entries -
+ data_->header.lru.sizes[Rankings::DELETED];
+
+ if (not_deleted < 0) {
+ NOTREACHED();
+ not_deleted = 0;
+ }
+
+ return not_deleted;
+}
+
+int BackendImpl::OpenEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.OpenEntry(key, entry, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::CreateEntry(const std::string& key, Entry** entry,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.CreateEntry(key, entry, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::DoomEntry(const std::string& key,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.DoomEntry(key, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::DoomAllEntries(CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.DoomAllEntries(callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::DoomEntriesBetween(const base::Time initial_time,
+ const base::Time end_time,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.DoomEntriesBetween(initial_time, end_time, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::DoomEntriesSince(const base::Time initial_time,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.DoomEntriesSince(initial_time, callback);
+ return net::ERR_IO_PENDING;
+}
+
+int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry,
+ CompletionCallback* callback) {
+ DCHECK(callback);
+ background_queue_.OpenNextEntry(iter, next_entry, callback);
+ return net::ERR_IO_PENDING;
+}
+
+void BackendImpl::EndEnumeration(void** iter) {
+ background_queue_.EndEnumeration(*iter);
+ *iter = NULL;
+}
+
+void BackendImpl::GetStats(StatsItems* stats) {
+ if (disabled_)
+ return;
+
+ std::pair<std::string, std::string> item;
+
+ item.first = "Entries";
+ item.second = StringPrintf("%d", data_->header.num_entries);
+ stats->push_back(item);
+
+ item.first = "Pending IO";
+ item.second = StringPrintf("%d", num_pending_io_);
+ stats->push_back(item);
+
+ item.first = "Max size";
+ item.second = StringPrintf("%d", max_size_);
+ stats->push_back(item);
+
+ item.first = "Current size";
+ item.second = StringPrintf("%d", data_->header.num_bytes);
+ stats->push_back(item);
+
+ stats_.GetItems(stats);
+}
+
+// ------------------------------------------------------------------------
+
int BackendImpl::SyncInit() {
DCHECK(!init_);
if (init_)
@@ -409,53 +525,39 @@ int BackendImpl::SyncInit() {
return disabled_ ? net::ERR_FAILED : net::OK;
}
-int BackendImpl::Init(CompletionCallback* callback) {
- background_queue_.Init(callback);
- return net::ERR_IO_PENDING;
-}
-
-BackendImpl::~BackendImpl() {
- background_queue_.WaitForPendingIO();
+void BackendImpl::CleanupCache() {
+ Trace("Backend Cleanup");
+ if (init_) {
+ if (data_)
+ data_->header.crash = 0;
- if (background_queue_.BackgroundIsCurrentThread()) {
- // Unit tests may use the same thread for everything.
- CleanupCache();
- } else {
- background_queue_.background_thread()->PostTask(FROM_HERE,
- new FinalCleanup(this));
- done_.Wait();
+ timer_.Stop();
+ File::WaitForPendingIO(&num_pending_io_);
+ DCHECK(!num_refs_);
}
+ factory_.RevokeAll();
+ done_.Signal();
}
// ------------------------------------------------------------------------
-int32 BackendImpl::GetEntryCount() const {
- if (!index_)
- return 0;
- // num_entries includes entries already evicted.
- int32 not_deleted = data_->header.num_entries -
- data_->header.lru.sizes[Rankings::DELETED];
-
- if (not_deleted < 0) {
- NOTREACHED();
- not_deleted = 0;
- }
-
- return not_deleted;
-}
-
-int BackendImpl::OpenEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback) {
+int BackendImpl::OpenPrevEntry(void** iter, Entry** prev_entry,
+ CompletionCallback* callback) {
DCHECK(callback);
- background_queue_.OpenEntry(key, entry, callback);
+ background_queue_.OpenPrevEntry(iter, prev_entry, callback);
return net::ERR_IO_PENDING;
}
-int BackendImpl::CreateEntry(const std::string& key, Entry** entry,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.CreateEntry(key, entry, callback);
- return net::ERR_IO_PENDING;
+int BackendImpl::SyncOpenEntry(const std::string& key, Entry** entry) {
+ DCHECK(entry);
+ *entry = OpenEntryImpl(key);
+ return (*entry) ? net::OK : net::ERR_FAILED;
+}
+
+int BackendImpl::SyncCreateEntry(const std::string& key, Entry** entry) {
+ DCHECK(entry);
+ *entry = CreateEntryImpl(key);
+ return (*entry) ? net::OK : net::ERR_FAILED;
}
int BackendImpl::SyncDoomEntry(const std::string& key) {
@@ -471,13 +573,6 @@ int BackendImpl::SyncDoomEntry(const std::string& key) {
return net::OK;
}
-int BackendImpl::DoomEntry(const std::string& key,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.DoomEntry(key, callback);
- return net::ERR_IO_PENDING;
-}
-
int BackendImpl::SyncDoomAllEntries() {
if (!num_refs_) {
PrepareForRestart();
@@ -493,12 +588,6 @@ int BackendImpl::SyncDoomAllEntries() {
}
}
-int BackendImpl::DoomAllEntries(CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.DoomAllEntries(callback);
- return net::ERR_IO_PENDING;
-}
-
int BackendImpl::SyncDoomEntriesBetween(const base::Time initial_time,
const base::Time end_time) {
if (end_time.is_null())
@@ -535,14 +624,6 @@ int BackendImpl::SyncDoomEntriesBetween(const base::Time initial_time,
return net::OK;
}
-int BackendImpl::DoomEntriesBetween(const base::Time initial_time,
- const base::Time end_time,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.DoomEntriesBetween(initial_time, end_time, callback);
- return net::ERR_IO_PENDING;
-}
-
// We use OpenNextEntryImpl to retrieve elements from the cache, until we get
// entries that are too old.
int BackendImpl::SyncDoomEntriesSince(const base::Time initial_time) {
@@ -567,87 +648,6 @@ int BackendImpl::SyncDoomEntriesSince(const base::Time initial_time) {
}
}
-int BackendImpl::DoomEntriesSince(const base::Time initial_time,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.DoomEntriesSince(initial_time, callback);
- return net::ERR_IO_PENDING;
-}
-
-int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.OpenNextEntry(iter, next_entry, callback);
- return net::ERR_IO_PENDING;
-}
-
-void BackendImpl::EndEnumeration(void** iter) {
- background_queue_.EndEnumeration(*iter);
- *iter = NULL;
-}
-
-void BackendImpl::GetStats(StatsItems* stats) {
- if (disabled_)
- return;
-
- std::pair<std::string, std::string> item;
-
- item.first = "Entries";
- item.second = StringPrintf("%d", data_->header.num_entries);
- stats->push_back(item);
-
- item.first = "Pending IO";
- item.second = StringPrintf("%d", num_pending_io_);
- stats->push_back(item);
-
- item.first = "Max size";
- item.second = StringPrintf("%d", max_size_);
- stats->push_back(item);
-
- item.first = "Current size";
- item.second = StringPrintf("%d", data_->header.num_bytes);
- stats->push_back(item);
-
- stats_.GetItems(stats);
-}
-
-// ------------------------------------------------------------------------
-
-void BackendImpl::CleanupCache() {
- Trace("Backend Cleanup");
- if (init_) {
- if (data_)
- data_->header.crash = 0;
-
- timer_.Stop();
- File::WaitForPendingIO(&num_pending_io_);
- DCHECK(!num_refs_);
- }
- factory_.RevokeAll();
- done_.Signal();
-}
-
-// ------------------------------------------------------------------------
-
-int BackendImpl::OpenPrevEntry(void** iter, Entry** prev_entry,
- CompletionCallback* callback) {
- DCHECK(callback);
- background_queue_.OpenPrevEntry(iter, prev_entry, callback);
- return net::ERR_IO_PENDING;
-}
-
-int BackendImpl::SyncOpenEntry(const std::string& key, Entry** entry) {
- DCHECK(entry);
- *entry = OpenEntryImpl(key);
- return (*entry) ? net::OK : net::ERR_FAILED;
-}
-
-int BackendImpl::SyncCreateEntry(const std::string& key, Entry** entry) {
- DCHECK(entry);
- *entry = CreateEntryImpl(key);
- return (*entry) ? net::OK : net::ERR_FAILED;
-}
-
int BackendImpl::SyncOpenNextEntry(void** iter, Entry** next_entry) {
*next_entry = OpenNextEntryImpl(iter);
return (*next_entry) ? net::OK : net::ERR_FAILED;
diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc
index c0e7270..a017549 100644
--- a/net/disk_cache/entry_impl.cc
+++ b/net/disk_cache/entry_impl.cc
@@ -241,14 +241,6 @@ int EntryImpl::WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
return net::ERR_IO_PENDING;
}
-int EntryImpl::GetAvailableRangeImpl(int64 offset, int len, int64* start) {
- int result = InitSparseData();
- if (net::OK != result)
- return result;
-
- return sparse_->GetAvailableRange(offset, len, start);
-}
-
int EntryImpl::GetAvailableRange(int64 offset, int len, int64* start,
CompletionCallback* callback) {
backend_->background_queue()->GetAvailableRange(this, offset, len, start,
@@ -479,6 +471,14 @@ int EntryImpl::WriteSparseDataImpl(int64 offset, net::IOBuffer* buf,
return result;
}
+int EntryImpl::GetAvailableRangeImpl(int64 offset, int len, int64* start) {
+ int result = InitSparseData();
+ if (net::OK != result)
+ return result;
+
+ return sparse_->GetAvailableRange(offset, len, start);
+}
+
void EntryImpl::CancelSparseIOImpl() {
if (!sparse_.get())
return;