blob: 80d6ca0fc909302ed4fab62136b706f8415e57dc [file] [log] [blame]
[email protected]05f8087d2012-06-29 18:58:371// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
5#include "net/disk_cache/disk_cache_test_base.h"
6
dchengc7eeda422015-12-26 03:56:487#include <utility>
8
Sebastien Marchand6d0558fd2019-01-25 16:49:379#include "base/bind.h"
thestigd8df0332014-09-04 06:33:2910#include "base/files/file_util.h"
[email protected]79b3fec2011-11-15 22:33:4711#include "base/path_service.h"
[email protected]94a9d1a2013-03-24 09:50:3112#include "base/run_loop.h"
[email protected]81e549a2014-08-21 04:19:5513#include "base/single_thread_task_runner.h"
[email protected]8b2f8a52013-08-28 08:45:3514#include "base/threading/platform_thread.h"
gabf767595f2016-05-11 18:50:3515#include "base/threading/thread_task_runner_handle.h"
[email protected]e1fcf142010-08-23 18:47:2516#include "net/base/io_buffer.h"
[email protected]fb2622f2010-07-13 18:00:5617#include "net/base/net_errors.h"
Josh Karlindd9a5d142018-06-06 00:35:4818#include "net/base/request_priority.h"
[email protected]bc4fb8e2010-03-18 23:58:1719#include "net/base/test_completion_callback.h"
Maks Orlovich036fd1f2017-08-07 17:51:1120#include "net/disk_cache/backend_cleanup_tracker.h"
[email protected]c2c5cfc2014-03-03 16:35:2821#include "net/disk_cache/blockfile/backend_impl.h"
[email protected]398ad132013-04-02 15:11:0122#include "net/disk_cache/cache_util.h"
23#include "net/disk_cache/disk_cache.h"
initial.commit586acc5fe2008-07-26 22:42:5224#include "net/disk_cache/disk_cache_test_util.h"
[email protected]c2c5cfc2014-03-03 16:35:2825#include "net/disk_cache/memory/mem_backend_impl.h"
[email protected]398ad132013-04-02 15:11:0126#include "net/disk_cache/simple/simple_backend_impl.h"
Maks Orlovichf378b3a2017-10-31 16:27:3027#include "net/disk_cache/simple/simple_file_tracker.h"
[email protected]7e48c1b2013-07-12 12:15:4328#include "net/disk_cache/simple/simple_index.h"
robpercival214763f2016-07-01 23:27:0129#include "net/test/gtest_util.h"
30#include "testing/gmock/include/gmock/gmock.h"
31#include "testing/gtest/include/gtest/gtest.h"
32
33using net::test::IsOk;
initial.commit586acc5fe2008-07-26 22:42:5234
[email protected]79b3fec2011-11-15 22:33:4735DiskCacheTest::DiskCacheTest() {
[email protected]784f9302012-08-17 00:13:4336 CHECK(temp_dir_.CreateUniqueTempDir());
vabrb8582322016-09-09 08:05:3737 cache_path_ = temp_dir_.GetPath();
[email protected]79b3fec2011-11-15 22:33:4738}
39
Chris Watkins68b15032017-12-01 03:07:1340DiskCacheTest::~DiskCacheTest() = default;
[email protected]79b3fec2011-11-15 22:33:4741
42bool DiskCacheTest::CopyTestCache(const std::string& name) {
[email protected]6cdfd7f2013-02-08 20:40:1543 base::FilePath path;
Avi Drissman5c80d832018-05-01 17:01:1944 base::PathService::Get(base::DIR_SOURCE_ROOT, &path);
[email protected]79b3fec2011-11-15 22:33:4745 path = path.AppendASCII("net");
46 path = path.AppendASCII("data");
47 path = path.AppendASCII("cache_tests");
48 path = path.AppendASCII(name);
49
50 if (!CleanupCacheDir())
51 return false;
[email protected]f0ff2ad2013-07-09 17:42:2652 return base::CopyDirectory(path, cache_path_, false);
[email protected]79b3fec2011-11-15 22:33:4753}
54
55bool DiskCacheTest::CleanupCacheDir() {
56 return DeleteCache(cache_path_);
57}
58
[email protected]17b89142008-11-07 21:52:1559void DiskCacheTest::TearDown() {
[email protected]94a9d1a2013-03-24 09:50:3160 base::RunLoop().RunUntilIdle();
[email protected]17b89142008-11-07 21:52:1561}
62
gavinpb1aaa052014-09-24 14:54:3563DiskCacheTestWithCache::TestIterator::TestIterator(
danakjd04b92d2016-04-16 01:16:4964 std::unique_ptr<disk_cache::Backend::Iterator> iterator)
dchengc7eeda422015-12-26 03:56:4865 : iterator_(std::move(iterator)) {}
gavinpb1aaa052014-09-24 14:54:3566
Chris Watkins68b15032017-12-01 03:07:1367DiskCacheTestWithCache::TestIterator::~TestIterator() = default;
gavinpb1aaa052014-09-24 14:54:3568
69int DiskCacheTestWithCache::TestIterator::OpenNextEntry(
70 disk_cache::Entry** next_entry) {
71 net::TestCompletionCallback cb;
72 int rv = iterator_->OpenNextEntry(next_entry, cb.callback());
73 return cb.GetResult(rv);
74}
75
[email protected]7aefb152011-01-21 23:46:4976DiskCacheTestWithCache::DiskCacheTestWithCache()
Raul Tambre94493c652019-03-11 17:18:3577 : cache_impl_(nullptr),
78 simple_cache_impl_(nullptr),
79 mem_cache_(nullptr),
[email protected]7aefb152011-01-21 23:46:4980 mask_(0),
81 size_(0),
82 type_(net::DISK_CACHE),
83 memory_only_(false),
[email protected]398ad132013-04-02 15:11:0184 simple_cache_mode_(false),
[email protected]7e48c1b2013-07-12 12:15:4385 simple_cache_wait_for_index_(true),
[email protected]7aefb152011-01-21 23:46:4986 force_creation_(false),
87 new_eviction_(false),
88 first_cleanup_(true),
89 integrity_(true),
Bence Béky98447b12018-05-08 03:14:0190 use_current_thread_(false) {}
initial.commit586acc5fe2008-07-26 22:42:5291
Chris Watkins68b15032017-12-01 03:07:1392DiskCacheTestWithCache::~DiskCacheTestWithCache() = default;
[email protected]7aefb152011-01-21 23:46:4993
[email protected]4d5e0362008-08-28 00:59:0694void DiskCacheTestWithCache::InitCache() {
initial.commit586acc5fe2008-07-26 22:42:5295 if (memory_only_)
96 InitMemoryCache();
97 else
98 InitDiskCache();
99
Raul Tambre94493c652019-03-11 17:18:35100 ASSERT_TRUE(nullptr != cache_);
[email protected]a2553842013-04-19 14:25:18101 if (first_cleanup_)
[email protected]a9da16d2008-07-30 21:41:54102 ASSERT_EQ(0, cache_->GetEntryCount());
initial.commit586acc5fe2008-07-26 22:42:52103}
104
initial.commit586acc5fe2008-07-26 22:42:52105// We are expected to leak memory when simulating crashes.
[email protected]4d5e0362008-08-28 00:59:06106void DiskCacheTestWithCache::SimulateCrash() {
[email protected]398ad132013-04-02 15:11:01107 ASSERT_TRUE(!memory_only_);
[email protected]2a65aceb82011-12-19 20:59:27108 net::TestCompletionCallback cb;
109 int rv = cache_impl_->FlushQueueForTest(cb.callback());
robpercival214763f2016-07-01 23:27:01110 ASSERT_THAT(cb.GetResult(rv), IsOk());
initial.commit586acc5fe2008-07-26 22:42:52111 cache_impl_->ClearRefCountForTest();
112
[email protected]8c3f5a32013-08-01 11:57:53113 cache_.reset();
Maks Orlovichf3860652017-12-13 18:03:16114 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, size_, mask_));
initial.commit586acc5fe2008-07-26 22:42:52115
Maks Orlovich463dc502017-07-25 14:52:49116 CreateBackend(disk_cache::kNoRandom);
initial.commit586acc5fe2008-07-26 22:42:52117}
[email protected]a9da16d2008-07-30 21:41:54118
[email protected]4d5e0362008-08-28 00:59:06119void DiskCacheTestWithCache::SetTestMode() {
[email protected]398ad132013-04-02 15:11:01120 ASSERT_TRUE(!memory_only_);
[email protected]a9da16d2008-07-30 21:41:54121 cache_impl_->SetUnitTestMode();
122}
[email protected]bc4fb8e2010-03-18 23:58:17123
Ben Kelly5a16ed02018-09-07 21:28:09124void DiskCacheTestWithCache::SetMaxSize(int64_t size, bool should_succeed) {
[email protected]7aefb152011-01-21 23:46:49125 size_ = size;
[email protected]1ed95752013-04-23 00:12:36126 if (simple_cache_impl_)
Ben Kelly5a16ed02018-09-07 21:28:09127 EXPECT_EQ(should_succeed, simple_cache_impl_->SetMaxSize(size));
[email protected]1ed95752013-04-23 00:12:36128
[email protected]7aefb152011-01-21 23:46:49129 if (cache_impl_)
Ben Kelly5a16ed02018-09-07 21:28:09130 EXPECT_EQ(should_succeed, cache_impl_->SetMaxSize(size));
[email protected]7aefb152011-01-21 23:46:49131
132 if (mem_cache_)
Ben Kelly5a16ed02018-09-07 21:28:09133 EXPECT_EQ(should_succeed, mem_cache_->SetMaxSize(size));
[email protected]7aefb152011-01-21 23:46:49134}
135
Steven Bingler6a1d77d2019-01-16 01:57:59136int DiskCacheTestWithCache::OpenOrCreateEntry(
137 const std::string& key,
138 disk_cache::EntryWithOpened* entry_struct) {
139 return OpenOrCreateEntryWithPriority(key, net::HIGHEST, entry_struct);
Steven Bingler6afedf82019-01-08 19:34:49140}
141
142int DiskCacheTestWithCache::OpenOrCreateEntryWithPriority(
143 const std::string& key,
144 net::RequestPriority request_priority,
Steven Bingler6a1d77d2019-01-16 01:57:59145 disk_cache::EntryWithOpened* entry_struct) {
Steven Bingler6afedf82019-01-08 19:34:49146 net::TestCompletionCallback cb;
Steven Bingler6a1d77d2019-01-16 01:57:59147 int rv = cache_->OpenOrCreateEntry(key, request_priority, entry_struct,
148 cb.callback());
Steven Bingler6afedf82019-01-08 19:34:49149 return cb.GetResult(rv);
150}
151
[email protected]bc4fb8e2010-03-18 23:58:17152int DiskCacheTestWithCache::OpenEntry(const std::string& key,
153 disk_cache::Entry** entry) {
Josh Karlindd9a5d142018-06-06 00:35:48154 return OpenEntryWithPriority(key, net::HIGHEST, entry);
155}
156
157int DiskCacheTestWithCache::OpenEntryWithPriority(
158 const std::string& key,
159 net::RequestPriority request_priority,
160 disk_cache::Entry** entry) {
[email protected]2a65aceb82011-12-19 20:59:27161 net::TestCompletionCallback cb;
Josh Karlindd9a5d142018-06-06 00:35:48162 int rv = cache_->OpenEntry(key, request_priority, entry, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17163 return cb.GetResult(rv);
164}
165
166int DiskCacheTestWithCache::CreateEntry(const std::string& key,
167 disk_cache::Entry** entry) {
Josh Karlindd9a5d142018-06-06 00:35:48168 return CreateEntryWithPriority(key, net::HIGHEST, entry);
169}
170
171int DiskCacheTestWithCache::CreateEntryWithPriority(
172 const std::string& key,
173 net::RequestPriority request_priority,
174 disk_cache::Entry** entry) {
[email protected]2a65aceb82011-12-19 20:59:27175 net::TestCompletionCallback cb;
Josh Karlindd9a5d142018-06-06 00:35:48176 int rv = cache_->CreateEntry(key, request_priority, entry, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17177 return cb.GetResult(rv);
178}
179
180int DiskCacheTestWithCache::DoomEntry(const std::string& key) {
[email protected]42c459632011-12-17 02:20:23181 net::TestCompletionCallback cb;
Josh Karlindd9a5d142018-06-06 00:35:48182 int rv = cache_->DoomEntry(key, net::HIGHEST, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17183 return cb.GetResult(rv);
184}
185
186int DiskCacheTestWithCache::DoomAllEntries() {
[email protected]6ad7c0912011-12-15 19:10:19187 net::TestCompletionCallback cb;
188 int rv = cache_->DoomAllEntries(cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17189 return cb.GetResult(rv);
190}
191
192int DiskCacheTestWithCache::DoomEntriesBetween(const base::Time initial_time,
193 const base::Time end_time) {
[email protected]6ad7c0912011-12-15 19:10:19194 net::TestCompletionCallback cb;
195 int rv = cache_->DoomEntriesBetween(initial_time, end_time, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17196 return cb.GetResult(rv);
197}
198
199int DiskCacheTestWithCache::DoomEntriesSince(const base::Time initial_time) {
[email protected]2a65aceb82011-12-19 20:59:27200 net::TestCompletionCallback cb;
201 int rv = cache_->DoomEntriesSince(initial_time, cb.callback());
[email protected]bc4fb8e2010-03-18 23:58:17202 return cb.GetResult(rv);
203}
204
Ben Kelly5a16ed02018-09-07 21:28:09205int64_t DiskCacheTestWithCache::CalculateSizeOfAllEntries() {
206 net::TestInt64CompletionCallback cb;
207 int64_t rv = cache_->CalculateSizeOfAllEntries(cb.callback());
msramekaee01ceb2015-10-07 14:23:33208 return cb.GetResult(rv);
209}
210
Ben Kelly5a16ed02018-09-07 21:28:09211int64_t DiskCacheTestWithCache::CalculateSizeOfEntriesBetween(
dullwebera0030052017-01-16 11:56:04212 const base::Time initial_time,
213 const base::Time end_time) {
Ben Kelly5a16ed02018-09-07 21:28:09214 net::TestInt64CompletionCallback cb;
215 int64_t rv = cache_->CalculateSizeOfEntriesBetween(initial_time, end_time,
216 cb.callback());
dullwebera0030052017-01-16 11:56:04217 return cb.GetResult(rv);
218}
219
danakjd04b92d2016-04-16 01:16:49220std::unique_ptr<DiskCacheTestWithCache::TestIterator>
221DiskCacheTestWithCache::CreateIterator() {
222 return std::unique_ptr<TestIterator>(
223 new TestIterator(cache_->CreateIterator()));
[email protected]bc4fb8e2010-03-18 23:58:17224}
[email protected]fb2622f2010-07-13 18:00:56225
226void DiskCacheTestWithCache::FlushQueueForTest() {
227 if (memory_only_ || !cache_impl_)
228 return;
229
[email protected]2a65aceb82011-12-19 20:59:27230 net::TestCompletionCallback cb;
231 int rv = cache_impl_->FlushQueueForTest(cb.callback());
robpercival214763f2016-07-01 23:27:01232 EXPECT_THAT(cb.GetResult(rv), IsOk());
[email protected]fb2622f2010-07-13 18:00:56233}
[email protected]e1fcf142010-08-23 18:47:25234
[email protected]f27bbe002011-12-22 11:29:34235void DiskCacheTestWithCache::RunTaskForTest(const base::Closure& closure) {
[email protected]65188eb2010-09-16 20:59:29236 if (memory_only_ || !cache_impl_) {
[email protected]f27bbe002011-12-22 11:29:34237 closure.Run();
[email protected]65188eb2010-09-16 20:59:29238 return;
239 }
240
[email protected]2a65aceb82011-12-19 20:59:27241 net::TestCompletionCallback cb;
[email protected]f27bbe002011-12-22 11:29:34242 int rv = cache_impl_->RunTaskForTest(closure, cb.callback());
robpercival214763f2016-07-01 23:27:01243 EXPECT_THAT(cb.GetResult(rv), IsOk());
[email protected]65188eb2010-09-16 20:59:29244}
245
[email protected]e1fcf142010-08-23 18:47:25246int DiskCacheTestWithCache::ReadData(disk_cache::Entry* entry, int index,
247 int offset, net::IOBuffer* buf, int len) {
[email protected]2a65aceb82011-12-19 20:59:27248 net::TestCompletionCallback cb;
249 int rv = entry->ReadData(index, offset, buf, len, cb.callback());
[email protected]e1fcf142010-08-23 18:47:25250 return cb.GetResult(rv);
251}
252
[email protected]e1fcf142010-08-23 18:47:25253int DiskCacheTestWithCache::WriteData(disk_cache::Entry* entry, int index,
254 int offset, net::IOBuffer* buf, int len,
255 bool truncate) {
[email protected]2a65aceb82011-12-19 20:59:27256 net::TestCompletionCallback cb;
257 int rv = entry->WriteData(index, offset, buf, len, cb.callback(), truncate);
[email protected]e1fcf142010-08-23 18:47:25258 return cb.GetResult(rv);
259}
260
261int DiskCacheTestWithCache::ReadSparseData(disk_cache::Entry* entry,
Avi Drissman13fc8932015-12-20 04:40:46262 int64_t offset,
263 net::IOBuffer* buf,
[email protected]e1fcf142010-08-23 18:47:25264 int len) {
[email protected]2a65aceb82011-12-19 20:59:27265 net::TestCompletionCallback cb;
266 int rv = entry->ReadSparseData(offset, buf, len, cb.callback());
[email protected]e1fcf142010-08-23 18:47:25267 return cb.GetResult(rv);
268}
269
270int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry,
Avi Drissman13fc8932015-12-20 04:40:46271 int64_t offset,
272 net::IOBuffer* buf,
273 int len) {
[email protected]2a65aceb82011-12-19 20:59:27274 net::TestCompletionCallback cb;
275 int rv = entry->WriteSparseData(offset, buf, len, cb.callback());
[email protected]e1fcf142010-08-23 18:47:25276 return cb.GetResult(rv);
277}
[email protected]7aefb152011-01-21 23:46:49278
[email protected]ceb61da32011-01-25 23:52:02279void DiskCacheTestWithCache::TrimForTest(bool empty) {
[email protected]f27bbe002011-12-22 11:29:34280 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimForTest,
281 base::Unretained(cache_impl_),
282 empty));
[email protected]ceb61da32011-01-25 23:52:02283}
284
285void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) {
[email protected]f27bbe002011-12-22 11:29:34286 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimDeletedListForTest,
287 base::Unretained(cache_impl_),
288 empty));
[email protected]ceb61da32011-01-25 23:52:02289}
290
[email protected]05f8087d2012-06-29 18:58:37291void DiskCacheTestWithCache::AddDelay() {
[email protected]8b2f8a52013-08-28 08:45:35292 if (simple_cache_mode_) {
293 // The simple cache uses second resolution for many timeouts, so it's safest
294 // to advance by at least whole seconds before falling back into the normal
295 // disk cache epsilon advance.
296 const base::Time initial_time = base::Time::Now();
297 do {
298 base::PlatformThread::YieldCurrentThread();
299 } while (base::Time::Now() -
300 initial_time < base::TimeDelta::FromSeconds(1));
301 }
302
[email protected]05f8087d2012-06-29 18:58:37303 base::Time initial = base::Time::Now();
304 while (base::Time::Now() <= initial) {
305 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
306 };
307}
308
[email protected]7aefb152011-01-21 23:46:49309void DiskCacheTestWithCache::TearDown() {
Bence Béky98447b12018-05-08 03:14:01310 RunUntilIdle();
[email protected]8c3f5a32013-08-01 11:57:53311 cache_.reset();
[email protected]7aefb152011-01-21 23:46:49312
[email protected]fccce902013-04-15 19:00:51313 if (!memory_only_ && !simple_cache_mode_ && integrity_) {
Maks Orlovichf3860652017-12-13 18:03:16314 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, size_, mask_));
[email protected]7aefb152011-01-21 23:46:49315 }
Bence Béky98447b12018-05-08 03:14:01316 RunUntilIdle();
Maks Orlovichf378b3a2017-10-31 16:27:30317 if (simple_cache_mode_ && simple_file_tracker_)
318 EXPECT_TRUE(simple_file_tracker_->IsEmptyForTesting());
319
[email protected]de677dc2013-09-13 02:12:25320 DiskCacheTest::TearDown();
[email protected]7aefb152011-01-21 23:46:49321}
322
323void DiskCacheTestWithCache::InitMemoryCache() {
Raul Tambre94493c652019-03-11 17:18:35324 mem_cache_ = new disk_cache::MemBackendImpl(nullptr);
[email protected]8c3f5a32013-08-01 11:57:53325 cache_.reset(mem_cache_);
326 ASSERT_TRUE(cache_);
[email protected]7aefb152011-01-21 23:46:49327
328 if (size_)
329 EXPECT_TRUE(mem_cache_->SetMaxSize(size_));
330
331 ASSERT_TRUE(mem_cache_->Init());
332}
333
334void DiskCacheTestWithCache::InitDiskCache() {
[email protected]7aefb152011-01-21 23:46:49335 if (first_cleanup_)
[email protected]79b3fec2011-11-15 22:33:47336 ASSERT_TRUE(CleanupCacheDir());
[email protected]7aefb152011-01-21 23:46:49337
Maks Orlovich463dc502017-07-25 14:52:49338 CreateBackend(disk_cache::kNoRandom);
[email protected]398ad132013-04-02 15:11:01339}
[email protected]7aefb152011-01-21 23:46:49340
Maks Orlovich463dc502017-07-25 14:52:49341void DiskCacheTestWithCache::CreateBackend(uint32_t flags) {
[email protected]81e549a2014-08-21 04:19:55342 scoped_refptr<base::SingleThreadTaskRunner> runner;
[email protected]398ad132013-04-02 15:11:01343 if (use_current_thread_)
[email protected]81e549a2014-08-21 04:19:55344 runner = base::ThreadTaskRunnerHandle::Get();
[email protected]7aefb152011-01-21 23:46:49345 else
Maks Orlovich463dc502017-07-25 14:52:49346 runner = nullptr; // let the backend sort it out.
[email protected]7aefb152011-01-21 23:46:49347
[email protected]398ad132013-04-02 15:11:01348 if (simple_cache_mode_) {
Maks Orlovich922db0c2018-02-21 15:28:46349 DCHECK(!use_current_thread_)
350 << "Using current thread unsupported by SimpleCache";
[email protected]398ad132013-04-02 15:11:01351 net::TestCompletionCallback cb;
Maks Orlovichdb1f0922018-01-31 03:41:17352 // We limit ourselves to 64 fds since OS X by default gives us 256.
353 // (Chrome raises the number on startup, but the test fixture doesn't).
Maks Orlovichf378b3a2017-10-31 16:27:30354 if (!simple_file_tracker_)
Maks Orlovichdb1f0922018-01-31 03:41:17355 simple_file_tracker_ =
356 std::make_unique<disk_cache::SimpleFileTracker>(64);
Maks Orlovichf378b3a2017-10-31 16:27:30357 std::unique_ptr<disk_cache::SimpleBackendImpl> simple_backend =
358 std::make_unique<disk_cache::SimpleBackendImpl>(
359 cache_path_, /* cleanup_tracker = */ nullptr,
Maks Orlovich922db0c2018-02-21 15:28:46360 simple_file_tracker_.get(), size_, type_, /*net_log = */ nullptr);
[email protected]00831c822013-04-10 15:37:12361 int rv = simple_backend->Init(cb.callback());
robpercival214763f2016-07-01 23:27:01362 ASSERT_THAT(cb.GetResult(rv), IsOk());
[email protected]8c3f5a32013-08-01 11:57:53363 simple_cache_impl_ = simple_backend.get();
dchengc7eeda422015-12-26 03:56:48364 cache_ = std::move(simple_backend);
[email protected]7e48c1b2013-07-12 12:15:43365 if (simple_cache_wait_for_index_) {
366 net::TestCompletionCallback wait_for_index_cb;
[email protected]8c3f5a32013-08-01 11:57:53367 rv = simple_cache_impl_->index()->ExecuteWhenReady(
[email protected]7e48c1b2013-07-12 12:15:43368 wait_for_index_cb.callback());
robpercival214763f2016-07-01 23:27:01369 ASSERT_THAT(wait_for_index_cb.GetResult(rv), IsOk());
[email protected]7e48c1b2013-07-12 12:15:43370 }
[email protected]398ad132013-04-02 15:11:01371 return;
372 }
373
374 if (mask_)
Steven Bingler252ffae2019-03-19 17:43:16375 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, type_,
Maks Orlovich036fd1f2017-08-07 17:51:11376 /* net_log = */ nullptr);
[email protected]398ad132013-04-02 15:11:01377 else
Steven Bingler252ffae2019-03-19 17:43:16378 cache_impl_ = new disk_cache::BackendImpl(
379 cache_path_, /* cleanup_tracker = */ nullptr, runner, type_,
380 /* net_log = */ nullptr);
[email protected]8c3f5a32013-08-01 11:57:53381 cache_.reset(cache_impl_);
382 ASSERT_TRUE(cache_);
[email protected]7aefb152011-01-21 23:46:49383 if (size_)
384 EXPECT_TRUE(cache_impl_->SetMaxSize(size_));
[email protected]7aefb152011-01-21 23:46:49385 if (new_eviction_)
386 cache_impl_->SetNewEviction();
[email protected]398ad132013-04-02 15:11:01387 cache_impl_->SetFlags(flags);
[email protected]42c459632011-12-17 02:20:23388 net::TestCompletionCallback cb;
389 int rv = cache_impl_->Init(cb.callback());
robpercival214763f2016-07-01 23:27:01390 ASSERT_THAT(cb.GetResult(rv), IsOk());
[email protected]7aefb152011-01-21 23:46:49391}