Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: net/disk_cache/disk_cache_test_base.cc

Issue 12794003: Initialize the simple cache backend at runtime. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/base/test_completion_callback.h" 11 #include "net/base/test_completion_callback.h"
12 #include "net/disk_cache/backend_impl.h" 12 #include "net/disk_cache/backend_impl.h"
13 #include "net/disk_cache/disk_cache.h"
13 #include "net/disk_cache/disk_cache_test_util.h" 14 #include "net/disk_cache/disk_cache_test_util.h"
14 #include "net/disk_cache/mem_backend_impl.h" 15 #include "net/disk_cache/mem_backend_impl.h"
15 16
16 DiskCacheTest::DiskCacheTest() { 17 DiskCacheTest::DiskCacheTest() {
17 CHECK(temp_dir_.CreateUniqueTempDir()); 18 CHECK(temp_dir_.CreateUniqueTempDir());
18 cache_path_ = temp_dir_.path(); 19 cache_path_ = temp_dir_.path();
19 if (!MessageLoop::current()) 20 if (!MessageLoop::current())
20 message_loop_.reset(new MessageLoopForIO()); 21 message_loop_.reset(new MessageLoopForIO());
21 } 22 }
22 23
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 void DiskCacheTestWithCache::InitDiskCache() { 254 void DiskCacheTestWithCache::InitDiskCache() {
254 if (first_cleanup_) 255 if (first_cleanup_)
255 ASSERT_TRUE(CleanupCacheDir()); 256 ASSERT_TRUE(CleanupCacheDir());
256 257
257 if (!cache_thread_.IsRunning()) { 258 if (!cache_thread_.IsRunning()) {
258 EXPECT_TRUE(cache_thread_.StartWithOptions( 259 EXPECT_TRUE(cache_thread_.StartWithOptions(
259 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 260 base::Thread::Options(MessageLoop::TYPE_IO, 0)));
260 } 261 }
261 ASSERT_TRUE(cache_thread_.message_loop() != NULL); 262 ASSERT_TRUE(cache_thread_.message_loop() != NULL);
262 263
264 // TODO(pasko,gavinp): run tests with Simple Cache as well.
263 if (implementation_) 265 if (implementation_)
264 return InitDiskCacheImpl(); 266 return InitDiskCacheImpl();
265 267
266 scoped_refptr<base::MessageLoopProxy> thread = 268 scoped_refptr<base::MessageLoopProxy> thread =
267 use_current_thread_ ? base::MessageLoopProxy::current() : 269 use_current_thread_ ? base::MessageLoopProxy::current() :
268 cache_thread_.message_loop_proxy(); 270 cache_thread_.message_loop_proxy();
269 271
270 net::TestCompletionCallback cb; 272 net::TestCompletionCallback cb;
271 int rv = disk_cache::BackendImpl::CreateBackend( 273 int rv = disk_cache::CreateCacheBackendWithFlags(type_, cache_path_, size_,
272 cache_path_, force_creation_, size_, type_, 274 force_creation_, disk_cache::kNoRandom, thread, NULL, &cache_,
273 disk_cache::kNoRandom, thread, NULL, &cache_, cb.callback()); 275 cb.callback());
276
274 ASSERT_EQ(net::OK, cb.GetResult(rv)); 277 ASSERT_EQ(net::OK, cb.GetResult(rv));
275 } 278 }
276 279
277 void DiskCacheTestWithCache::InitDiskCacheImpl() { 280 void DiskCacheTestWithCache::InitDiskCacheImpl() {
278 scoped_refptr<base::MessageLoopProxy> thread = 281 scoped_refptr<base::MessageLoopProxy> thread =
279 use_current_thread_ ? base::MessageLoopProxy::current() : 282 use_current_thread_ ? base::MessageLoopProxy::current() :
280 cache_thread_.message_loop_proxy(); 283 cache_thread_.message_loop_proxy();
281 if (mask_) 284 if (mask_)
282 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, thread, NULL); 285 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, thread, NULL);
283 else 286 else
284 cache_impl_ = new disk_cache::BackendImpl(cache_path_, thread, NULL); 287 cache_impl_ = new disk_cache::BackendImpl(cache_path_, thread, NULL);
285 288
286 cache_ = cache_impl_; 289 cache_ = cache_impl_;
287 ASSERT_TRUE(NULL != cache_); 290 ASSERT_TRUE(NULL != cache_);
288 291
289 if (size_) 292 if (size_)
290 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); 293 EXPECT_TRUE(cache_impl_->SetMaxSize(size_));
291 294
292 if (new_eviction_) 295 if (new_eviction_)
293 cache_impl_->SetNewEviction(); 296 cache_impl_->SetNewEviction();
294 297
295 cache_impl_->SetType(type_); 298 cache_impl_->SetType(type_);
296 cache_impl_->SetFlags(disk_cache::kNoRandom); 299 cache_impl_->SetFlags(disk_cache::kNoRandom);
297 net::TestCompletionCallback cb; 300 net::TestCompletionCallback cb;
298 int rv = cache_impl_->Init(cb.callback()); 301 int rv = cache_impl_->Init(cb.callback());
299 ASSERT_EQ(net::OK, cb.GetResult(rv)); 302 ASSERT_EQ(net::OK, cb.GetResult(rv));
300 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698