OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/disk_cache/disk_cache_test_base.h" | 5 #include "net/disk_cache/disk_cache_test_base.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
10 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
12 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
13 #include "net/disk_cache/backend_impl.h" | 14 #include "net/disk_cache/backend_impl.h" |
14 #include "net/disk_cache/cache_util.h" | 15 #include "net/disk_cache/cache_util.h" |
15 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
16 #include "net/disk_cache/disk_cache_test_util.h" | 17 #include "net/disk_cache/disk_cache_test_util.h" |
17 #include "net/disk_cache/mem_backend_impl.h" | 18 #include "net/disk_cache/mem_backend_impl.h" |
18 #include "net/disk_cache/simple/simple_backend_impl.h" | 19 #include "net/disk_cache/simple/simple_backend_impl.h" |
| 20 #include "net/disk_cache/v3/backend_impl_v3.h" |
| 21 |
| 22 namespace { |
| 23 |
| 24 base::FilePath GetCachePath() { |
| 25 base::FilePath path; |
| 26 PathService::Get(base::DIR_TEMP, &path); // Ignore return value; |
| 27 path = path.AppendASCII("cache_test"); |
| 28 if (!file_util::PathExists(path)) |
| 29 file_util::CreateDirectory(path); |
| 30 |
| 31 return path; |
| 32 } |
| 33 |
| 34 } // namespace |
19 | 35 |
20 DiskCacheTest::DiskCacheTest() { | 36 DiskCacheTest::DiskCacheTest() { |
21 CHECK(temp_dir_.CreateUniqueTempDir()); | 37 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
22 cache_path_ = temp_dir_.path(); | 38 //if (command_line->HasSwitch("fixed-cache-dir")) { |
| 39 if (true) { |
| 40 cache_path_ = GetCachePath(); |
| 41 } else { |
| 42 CHECK(temp_dir_.CreateUniqueTempDir()); |
| 43 cache_path_ = temp_dir_.path(); |
| 44 } |
| 45 |
23 if (!MessageLoop::current()) | 46 if (!MessageLoop::current()) |
24 message_loop_.reset(new MessageLoopForIO()); | 47 message_loop_.reset(new MessageLoopForIO()); |
25 } | 48 } |
26 | 49 |
27 DiskCacheTest::~DiskCacheTest() { | 50 DiskCacheTest::~DiskCacheTest() { |
28 } | 51 } |
29 | 52 |
30 bool DiskCacheTest::CopyTestCache(const std::string& name) { | 53 bool DiskCacheTest::CopyTestCache(const std::string& name) { |
31 base::FilePath path; | 54 base::FilePath path; |
32 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 55 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
33 path = path.AppendASCII("net"); | 56 path = path.AppendASCII("net"); |
34 path = path.AppendASCII("data"); | 57 path = path.AppendASCII("data"); |
35 path = path.AppendASCII("cache_tests"); | 58 path = path.AppendASCII("cache_tests"); |
36 path = path.AppendASCII(name); | 59 path = path.AppendASCII(name); |
37 | 60 |
38 if (!CleanupCacheDir()) | 61 if (!CleanupCacheDir()) |
39 return false; | 62 return false; |
40 return file_util::CopyDirectory(path, cache_path_, false); | 63 return file_util::CopyDirectory(path, cache_path_, false); |
41 } | 64 } |
42 | 65 |
43 bool DiskCacheTest::CleanupCacheDir() { | 66 bool DiskCacheTest::CleanupCacheDir() { |
44 return DeleteCache(cache_path_); | 67 return DeleteCache(cache_path_); |
45 } | 68 } |
46 | 69 |
| 70 bool DiskCacheTest::ForceRandomCacheDir() { |
| 71 if (temp_dir_.path().empty()) { |
| 72 if (!temp_dir_.CreateUniqueTempDir()) |
| 73 return false; |
| 74 cache_path_ = temp_dir_.path(); |
| 75 } |
| 76 return true; |
| 77 } |
| 78 |
47 void DiskCacheTest::TearDown() { | 79 void DiskCacheTest::TearDown() { |
48 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
49 } | 81 } |
50 | 82 |
51 DiskCacheTestWithCache::DiskCacheTestWithCache() | 83 DiskCacheTestWithCache::DiskCacheTestWithCache() |
52 : cache_(NULL), | 84 : cache_(NULL), |
53 cache_impl_(NULL), | 85 cache_impl_(NULL), |
54 simple_cache_impl_(NULL), | 86 simple_cache_impl_(NULL), |
55 mem_cache_(NULL), | 87 mem_cache_(NULL), |
| 88 cache_impl_v3_(NULL), |
56 mask_(0), | 89 mask_(0), |
57 size_(0), | 90 size_(0), |
58 type_(net::DISK_CACHE), | 91 type_(net::DISK_CACHE), |
59 memory_only_(false), | 92 memory_only_(false), |
60 simple_cache_mode_(false), | 93 simple_cache_mode_(false), |
61 force_creation_(false), | 94 force_creation_(false), |
62 new_eviction_(false), | 95 new_eviction_(false), |
| 96 v3_(false), |
63 first_cleanup_(true), | 97 first_cleanup_(true), |
64 integrity_(true), | 98 integrity_(true), |
65 use_current_thread_(false), | 99 use_current_thread_(false), |
| 100 avoid_test_flag_(false), |
| 101 unit_test_mode_(false), |
66 cache_thread_("CacheThread") { | 102 cache_thread_("CacheThread") { |
67 } | 103 } |
68 | 104 |
69 DiskCacheTestWithCache::~DiskCacheTestWithCache() {} | 105 DiskCacheTestWithCache::~DiskCacheTestWithCache() {} |
70 | 106 |
71 void DiskCacheTestWithCache::InitCache() { | 107 void DiskCacheTestWithCache::InitCache() { |
72 if (memory_only_) | 108 if (memory_only_) |
73 InitMemoryCache(); | 109 InitMemoryCache(); |
74 else | 110 else |
75 InitDiskCache(); | 111 InitDiskCache(); |
76 | 112 |
77 ASSERT_TRUE(NULL != cache_); | 113 ASSERT_TRUE(NULL != cache_); |
78 if (first_cleanup_) | 114 if (first_cleanup_) |
79 ASSERT_EQ(0, cache_->GetEntryCount()); | 115 ASSERT_EQ(0, cache_->GetEntryCount()); |
80 } | 116 } |
81 | 117 |
82 // We are expected to leak memory when simulating crashes. | 118 // We are expected to leak memory when simulating crashes. |
83 void DiskCacheTestWithCache::SimulateCrash() { | 119 void DiskCacheTestWithCache::SimulateCrash() { |
84 ASSERT_TRUE(!memory_only_); | 120 ASSERT_TRUE(!memory_only_); |
85 net::TestCompletionCallback cb; | 121 if (cache_impl_) { |
86 int rv = cache_impl_->FlushQueueForTest(cb.callback()); | 122 net::TestCompletionCallback cb; |
87 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 123 int rv = cache_impl_->FlushQueueForTest(cb.callback()); |
88 cache_impl_->ClearRefCountForTest(); | 124 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 125 cache_impl_->ClearRefCountForTest(); |
89 | 126 |
90 delete cache_impl_; | 127 delete cache_impl_; |
91 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); | 128 cache_impl_ = NULL; |
| 129 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
| 130 } else if (cache_impl_v3_) { |
| 131 cache_impl_v3_->SetFlags(disk_cache::BackendImplV3::NO_CLEAN_ON_EXIT); |
| 132 delete cache_impl_v3_; |
| 133 cache_impl_v3_ = NULL; |
| 134 } else { |
| 135 ASSERT_TRUE(0); |
| 136 } |
| 137 cache_ = NULL; |
92 | 138 |
93 CreateBackend(disk_cache::kNoRandom, &cache_thread_); | 139 CreateBackend(&cache_thread_); |
94 } | 140 } |
95 | 141 |
96 void DiskCacheTestWithCache::SetTestMode() { | 142 void DiskCacheTestWithCache::SetTestMode() { |
97 ASSERT_TRUE(!memory_only_); | 143 ASSERT_TRUE(!memory_only_); |
98 cache_impl_->SetUnitTestMode(); | 144 EXPECT_TRUE(cache_); |
| 145 if (cache_impl_) |
| 146 cache_impl_->SetUnitTestMode(); |
| 147 else if (cache_impl_v3_) |
| 148 cache_impl_v3_->SetUnitTestMode(); |
99 } | 149 } |
100 | 150 |
101 void DiskCacheTestWithCache::SetMaxSize(int size) { | 151 void DiskCacheTestWithCache::SetMaxSize(int size) { |
102 size_ = size; | 152 size_ = size; |
103 if (simple_cache_impl_) | 153 if (simple_cache_impl_) |
104 EXPECT_TRUE(simple_cache_impl_->SetMaxSize(size)); | 154 EXPECT_TRUE(simple_cache_impl_->SetMaxSize(size)); |
105 | 155 |
106 if (cache_impl_) | 156 if (cache_impl_) |
107 EXPECT_TRUE(cache_impl_->SetMaxSize(size)); | 157 EXPECT_TRUE(cache_impl_->SetMaxSize(size)); |
108 | 158 |
109 if (mem_cache_) | 159 if (mem_cache_) |
110 EXPECT_TRUE(mem_cache_->SetMaxSize(size)); | 160 EXPECT_TRUE(mem_cache_->SetMaxSize(size)); |
| 161 |
| 162 if (cache_impl_v3_) |
| 163 EXPECT_TRUE(cache_impl_v3_->SetMaxSize(size)); |
111 } | 164 } |
112 | 165 |
113 int DiskCacheTestWithCache::OpenEntry(const std::string& key, | 166 int DiskCacheTestWithCache::OpenEntry(const std::string& key, |
114 disk_cache::Entry** entry) { | 167 disk_cache::Entry** entry) { |
115 net::TestCompletionCallback cb; | 168 net::TestCompletionCallback cb; |
116 int rv = cache_->OpenEntry(key, entry, cb.callback()); | 169 int rv = cache_->OpenEntry(key, entry, cb.callback()); |
117 return cb.GetResult(rv); | 170 return cb.GetResult(rv); |
118 } | 171 } |
119 | 172 |
120 int DiskCacheTestWithCache::CreateEntry(const std::string& key, | 173 int DiskCacheTestWithCache::CreateEntry(const std::string& key, |
(...skipping 29 matching lines...) Expand all Loading... |
150 } | 203 } |
151 | 204 |
152 int DiskCacheTestWithCache::OpenNextEntry(void** iter, | 205 int DiskCacheTestWithCache::OpenNextEntry(void** iter, |
153 disk_cache::Entry** next_entry) { | 206 disk_cache::Entry** next_entry) { |
154 net::TestCompletionCallback cb; | 207 net::TestCompletionCallback cb; |
155 int rv = cache_->OpenNextEntry(iter, next_entry, cb.callback()); | 208 int rv = cache_->OpenNextEntry(iter, next_entry, cb.callback()); |
156 return cb.GetResult(rv); | 209 return cb.GetResult(rv); |
157 } | 210 } |
158 | 211 |
159 void DiskCacheTestWithCache::FlushQueueForTest() { | 212 void DiskCacheTestWithCache::FlushQueueForTest() { |
160 if (memory_only_ || !cache_impl_) | 213 if (memory_only_ || !(cache_impl_ || cache_impl_v3_)) |
161 return; | 214 return; |
162 | 215 |
163 net::TestCompletionCallback cb; | 216 net::TestCompletionCallback cb; |
164 int rv = cache_impl_->FlushQueueForTest(cb.callback()); | 217 int rv; |
| 218 if (cache_impl_) |
| 219 rv = cache_impl_->FlushQueueForTest(cb.callback()); |
| 220 else |
| 221 rv = cache_impl_v3_->FlushQueueForTest(cb.callback()); |
| 222 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
| 223 } |
| 224 |
| 225 void DiskCacheTestWithCache::CleanupForTest() { |
| 226 if (!cache_impl_v3_) |
| 227 return base::RunLoop().RunUntilIdle(); |
| 228 |
| 229 net::TestCompletionCallback cb; |
| 230 int rv = cache_impl_v3_->CleanupForTest(cb.callback()); |
165 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 231 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
166 } | 232 } |
167 | 233 |
168 void DiskCacheTestWithCache::RunTaskForTest(const base::Closure& closure) { | 234 void DiskCacheTestWithCache::RunTaskForTest(const base::Closure& closure) { |
169 if (memory_only_ || !cache_impl_) { | 235 if (memory_only_ || !cache_impl_) { |
170 closure.Run(); | 236 closure.Run(); |
171 return; | 237 return; |
172 } | 238 } |
173 | 239 |
174 net::TestCompletionCallback cb; | 240 net::TestCompletionCallback cb; |
(...skipping 25 matching lines...) Expand all Loading... |
200 } | 266 } |
201 | 267 |
202 int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry, | 268 int DiskCacheTestWithCache::WriteSparseData(disk_cache::Entry* entry, |
203 int64 offset, | 269 int64 offset, |
204 net::IOBuffer* buf, int len) { | 270 net::IOBuffer* buf, int len) { |
205 net::TestCompletionCallback cb; | 271 net::TestCompletionCallback cb; |
206 int rv = entry->WriteSparseData(offset, buf, len, cb.callback()); | 272 int rv = entry->WriteSparseData(offset, buf, len, cb.callback()); |
207 return cb.GetResult(rv); | 273 return cb.GetResult(rv); |
208 } | 274 } |
209 | 275 |
| 276 int DiskCacheTestWithCache::GetAvailableRange(disk_cache::Entry* entry, |
| 277 int64 offset, int len, |
| 278 int64* start) { |
| 279 net::TestCompletionCallback cb; |
| 280 int rv = entry->GetAvailableRange(offset, len, start, cb.callback()); |
| 281 return cb.GetResult(rv); |
| 282 } |
| 283 |
| 284 bool DiskCacheTestWithCache::IsAllocAllowed(int current_size, int new_size) { |
| 285 if (cache_impl_) |
| 286 return cache_impl_->IsAllocAllowed(current_size, new_size); |
| 287 if (cache_impl_v3_) |
| 288 return cache_impl_v3_->IsAllocAllowed(current_size, new_size, false); |
| 289 return false; |
| 290 } |
| 291 |
| 292 void DiskCacheTestWithCache::BufferDeleted(int size) { |
| 293 if (cache_impl_) |
| 294 cache_impl_->BufferDeleted(size); |
| 295 else if (cache_impl_v3_) |
| 296 cache_impl_v3_->BufferDeleted(size); |
| 297 } |
| 298 |
| 299 int DiskCacheTestWithCache::GetTotalBuffersSize() { |
| 300 if (cache_impl_) |
| 301 return cache_impl_->GetTotalBuffersSize(); |
| 302 if (cache_impl_v3_) |
| 303 return cache_impl_v3_->GetTotalBuffersSize(); |
| 304 return 0; |
| 305 } |
| 306 |
| 307 void DiskCacheTestWithCache::SetNoBuffering() { |
| 308 EXPECT_TRUE(cache_); |
| 309 if (cache_impl_) |
| 310 cache_impl_->SetFlags(disk_cache::kNoBuffering); |
| 311 else if (cache_impl_v3_) |
| 312 cache_impl_v3_->SetFlags(disk_cache::BackendImplV3::NO_BUFFERING); |
| 313 } |
| 314 |
| 315 void DiskCacheTestWithCache::WaitForEntryToClose(const std::string& key) { |
| 316 FlushQueueForTest(); |
| 317 if (!cache_impl_v3_) |
| 318 return; |
| 319 |
| 320 net::TestCompletionCallback cb; |
| 321 cache_impl_v3_->AddDelayForTest(30); |
| 322 int rv = cache_impl_v3_->WaitForEntryToCloseForTest(key, cb.callback()); |
| 323 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
| 324 } |
| 325 |
210 void DiskCacheTestWithCache::TrimForTest(bool empty) { | 326 void DiskCacheTestWithCache::TrimForTest(bool empty) { |
211 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimForTest, | 327 if (cache_impl_) { |
212 base::Unretained(cache_impl_), | 328 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimForTest, |
213 empty)); | 329 base::Unretained(cache_impl_), empty)); |
| 330 } else { |
| 331 cache_impl_v3_->TrimForTest(empty); |
| 332 } |
214 } | 333 } |
215 | 334 |
216 void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) { | 335 void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) { |
217 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimDeletedListForTest, | 336 if (cache_impl_) { |
218 base::Unretained(cache_impl_), | 337 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimDeletedListForTest, |
219 empty)); | 338 base::Unretained(cache_impl_), empty)); |
| 339 } else { |
| 340 cache_impl_v3_->TrimDeletedListForTest(empty); |
| 341 } |
| 342 } |
| 343 |
| 344 base::Time DiskCacheTestWithCache::GetTime() { |
| 345 if (cache_impl_v3_) { |
| 346 return cache_impl_v3_->GetTime(); |
| 347 } else { |
| 348 return base::Time::Now(); |
| 349 } |
| 350 } |
| 351 |
| 352 void DiskCacheTestWithCache::AddDelayForTest(int seconds) { |
| 353 if (cache_impl_v3_) { |
| 354 cache_impl_v3_->AddDelayForTest(seconds); |
| 355 } else { |
| 356 AddDelay(); |
| 357 } |
220 } | 358 } |
221 | 359 |
222 void DiskCacheTestWithCache::AddDelay() { | 360 void DiskCacheTestWithCache::AddDelay() { |
223 base::Time initial = base::Time::Now(); | 361 base::Time initial = base::Time::Now(); |
224 while (base::Time::Now() <= initial) { | 362 while (base::Time::Now() <= initial) { |
225 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | 363 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
226 }; | 364 }; |
227 } | 365 } |
228 | 366 |
229 void DiskCacheTestWithCache::TearDown() { | 367 void DiskCacheTestWithCache::TearDown() { |
230 base::RunLoop().RunUntilIdle(); | 368 CleanupForTest(); |
231 delete cache_; | 369 delete cache_; |
232 if (cache_thread_.IsRunning()) | 370 if (cache_thread_.IsRunning()) |
233 cache_thread_.Stop(); | 371 cache_thread_.Stop(); |
234 | 372 |
| 373 base::RunLoop().RunUntilIdle(); |
| 374 |
235 if (!memory_only_ && !simple_cache_mode_ && integrity_) { | 375 if (!memory_only_ && !simple_cache_mode_ && integrity_) { |
236 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); | 376 if (!v3_) |
| 377 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
237 } | 378 } |
238 | 379 |
239 PlatformTest::TearDown(); | 380 PlatformTest::TearDown(); |
240 } | 381 } |
241 | 382 |
242 void DiskCacheTestWithCache::InitMemoryCache() { | 383 void DiskCacheTestWithCache::InitMemoryCache() { |
243 mem_cache_ = new disk_cache::MemBackendImpl(NULL); | 384 mem_cache_ = new disk_cache::MemBackendImpl(NULL); |
244 cache_ = mem_cache_; | 385 cache_ = mem_cache_; |
245 ASSERT_TRUE(NULL != cache_); | 386 ASSERT_TRUE(NULL != cache_); |
246 | 387 |
247 if (size_) | 388 if (size_) |
248 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); | 389 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); |
249 | 390 |
250 ASSERT_TRUE(mem_cache_->Init()); | 391 ASSERT_TRUE(mem_cache_->Init()); |
251 } | 392 } |
252 | 393 |
253 void DiskCacheTestWithCache::InitDiskCache() { | 394 void DiskCacheTestWithCache::InitDiskCache() { |
254 if (first_cleanup_) | 395 if (first_cleanup_) |
255 ASSERT_TRUE(CleanupCacheDir()); | 396 ASSERT_TRUE(CleanupCacheDir()); |
256 | 397 |
257 if (!cache_thread_.IsRunning()) { | 398 if (!cache_thread_.IsRunning()) { |
258 ASSERT_TRUE(cache_thread_.StartWithOptions( | 399 ASSERT_TRUE(cache_thread_.StartWithOptions( |
259 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 400 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
260 } | 401 } |
261 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | 402 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
262 | 403 |
263 CreateBackend(disk_cache::kNoRandom, &cache_thread_); | 404 CreateBackend(&cache_thread_); |
264 } | 405 } |
265 | 406 |
266 void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { | 407 void DiskCacheTestWithCache::CreateBackend(base::Thread* thread) { |
267 base::MessageLoopProxy* runner; | 408 base::MessageLoopProxy* runner; |
268 if (use_current_thread_) | 409 if (use_current_thread_) |
269 runner = base::MessageLoopProxy::current(); | 410 runner = base::MessageLoopProxy::current(); |
270 else | 411 else |
271 runner = thread->message_loop_proxy(); | 412 runner = thread->message_loop_proxy(); |
272 | 413 |
273 if (simple_cache_mode_) { | 414 if (simple_cache_mode_) { |
274 net::TestCompletionCallback cb; | 415 net::TestCompletionCallback cb; |
275 disk_cache::SimpleBackendImpl* simple_backend = | 416 disk_cache::SimpleBackendImpl* simple_backend = |
276 new disk_cache::SimpleBackendImpl(cache_path_, size_, type_, | 417 new disk_cache::SimpleBackendImpl(cache_path_, size_, type_, |
277 make_scoped_refptr(runner), NULL); | 418 make_scoped_refptr(runner), NULL); |
278 int rv = simple_backend->Init(cb.callback()); | 419 int rv = simple_backend->Init(cb.callback()); |
279 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 420 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
280 cache_ = simple_cache_impl_ = simple_backend; | 421 cache_ = simple_cache_impl_ = simple_backend; |
281 return; | 422 return; |
282 } | 423 } |
283 | 424 |
284 if (mask_) | 425 if (mask_) |
285 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); | 426 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); |
| 427 else if (v3_) |
| 428 cache_impl_v3_ = new disk_cache::BackendImplV3(cache_path_, runner, NULL); |
286 else | 429 else |
287 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); | 430 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); |
288 cache_ = cache_impl_; | 431 cache_ = cache_impl_; |
| 432 if (!cache_) |
| 433 cache_ = cache_impl_v3_; |
289 ASSERT_TRUE(NULL != cache_); | 434 ASSERT_TRUE(NULL != cache_); |
290 if (size_) | |
291 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | |
292 if (new_eviction_) | |
293 cache_impl_->SetNewEviction(); | |
294 cache_impl_->SetType(type_); | |
295 cache_impl_->SetFlags(flags); | |
296 net::TestCompletionCallback cb; | 435 net::TestCompletionCallback cb; |
297 int rv = cache_impl_->Init(cb.callback()); | 436 int rv = 0; |
| 437 if (cache_impl_) { |
| 438 if (size_) |
| 439 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
| 440 if (new_eviction_) |
| 441 cache_impl_->SetNewEviction(); |
| 442 |
| 443 cache_impl_->SetType(type_); |
| 444 if (unit_test_mode_) |
| 445 cache_impl_->SetFlags(disk_cache::kUnitTestMode); |
| 446 if (!avoid_test_flag_) |
| 447 cache_impl_->SetFlags(disk_cache::kNoRandom); |
| 448 rv = cache_impl_->Init(cb.callback()); |
| 449 } else { |
| 450 if (size_) |
| 451 EXPECT_TRUE(cache_impl_v3_->SetMaxSize(size_)); |
| 452 if (new_eviction_) |
| 453 cache_impl_v3_->SetNewEviction(); |
| 454 |
| 455 cache_impl_v3_->SetType(type_); |
| 456 cache_impl_v3_->SetFlags(disk_cache::BackendImplV3::BASIC_UNIT_TEST); |
| 457 if (unit_test_mode_) |
| 458 cache_impl_v3_->SetFlags(disk_cache::BackendImplV3::UNIT_TEST_MODE); |
| 459 rv = cache_impl_v3_->Init(cb.callback()); |
| 460 } |
298 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 461 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
299 cache_ = cache_impl_; | |
300 } | 462 } |
OLD | NEW |