| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 bool DiskCacheTest::CleanupCacheDir() { | 49 bool DiskCacheTest::CleanupCacheDir() { |
| 50 return DeleteCache(cache_path_); | 50 return DeleteCache(cache_path_); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void DiskCacheTest::TearDown() { | 53 void DiskCacheTest::TearDown() { |
| 54 base::RunLoop().RunUntilIdle(); | 54 base::RunLoop().RunUntilIdle(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 DiskCacheTestWithCache::TestIterator::TestIterator( | 57 DiskCacheTestWithCache::TestIterator::TestIterator( |
| 58 scoped_ptr<disk_cache::Backend::Iterator> iterator) | 58 std::unique_ptr<disk_cache::Backend::Iterator> iterator) |
| 59 : iterator_(std::move(iterator)) {} | 59 : iterator_(std::move(iterator)) {} |
| 60 | 60 |
| 61 DiskCacheTestWithCache::TestIterator::~TestIterator() {} | 61 DiskCacheTestWithCache::TestIterator::~TestIterator() {} |
| 62 | 62 |
| 63 int DiskCacheTestWithCache::TestIterator::OpenNextEntry( | 63 int DiskCacheTestWithCache::TestIterator::OpenNextEntry( |
| 64 disk_cache::Entry** next_entry) { | 64 disk_cache::Entry** next_entry) { |
| 65 net::TestCompletionCallback cb; | 65 net::TestCompletionCallback cb; |
| 66 int rv = iterator_->OpenNextEntry(next_entry, cb.callback()); | 66 int rv = iterator_->OpenNextEntry(next_entry, cb.callback()); |
| 67 return cb.GetResult(rv); | 67 return cb.GetResult(rv); |
| 68 } | 68 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 int rv = cache_->DoomEntriesSince(initial_time, cb.callback()); | 167 int rv = cache_->DoomEntriesSince(initial_time, cb.callback()); |
| 168 return cb.GetResult(rv); | 168 return cb.GetResult(rv); |
| 169 } | 169 } |
| 170 | 170 |
| 171 int DiskCacheTestWithCache::CalculateSizeOfAllEntries() { | 171 int DiskCacheTestWithCache::CalculateSizeOfAllEntries() { |
| 172 net::TestCompletionCallback cb; | 172 net::TestCompletionCallback cb; |
| 173 int rv = cache_->CalculateSizeOfAllEntries(cb.callback()); | 173 int rv = cache_->CalculateSizeOfAllEntries(cb.callback()); |
| 174 return cb.GetResult(rv); | 174 return cb.GetResult(rv); |
| 175 } | 175 } |
| 176 | 176 |
| 177 scoped_ptr<DiskCacheTestWithCache::TestIterator> | 177 std::unique_ptr<DiskCacheTestWithCache::TestIterator> |
| 178 DiskCacheTestWithCache::CreateIterator() { | 178 DiskCacheTestWithCache::CreateIterator() { |
| 179 return scoped_ptr<TestIterator>(new TestIterator(cache_->CreateIterator())); | 179 return std::unique_ptr<TestIterator>( |
| 180 new TestIterator(cache_->CreateIterator())); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void DiskCacheTestWithCache::FlushQueueForTest() { | 183 void DiskCacheTestWithCache::FlushQueueForTest() { |
| 183 if (memory_only_ || !cache_impl_) | 184 if (memory_only_ || !cache_impl_) |
| 184 return; | 185 return; |
| 185 | 186 |
| 186 net::TestCompletionCallback cb; | 187 net::TestCompletionCallback cb; |
| 187 int rv = cache_impl_->FlushQueueForTest(cb.callback()); | 188 int rv = cache_impl_->FlushQueueForTest(cb.callback()); |
| 188 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 189 EXPECT_EQ(net::OK, cb.GetResult(rv)); |
| 189 } | 190 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 void DiskCacheTestWithCache::CreateBackend(uint32_t flags, | 306 void DiskCacheTestWithCache::CreateBackend(uint32_t flags, |
| 306 base::Thread* thread) { | 307 base::Thread* thread) { |
| 307 scoped_refptr<base::SingleThreadTaskRunner> runner; | 308 scoped_refptr<base::SingleThreadTaskRunner> runner; |
| 308 if (use_current_thread_) | 309 if (use_current_thread_) |
| 309 runner = base::ThreadTaskRunnerHandle::Get(); | 310 runner = base::ThreadTaskRunnerHandle::Get(); |
| 310 else | 311 else |
| 311 runner = thread->task_runner(); | 312 runner = thread->task_runner(); |
| 312 | 313 |
| 313 if (simple_cache_mode_) { | 314 if (simple_cache_mode_) { |
| 314 net::TestCompletionCallback cb; | 315 net::TestCompletionCallback cb; |
| 315 scoped_ptr<disk_cache::SimpleBackendImpl> simple_backend( | 316 std::unique_ptr<disk_cache::SimpleBackendImpl> simple_backend( |
| 316 new disk_cache::SimpleBackendImpl( | 317 new disk_cache::SimpleBackendImpl(cache_path_, size_, type_, runner, |
| 317 cache_path_, size_, type_, runner, NULL)); | 318 NULL)); |
| 318 int rv = simple_backend->Init(cb.callback()); | 319 int rv = simple_backend->Init(cb.callback()); |
| 319 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 320 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 320 simple_cache_impl_ = simple_backend.get(); | 321 simple_cache_impl_ = simple_backend.get(); |
| 321 cache_ = std::move(simple_backend); | 322 cache_ = std::move(simple_backend); |
| 322 if (simple_cache_wait_for_index_) { | 323 if (simple_cache_wait_for_index_) { |
| 323 net::TestCompletionCallback wait_for_index_cb; | 324 net::TestCompletionCallback wait_for_index_cb; |
| 324 rv = simple_cache_impl_->index()->ExecuteWhenReady( | 325 rv = simple_cache_impl_->index()->ExecuteWhenReady( |
| 325 wait_for_index_cb.callback()); | 326 wait_for_index_cb.callback()); |
| 326 ASSERT_EQ(net::OK, wait_for_index_cb.GetResult(rv)); | 327 ASSERT_EQ(net::OK, wait_for_index_cb.GetResult(rv)); |
| 327 } | 328 } |
| 328 return; | 329 return; |
| 329 } | 330 } |
| 330 | 331 |
| 331 if (mask_) | 332 if (mask_) |
| 332 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); | 333 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); |
| 333 else | 334 else |
| 334 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); | 335 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); |
| 335 cache_.reset(cache_impl_); | 336 cache_.reset(cache_impl_); |
| 336 ASSERT_TRUE(cache_); | 337 ASSERT_TRUE(cache_); |
| 337 if (size_) | 338 if (size_) |
| 338 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); | 339 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); |
| 339 if (new_eviction_) | 340 if (new_eviction_) |
| 340 cache_impl_->SetNewEviction(); | 341 cache_impl_->SetNewEviction(); |
| 341 cache_impl_->SetType(type_); | 342 cache_impl_->SetType(type_); |
| 342 cache_impl_->SetFlags(flags); | 343 cache_impl_->SetFlags(flags); |
| 343 net::TestCompletionCallback cb; | 344 net::TestCompletionCallback cb; |
| 344 int rv = cache_impl_->Init(cb.callback()); | 345 int rv = cache_impl_->Init(cb.callback()); |
| 345 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 346 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
| 346 } | 347 } |
| OLD | NEW |