| Index: net/disk_cache/backend_impl.cc
|
| ===================================================================
|
| --- net/disk_cache/backend_impl.cc (revision 126788)
|
| +++ net/disk_cache/backend_impl.cc (working copy)
|
| @@ -352,7 +352,15 @@
|
| }
|
|
|
| BackendImpl::~BackendImpl() {
|
| - background_queue_.WaitForPendingIO();
|
| + if (user_flags_ & kNoRandom) {
|
| + // This is a unit test, so we want to be strict about not leaking entries
|
| + // and completing all the work.
|
| + background_queue_.WaitForPendingIO();
|
| + } else {
|
| + // This is most likely not a test, so we want to do as little work as
|
| + // possible at this time, at the price of leaving dirty entries behind.
|
| + background_queue_.DropPendingIO();
|
| + }
|
|
|
| if (background_queue_.BackgroundIsCurrentThread()) {
|
| // Unit tests may use the same thread for everything.
|
| @@ -378,7 +386,7 @@
|
| int max_bytes, net::CacheType type,
|
| uint32 flags, base::MessageLoopProxy* thread,
|
| net::NetLog* net_log, Backend** backend,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| CacheCreator* creator =
|
| new CacheCreator(full_path, force, max_bytes, type, flags, thread,
|
| @@ -387,7 +395,7 @@
|
| return creator->Run();
|
| }
|
|
|
| -int BackendImpl::Init(const net::CompletionCallback& callback) {
|
| +int BackendImpl::Init(const CompletionCallback& callback) {
|
| background_queue_.Init(callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
| @@ -428,7 +436,7 @@
|
| return net::ERR_FAILED;
|
| }
|
|
|
| - if (!(user_flags_ & disk_cache::kNoRandom)) {
|
| + if (!(user_flags_ & kNoRandom)) {
|
| // The unit test controls directly what to test.
|
| new_eviction_ = (cache_type_ == net::DISK_CACHE);
|
| }
|
| @@ -438,7 +446,7 @@
|
| return net::ERR_FAILED;
|
| }
|
|
|
| - if (!(user_flags_ & disk_cache::kNoRandom) &&
|
| + if (!(user_flags_ & kNoRandom) &&
|
| cache_type_ == net::DISK_CACHE && !InitExperiment(&data_->header))
|
| return net::ERR_FAILED;
|
|
|
| @@ -496,9 +504,9 @@
|
| if (data_)
|
| data_->header.crash = 0;
|
|
|
| - File::WaitForPendingIO(&num_pending_io_);
|
| if (user_flags_ & kNoRandom) {
|
| // This is a net_unittest, verify that we are not 'leaking' entries.
|
| + File::WaitForPendingIO(&num_pending_io_);
|
| DCHECK(!num_refs_);
|
| }
|
| }
|
| @@ -511,7 +519,7 @@
|
| // ------------------------------------------------------------------------
|
|
|
| int BackendImpl::OpenPrevEntry(void** iter, Entry** prev_entry,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| background_queue_.OpenPrevEntry(iter, prev_entry, callback);
|
| return net::ERR_IO_PENDING;
|
| @@ -826,6 +834,10 @@
|
| return block_files_.GetFile(address);
|
| }
|
|
|
| +base::WeakPtr<InFlightBackendIO> BackendImpl::GetBackgroundQueue() {
|
| + return background_queue_.GetWeakPtr();
|
| +}
|
| +
|
| bool BackendImpl::CreateExternalFile(Addr* address) {
|
| int file_number = data_->header.last_file + 1;
|
| Addr file_address(0);
|
| @@ -984,7 +996,7 @@
|
| void BackendImpl::OnEntryDestroyEnd() {
|
| DecreaseNumRefs();
|
| if (data_->header.num_bytes > max_size_ && !read_only_ &&
|
| - (up_ticks_ > kTrimDelay || user_flags_ & disk_cache::kNoRandom))
|
| + (up_ticks_ > kTrimDelay || user_flags_ & kNoRandom))
|
| eviction_.TrimCache(false);
|
| }
|
|
|
| @@ -1244,13 +1256,13 @@
|
| num_refs_ = 0;
|
| }
|
|
|
| -int BackendImpl::FlushQueueForTest(const net::CompletionCallback& callback) {
|
| +int BackendImpl::FlushQueueForTest(const CompletionCallback& callback) {
|
| background_queue_.FlushQueue(callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
|
|
| int BackendImpl::RunTaskForTest(const base::Closure& task,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| background_queue_.RunTask(task, callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
| @@ -1307,27 +1319,27 @@
|
| }
|
|
|
| int BackendImpl::OpenEntry(const std::string& key, Entry** entry,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| background_queue_.OpenEntry(key, entry, callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
|
|
| int BackendImpl::CreateEntry(const std::string& key, Entry** entry,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| background_queue_.CreateEntry(key, entry, callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
|
|
| int BackendImpl::DoomEntry(const std::string& key,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| background_queue_.DoomEntry(key, callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
|
|
| -int BackendImpl::DoomAllEntries(const net::CompletionCallback& callback) {
|
| +int BackendImpl::DoomAllEntries(const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| background_queue_.DoomAllEntries(callback);
|
| return net::ERR_IO_PENDING;
|
| @@ -1335,21 +1347,21 @@
|
|
|
| int BackendImpl::DoomEntriesBetween(const base::Time initial_time,
|
| const base::Time end_time,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| background_queue_.DoomEntriesBetween(initial_time, end_time, callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
|
|
| int BackendImpl::DoomEntriesSince(const base::Time initial_time,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| background_queue_.DoomEntriesSince(initial_time, callback);
|
| return net::ERR_IO_PENDING;
|
| }
|
|
|
| int BackendImpl::OpenNextEntry(void** iter, Entry** next_entry,
|
| - const net::CompletionCallback& callback) {
|
| + const CompletionCallback& callback) {
|
| DCHECK(!callback.is_null());
|
| background_queue_.OpenNextEntry(iter, next_entry, callback);
|
| return net::ERR_IO_PENDING;
|
|
|