OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/hash.h" | 10 #include "base/hash.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 timer.Done(); | 158 timer.Done(); |
159 } | 159 } |
160 | 160 |
161 TEST_F(DiskCacheTest, CacheBackendPerformance) { | 161 TEST_F(DiskCacheTest, CacheBackendPerformance) { |
162 base::Thread cache_thread("CacheThread"); | 162 base::Thread cache_thread("CacheThread"); |
163 ASSERT_TRUE(cache_thread.StartWithOptions( | 163 ASSERT_TRUE(cache_thread.StartWithOptions( |
164 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 164 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
165 | 165 |
166 ASSERT_TRUE(CleanupCacheDir()); | 166 ASSERT_TRUE(CleanupCacheDir()); |
167 net::TestCompletionCallback cb; | 167 net::TestCompletionCallback cb; |
168 disk_cache::Backend* cache; | 168 scoped_ptr<disk_cache::Backend> cache; |
169 int rv = disk_cache::CreateCacheBackend( | 169 int rv = disk_cache::CreateCacheBackend( |
170 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false, | 170 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false, |
171 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback()); | 171 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback()); |
172 | 172 |
173 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 173 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
174 | 174 |
175 int seed = static_cast<int>(Time::Now().ToInternalValue()); | 175 int seed = static_cast<int>(Time::Now().ToInternalValue()); |
176 srand(seed); | 176 srand(seed); |
177 | 177 |
178 TestEntries entries; | 178 TestEntries entries; |
179 int num_entries = 1000; | 179 int num_entries = 1000; |
180 | 180 |
181 EXPECT_TRUE(TimeWrite(num_entries, cache, &entries)); | 181 EXPECT_TRUE(TimeWrite(num_entries, cache.get(), &entries)); |
182 | 182 |
183 base::MessageLoop::current()->RunUntilIdle(); | 183 base::MessageLoop::current()->RunUntilIdle(); |
184 delete cache; | 184 cache.reset(); |
185 | 185 |
186 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 186 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
187 cache_path_.AppendASCII("index"))); | 187 cache_path_.AppendASCII("index"))); |
188 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 188 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
189 cache_path_.AppendASCII("data_0"))); | 189 cache_path_.AppendASCII("data_0"))); |
190 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 190 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
191 cache_path_.AppendASCII("data_1"))); | 191 cache_path_.AppendASCII("data_1"))); |
192 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 192 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
193 cache_path_.AppendASCII("data_2"))); | 193 cache_path_.AppendASCII("data_2"))); |
194 ASSERT_TRUE(file_util::EvictFileFromSystemCache( | 194 ASSERT_TRUE(file_util::EvictFileFromSystemCache( |
195 cache_path_.AppendASCII("data_3"))); | 195 cache_path_.AppendASCII("data_3"))); |
196 | 196 |
197 rv = disk_cache::CreateCacheBackend( | 197 rv = disk_cache::CreateCacheBackend( |
198 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false, | 198 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false, |
199 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback()); | 199 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback()); |
200 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 200 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
201 | 201 |
202 EXPECT_TRUE(TimeRead(num_entries, cache, entries, true)); | 202 EXPECT_TRUE(TimeRead(num_entries, cache.get(), entries, true)); |
203 | 203 |
204 EXPECT_TRUE(TimeRead(num_entries, cache, entries, false)); | 204 EXPECT_TRUE(TimeRead(num_entries, cache.get(), entries, false)); |
205 | 205 |
206 base::MessageLoop::current()->RunUntilIdle(); | 206 base::MessageLoop::current()->RunUntilIdle(); |
207 delete cache; | |
208 } | 207 } |
209 | 208 |
210 // Creating and deleting "entries" on a block-file is something quite frequent | 209 // Creating and deleting "entries" on a block-file is something quite frequent |
211 // (after all, almost everything is stored on block files). The operation is | 210 // (after all, almost everything is stored on block files). The operation is |
212 // almost free when the file is empty, but can be expensive if the file gets | 211 // almost free when the file is empty, but can be expensive if the file gets |
213 // fragmented, or if we have multiple files. This test measures that scenario, | 212 // fragmented, or if we have multiple files. This test measures that scenario, |
214 // by using multiple, highly fragmented files. | 213 // by using multiple, highly fragmented files. |
215 TEST_F(DiskCacheTest, BlockFilesPerformance) { | 214 TEST_F(DiskCacheTest, BlockFilesPerformance) { |
216 ASSERT_TRUE(CleanupCacheDir()); | 215 ASSERT_TRUE(CleanupCacheDir()); |
217 | 216 |
(...skipping 24 matching lines...) Expand all Loading... |
242 | 241 |
243 files.DeleteBlock(address[entry], false); | 242 files.DeleteBlock(address[entry], false); |
244 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), | 243 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), |
245 &address[entry])); | 244 &address[entry])); |
246 } | 245 } |
247 | 246 |
248 timer2.Done(); | 247 timer2.Done(); |
249 base::MessageLoop::current()->RunUntilIdle(); | 248 base::MessageLoop::current()->RunUntilIdle(); |
250 delete[] address; | 249 delete[] address; |
251 } | 250 } |
OLD | NEW |