| 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 "content/browser/appcache/appcache_disk_cache.h" | 5 #include "content/browser/appcache/appcache_disk_cache.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 callback_.Run(rv); | 191 callback_.Run(rv); |
| 192 } | 192 } |
| 193 | 193 |
| 194 base::WeakPtr<AppCacheDiskCache> owner_; | 194 base::WeakPtr<AppCacheDiskCache> owner_; |
| 195 Entry** entry_; | 195 Entry** entry_; |
| 196 net::CompletionCallback callback_; | 196 net::CompletionCallback callback_; |
| 197 disk_cache::Entry* entry_ptr_; | 197 disk_cache::Entry* entry_ptr_; |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 AppCacheDiskCache::AppCacheDiskCache() | 200 AppCacheDiskCache::AppCacheDiskCache() |
| 201 : is_disabled_(false), | 201 #if defined(APPCACHE_USE_SIMPLE_CACHE) |
| 202 weak_factory_(this) { | 202 : AppCacheDiskCache(true) |
| 203 #else |
| 204 : AppCacheDiskCache(false) |
| 205 #endif |
| 206 { |
| 203 } | 207 } |
| 204 | 208 |
| 205 AppCacheDiskCache::~AppCacheDiskCache() { | 209 AppCacheDiskCache::~AppCacheDiskCache() { |
| 206 Disable(); | 210 Disable(); |
| 207 } | 211 } |
| 208 | 212 |
| 209 int AppCacheDiskCache::InitWithDiskBackend( | 213 int AppCacheDiskCache::InitWithDiskBackend( |
| 210 const base::FilePath& disk_cache_directory, | 214 const base::FilePath& disk_cache_directory, |
| 211 int disk_cache_size, | 215 int disk_cache_size, |
| 212 bool force, | 216 bool force, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 pending_calls_.push_back(PendingCall(DOOM, key, NULL, callback)); | 301 pending_calls_.push_back(PendingCall(DOOM, key, NULL, callback)); |
| 298 return net::ERR_IO_PENDING; | 302 return net::ERR_IO_PENDING; |
| 299 } | 303 } |
| 300 | 304 |
| 301 if (!disk_cache_) | 305 if (!disk_cache_) |
| 302 return net::ERR_FAILED; | 306 return net::ERR_FAILED; |
| 303 | 307 |
| 304 return ActiveCall::DoomEntry(weak_factory_.GetWeakPtr(), key, callback); | 308 return ActiveCall::DoomEntry(weak_factory_.GetWeakPtr(), key, callback); |
| 305 } | 309 } |
| 306 | 310 |
| 311 AppCacheDiskCache::AppCacheDiskCache(bool use_simple_cache) |
| 312 : use_simple_cache_(use_simple_cache), |
| 313 is_disabled_(false), |
| 314 weak_factory_(this) { |
| 315 } |
| 316 |
| 307 AppCacheDiskCache::PendingCall::PendingCall() | 317 AppCacheDiskCache::PendingCall::PendingCall() |
| 308 : call_type(CREATE), | 318 : call_type(CREATE), |
| 309 key(0), | 319 key(0), |
| 310 entry(NULL) { | 320 entry(NULL) { |
| 311 } | 321 } |
| 312 | 322 |
| 313 AppCacheDiskCache::PendingCall::PendingCall(PendingCallType call_type, | 323 AppCacheDiskCache::PendingCall::PendingCall(PendingCallType call_type, |
| 314 int64 key, | 324 int64 key, |
| 315 Entry** entry, | 325 Entry** entry, |
| 316 const net::CompletionCallback& callback) | 326 const net::CompletionCallback& callback) |
| 317 : call_type(call_type), | 327 : call_type(call_type), |
| 318 key(key), | 328 key(key), |
| 319 entry(entry), | 329 entry(entry), |
| 320 callback(callback) { | 330 callback(callback) { |
| 321 } | 331 } |
| 322 | 332 |
| 323 AppCacheDiskCache::PendingCall::~PendingCall() {} | 333 AppCacheDiskCache::PendingCall::~PendingCall() {} |
| 324 | 334 |
| 325 int AppCacheDiskCache::Init( | 335 int AppCacheDiskCache::Init( |
| 326 net::CacheType cache_type, | 336 net::CacheType cache_type, |
| 327 const base::FilePath& cache_directory, | 337 const base::FilePath& cache_directory, |
| 328 int cache_size, | 338 int cache_size, |
| 329 bool force, | 339 bool force, |
| 330 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, | 340 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, |
| 331 const net::CompletionCallback& callback) { | 341 const net::CompletionCallback& callback) { |
| 332 DCHECK(!is_initializing() && !disk_cache_.get()); | 342 DCHECK(!is_initializing() && !disk_cache_.get()); |
| 333 is_disabled_ = false; | 343 is_disabled_ = false; |
| 334 create_backend_callback_ = new CreateBackendCallbackShim(this); | 344 create_backend_callback_ = new CreateBackendCallbackShim(this); |
| 335 | 345 |
| 336 #if defined(APPCACHE_USE_SIMPLE_CACHE) | |
| 337 const net::BackendType backend_type = net::CACHE_BACKEND_SIMPLE; | |
| 338 #else | |
| 339 const net::BackendType backend_type = net::CACHE_BACKEND_DEFAULT; | |
| 340 #endif | |
| 341 int rv = disk_cache::CreateCacheBackend( | 346 int rv = disk_cache::CreateCacheBackend( |
| 342 cache_type, | 347 cache_type, |
| 343 backend_type, | 348 use_simple_cache_ ? net::CACHE_BACKEND_SIMPLE |
| 349 : net::CACHE_BACKEND_DEFAULT, |
| 344 cache_directory, | 350 cache_directory, |
| 345 cache_size, | 351 cache_size, |
| 346 force, | 352 force, |
| 347 cache_thread, | 353 cache_thread, |
| 348 NULL, | 354 NULL, |
| 349 &(create_backend_callback_->backend_ptr_), | 355 &(create_backend_callback_->backend_ptr_), |
| 350 base::Bind(&CreateBackendCallbackShim::Callback, | 356 base::Bind(&CreateBackendCallbackShim::Callback, |
| 351 create_backend_callback_)); | 357 create_backend_callback_)); |
| 352 if (rv == net::ERR_IO_PENDING) | 358 if (rv == net::ERR_IO_PENDING) |
| 353 init_callback_ = callback; | 359 init_callback_ = callback; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 NOTREACHED(); | 392 NOTREACHED(); |
| 387 break; | 393 break; |
| 388 } | 394 } |
| 389 if (rv != net::ERR_IO_PENDING) | 395 if (rv != net::ERR_IO_PENDING) |
| 390 iter->callback.Run(rv); | 396 iter->callback.Run(rv); |
| 391 } | 397 } |
| 392 pending_calls_.clear(); | 398 pending_calls_.clear(); |
| 393 } | 399 } |
| 394 | 400 |
| 395 } // namespace content | 401 } // namespace content |
| OLD | NEW |