Commit 7e369217 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Reduce scope of waitable event in disk_cache BackendImpl

This is a step forward to remove the waitable event.
This CL is removing the Waitable event member and reducing
its scope only to the destructor (where it is used).

R=gab@chromium.org

Bug: 1065004
Change-Id: I7a813c09a52ccd428c64631bd81fc8a5d710c880
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132766Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756335}
parent a1c88d09
......@@ -110,8 +110,10 @@ bool InitExperiment(disk_cache::IndexHeader* header, bool cache_created) {
}
// A callback to perform final cleanup on the background thread.
void FinalCleanupCallback(disk_cache::BackendImpl* backend) {
void FinalCleanupCallback(disk_cache::BackendImpl* backend,
base::WaitableEvent* done) {
backend->CleanupCache();
done->Signal();
}
class CacheThread : public base::Thread {
......@@ -159,9 +161,7 @@ BackendImpl::BackendImpl(
block_files_(path),
mask_(0),
user_flags_(0),
net_log_(net_log),
done_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED) {
net_log_(net_log) {
TRACE_EVENT0("disk_cache", "BackendImpl::BackendImpl");
}
......@@ -177,9 +177,7 @@ BackendImpl::BackendImpl(
block_files_(path),
mask_(mask),
user_flags_(kMask),
net_log_(net_log),
done_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED) {
net_log_(net_log) {
TRACE_EVENT0("disk_cache", "BackendImpl::BackendImpl");
}
......@@ -199,12 +197,15 @@ BackendImpl::~BackendImpl() {
// Unit tests may use the same sequence for everything.
CleanupCache();
} else {
// Signals the end of background work.
base::WaitableEvent done;
background_queue_.background_thread()->PostTask(
FROM_HERE,
base::BindOnce(&FinalCleanupCallback, base::Unretained(this)));
FROM_HERE, base::BindOnce(&FinalCleanupCallback, base::Unretained(this),
base::Unretained(&done)));
// http://crbug.com/74623
base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_wait;
done_.Wait();
done.Wait();
}
}
......@@ -348,7 +349,6 @@ void BackendImpl::CleanupCache() {
FlushIndex();
index_ = nullptr;
ptr_factory_.InvalidateWeakPtrs();
done_.Signal();
}
// ------------------------------------------------------------------------
......
......@@ -426,7 +426,6 @@ class NET_EXPORT_PRIVATE BackendImpl : public Backend {
Stats stats_; // Usage statistics.
std::unique_ptr<base::RepeatingTimer> timer_; // Usage timer.
base::WaitableEvent done_; // Signals the end of background work.
base::WeakPtrFactory<BackendImpl> ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(BackendImpl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment