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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 588 |
589 // See crbug.com/330074 | 589 // See crbug.com/330074 |
590 #if !defined(OS_IOS) | 590 #if !defined(OS_IOS) |
591 // Tests that one cache instance is not affected by another one going away. | 591 // Tests that one cache instance is not affected by another one going away. |
592 TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) { | 592 TEST_F(DiskCacheBackendTest, MultipleInstancesWithPendingFileIO) { |
593 base::ScopedTempDir store; | 593 base::ScopedTempDir store; |
594 ASSERT_TRUE(store.CreateUniqueTempDir()); | 594 ASSERT_TRUE(store.CreateUniqueTempDir()); |
595 | 595 |
596 net::TestCompletionCallback cb; | 596 net::TestCompletionCallback cb; |
597 std::unique_ptr<disk_cache::Backend> extra_cache; | 597 std::unique_ptr<disk_cache::Backend> extra_cache; |
598 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 598 int rv = disk_cache::CreateCacheBackend( |
599 net::CACHE_BACKEND_DEFAULT, | 599 net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store.GetPath(), 0, false, |
600 store.path(), | 600 base::ThreadTaskRunnerHandle::Get(), NULL, &extra_cache, cb.callback()); |
601 0, | |
602 false, | |
603 base::ThreadTaskRunnerHandle::Get(), | |
604 NULL, | |
605 &extra_cache, | |
606 cb.callback()); | |
607 ASSERT_THAT(cb.GetResult(rv), IsOk()); | 601 ASSERT_THAT(cb.GetResult(rv), IsOk()); |
608 ASSERT_TRUE(extra_cache.get() != NULL); | 602 ASSERT_TRUE(extra_cache.get() != NULL); |
609 | 603 |
610 ASSERT_TRUE(CleanupCacheDir()); | 604 ASSERT_TRUE(CleanupCacheDir()); |
611 SetNewEviction(); // Match the expected behavior for integrity verification. | 605 SetNewEviction(); // Match the expected behavior for integrity verification. |
612 UseCurrentThread(); | 606 UseCurrentThread(); |
613 | 607 |
614 CreateBackend(disk_cache::kNoBuffering, NULL); | 608 CreateBackend(disk_cache::kNoBuffering, NULL); |
615 rv = GeneratePendingIO(&cb); | 609 rv = GeneratePendingIO(&cb); |
616 | 610 |
(...skipping 2606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3223 ASSERT_TRUE(store2.CreateUniqueTempDir()); | 3217 ASSERT_TRUE(store2.CreateUniqueTempDir()); |
3224 | 3218 |
3225 base::Thread cache_thread("CacheThread"); | 3219 base::Thread cache_thread("CacheThread"); |
3226 ASSERT_TRUE(cache_thread.StartWithOptions( | 3220 ASSERT_TRUE(cache_thread.StartWithOptions( |
3227 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 3221 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
3228 net::TestCompletionCallback cb; | 3222 net::TestCompletionCallback cb; |
3229 | 3223 |
3230 const int kNumberOfCaches = 2; | 3224 const int kNumberOfCaches = 2; |
3231 std::unique_ptr<disk_cache::Backend> cache[kNumberOfCaches]; | 3225 std::unique_ptr<disk_cache::Backend> cache[kNumberOfCaches]; |
3232 | 3226 |
3233 int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, | 3227 int rv = disk_cache::CreateCacheBackend( |
3234 net::CACHE_BACKEND_DEFAULT, | 3228 net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, store1.GetPath(), 0, false, |
3235 store1.path(), | 3229 cache_thread.task_runner(), NULL, &cache[0], cb.callback()); |
3236 0, | |
3237 false, | |
3238 cache_thread.task_runner(), | |
3239 NULL, | |
3240 &cache[0], | |
3241 cb.callback()); | |
3242 ASSERT_THAT(cb.GetResult(rv), IsOk()); | 3230 ASSERT_THAT(cb.GetResult(rv), IsOk()); |
3243 rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, | 3231 rv = disk_cache::CreateCacheBackend( |
3244 net::CACHE_BACKEND_DEFAULT, | 3232 net::MEDIA_CACHE, net::CACHE_BACKEND_DEFAULT, store2.GetPath(), 0, false, |
3245 store2.path(), | 3233 cache_thread.task_runner(), NULL, &cache[1], cb.callback()); |
3246 0, | |
3247 false, | |
3248 cache_thread.task_runner(), | |
3249 NULL, | |
3250 &cache[1], | |
3251 cb.callback()); | |
3252 ASSERT_THAT(cb.GetResult(rv), IsOk()); | 3234 ASSERT_THAT(cb.GetResult(rv), IsOk()); |
3253 | 3235 |
3254 ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL); | 3236 ASSERT_TRUE(cache[0].get() != NULL && cache[1].get() != NULL); |
3255 | 3237 |
3256 std::string key("the first key"); | 3238 std::string key("the first key"); |
3257 disk_cache::Entry* entry; | 3239 disk_cache::Entry* entry; |
3258 for (int i = 0; i < kNumberOfCaches; i++) { | 3240 for (int i = 0; i < kNumberOfCaches; i++) { |
3259 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); | 3241 rv = cache[i]->CreateEntry(key, &entry, cb.callback()); |
3260 ASSERT_THAT(cb.GetResult(rv), IsOk()); | 3242 ASSERT_THAT(cb.GetResult(rv), IsOk()); |
3261 entry->Close(); | 3243 entry->Close(); |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3869 // because that would advance the cache directory mtime and invalidate the | 3851 // because that would advance the cache directory mtime and invalidate the |
3870 // index. | 3852 // index. |
3871 entry2->Doom(); | 3853 entry2->Doom(); |
3872 entry2->Close(); | 3854 entry2->Close(); |
3873 | 3855 |
3874 DisableFirstCleanup(); | 3856 DisableFirstCleanup(); |
3875 InitCache(); | 3857 InitCache(); |
3876 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, | 3858 EXPECT_EQ(disk_cache::SimpleIndex::INITIALIZE_METHOD_LOADED, |
3877 simple_cache_impl_->index()->init_method()); | 3859 simple_cache_impl_->index()->init_method()); |
3878 } | 3860 } |
OLD | NEW |