| 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 if (!cache_impl_v3_) |
| 317 return FlushQueueForTest(); |
| 318 |
| 319 net::TestCompletionCallback cb; |
| 320 int rv = cache_impl_v3_->WaitForEntryToCloseForTest(key, cb.callback()); |
| 321 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
| 322 } |
| 323 |
| 210 void DiskCacheTestWithCache::TrimForTest(bool empty) { | 324 void DiskCacheTestWithCache::TrimForTest(bool empty) { |
| 211 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimForTest, | 325 if (cache_impl_) { |
| 212 base::Unretained(cache_impl_), | 326 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimForTest, |
| 213 empty)); | 327 base::Unretained(cache_impl_), empty)); |
| 328 } else { |
| 329 cache_impl_v3_->TrimForTest(empty); |
| 330 } |
| 214 } | 331 } |
| 215 | 332 |
| 216 void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) { | 333 void DiskCacheTestWithCache::TrimDeletedListForTest(bool empty) { |
| 217 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimDeletedListForTest, | 334 if (cache_impl_) { |
| 218 base::Unretained(cache_impl_), | 335 RunTaskForTest(base::Bind(&disk_cache::BackendImpl::TrimDeletedListForTest, |
| 219 empty)); | 336 base::Unretained(cache_impl_), empty)); |
| 337 } else { |
| 338 cache_impl_v3_->TrimDeletedListForTest(empty); |
| 339 } |
| 340 } |
| 341 |
| 342 base::Time DiskCacheTestWithCache::GetCurrentTime() { |
| 343 if (cache_impl_v3_) { |
| 344 return cache_impl_v3_->GetCurrentTime(); |
| 345 } else { |
| 346 return base::Time::Now(); |
| 347 } |
| 348 } |
| 349 |
| 350 void DiskCacheTestWithCache::AddDelayForTest(int seconds) { |
| 351 if (cache_impl_v3_) { |
| 352 cache_impl_v3_->AddDelayForTest(seconds); |
| 353 } else { |
| 354 AddDelay(); |
| 355 } |
| 220 } | 356 } |
| 221 | 357 |
| 222 void DiskCacheTestWithCache::AddDelay() { | 358 void DiskCacheTestWithCache::AddDelay() { |
| 223 base::Time initial = base::Time::Now(); | 359 base::Time initial = base::Time::Now(); |
| 224 while (base::Time::Now() <= initial) { | 360 while (base::Time::Now() <= initial) { |
| 225 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | 361 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
| 226 }; | 362 }; |
| 227 } | 363 } |
| 228 | 364 |
| 229 void DiskCacheTestWithCache::TearDown() { | 365 void DiskCacheTestWithCache::TearDown() { |
| 230 base::RunLoop().RunUntilIdle(); | 366 CleanupForTest(); |
| 231 delete cache_; | 367 delete cache_; |
| 232 if (cache_thread_.IsRunning()) | 368 if (cache_thread_.IsRunning()) |
| 233 cache_thread_.Stop(); | 369 cache_thread_.Stop(); |
| 234 | 370 |
| 371 base::RunLoop().RunUntilIdle(); |
| 372 |
| 235 if (!memory_only_ && !simple_cache_mode_ && integrity_) { | 373 if (!memory_only_ && !simple_cache_mode_ && integrity_) { |
| 236 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); | 374 if (!v3_) |
| 375 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); |
| 237 } | 376 } |
| 238 | 377 |
| 239 PlatformTest::TearDown(); | 378 PlatformTest::TearDown(); |
| 240 } | 379 } |
| 241 | 380 |
| 242 void DiskCacheTestWithCache::InitMemoryCache() { | 381 void DiskCacheTestWithCache::InitMemoryCache() { |
| 243 mem_cache_ = new disk_cache::MemBackendImpl(NULL); | 382 mem_cache_ = new disk_cache::MemBackendImpl(NULL); |
| 244 cache_ = mem_cache_; | 383 cache_ = mem_cache_; |
| 245 ASSERT_TRUE(NULL != cache_); | 384 ASSERT_TRUE(NULL != cache_); |
| 246 | 385 |
| 247 if (size_) | 386 if (size_) |
| 248 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); | 387 EXPECT_TRUE(mem_cache_->SetMaxSize(size_)); |
| 249 | 388 |
| 250 ASSERT_TRUE(mem_cache_->Init()); | 389 ASSERT_TRUE(mem_cache_->Init()); |
| 251 } | 390 } |
| 252 | 391 |
| 253 void DiskCacheTestWithCache::InitDiskCache() { | 392 void DiskCacheTestWithCache::InitDiskCache() { |
| 254 if (first_cleanup_) | 393 if (first_cleanup_) |
| 255 ASSERT_TRUE(CleanupCacheDir()); | 394 ASSERT_TRUE(CleanupCacheDir()); |
| 256 | 395 |
| 257 if (!cache_thread_.IsRunning()) { | 396 if (!cache_thread_.IsRunning()) { |
| 258 ASSERT_TRUE(cache_thread_.StartWithOptions( | 397 ASSERT_TRUE(cache_thread_.StartWithOptions( |
| 259 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | 398 base::Thread::Options(MessageLoop::TYPE_IO, 0))); |
| 260 } | 399 } |
| 261 ASSERT_TRUE(cache_thread_.message_loop() != NULL); | 400 ASSERT_TRUE(cache_thread_.message_loop() != NULL); |
| 262 | 401 |
| 263 CreateBackend(disk_cache::kNoRandom, &cache_thread_); | 402 CreateBackend(&cache_thread_); |
| 264 } | 403 } |
| 265 | 404 |
| 266 void DiskCacheTestWithCache::CreateBackend(uint32 flags, base::Thread* thread) { | 405 void DiskCacheTestWithCache::CreateBackend(base::Thread* thread) { |
| 267 base::MessageLoopProxy* runner; | 406 base::MessageLoopProxy* runner; |
| 268 if (use_current_thread_) | 407 if (use_current_thread_) |
| 269 runner = base::MessageLoopProxy::current(); | 408 runner = base::MessageLoopProxy::current(); |
| 270 else | 409 else |
| 271 runner = thread->message_loop_proxy(); | 410 runner = thread->message_loop_proxy(); |
| 272 | 411 |
| 273 if (simple_cache_mode_) { | 412 if (simple_cache_mode_) { |
| 274 net::TestCompletionCallback cb; | 413 net::TestCompletionCallback cb; |
| 275 disk_cache::SimpleBackendImpl* simple_backend = | 414 disk_cache::SimpleBackendImpl* simple_backend = |
| 276 new disk_cache::SimpleBackendImpl(cache_path_, size_, type_, | 415 new disk_cache::SimpleBackendImpl(cache_path_, size_, type_, |
| 277 make_scoped_refptr(runner), NULL); | 416 make_scoped_refptr(runner), NULL); |
| 278 int rv = simple_backend->Init(cb.callback()); | 417 int rv = simple_backend->Init(cb.callback()); |
| 279 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 418 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 280 cache_ = simple_cache_impl_ = simple_backend; | 419 cache_ = simple_cache_impl_ = simple_backend; |
| 281 return; | 420 return; |
| 282 } | 421 } |
| 283 | 422 |
| 284 if (mask_) | 423 if (mask_) |
| 285 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); | 424 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); |
| 425 else if (v3_) |
| 426 cache_impl_v3_ = new disk_cache::BackendImplV3(cache_path_, runner, NULL); |
| 286 else | 427 else |
| 287 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); | 428 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); |
| 288 cache_ = cache_impl_; | 429 cache_ = cache_impl_; |
| 430 if (!cache_) |
| 431 cache_ = cache_impl_v3_; |
| 289 ASSERT_TRUE(NULL != cache_); | 432 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; | 433 net::TestCompletionCallback cb; |
| 297 int rv = cache_impl_->Init(cb.callback()); | 434 int rv = 0; |
| 435 if (cache_impl_) { |
| 436 if (size_) |
| 437 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
| 438 if (new_eviction_) |
| 439 cache_impl_->SetNewEviction(); |
| 440 |
| 441 cache_impl_->SetType(type_); |
| 442 if (unit_test_mode_) |
| 443 cache_impl_->SetFlags(disk_cache::kUnitTestMode); |
| 444 if (!avoid_test_flag_) |
| 445 cache_impl_->SetFlags(disk_cache::kNoRandom); |
| 446 rv = cache_impl_->Init(cb.callback()); |
| 447 } else { |
| 448 if (size_) |
| 449 EXPECT_TRUE(cache_impl_v3_->SetMaxSize(size_)); |
| 450 if (new_eviction_) |
| 451 cache_impl_v3_->SetNewEviction(); |
| 452 |
| 453 cache_impl_v3_->SetType(type_); |
| 454 cache_impl_v3_->SetFlags(disk_cache::BackendImplV3::BASIC_UNIT_TEST); |
| 455 if (unit_test_mode_) |
| 456 cache_impl_v3_->SetFlags(disk_cache::BackendImplV3::UNIT_TEST_MODE); |
| 457 rv = cache_impl_v3_->Init(cb.callback()); |
| 458 } |
| 298 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 459 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 299 cache_ = cache_impl_; | |
| 300 } | 460 } |
| OLD | NEW |