Chromium Code Reviews| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 delete this; | 170 delete this; |
| 171 } | 171 } |
| 172 | 172 |
| 173 Entry** entry_; | 173 Entry** entry_; |
| 174 net::CompletionCallback callback_; | 174 net::CompletionCallback callback_; |
| 175 AppCacheDiskCache* owner_; | 175 AppCacheDiskCache* owner_; |
| 176 disk_cache::Entry* entry_ptr_; | 176 disk_cache::Entry* entry_ptr_; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 AppCacheDiskCache::AppCacheDiskCache() | 179 AppCacheDiskCache::AppCacheDiskCache() |
| 180 : is_disabled_(false) { | 180 #if defined(APPCACHE_USE_SIMPLE_CACHE) |
| 181 : use_simple_cache_(true) | |
|
kinuko
2015/05/15 02:28:48
nit: we can use delegated ctor too
nhiroki
2015/05/15 03:02:47
Done (I thought delegated ctor was still under dis
| |
| 182 #endif | |
| 183 { | |
| 181 } | 184 } |
| 182 | 185 |
| 183 AppCacheDiskCache::~AppCacheDiskCache() { | 186 AppCacheDiskCache::~AppCacheDiskCache() { |
| 184 Disable(); | 187 Disable(); |
| 185 } | 188 } |
| 186 | 189 |
| 187 int AppCacheDiskCache::InitWithDiskBackend( | 190 int AppCacheDiskCache::InitWithDiskBackend( |
| 188 const base::FilePath& disk_cache_directory, | 191 const base::FilePath& disk_cache_directory, |
| 189 int disk_cache_size, | 192 int disk_cache_size, |
| 190 bool force, | 193 bool force, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 274 pending_calls_.push_back(PendingCall(DOOM, key, NULL, callback)); | 277 pending_calls_.push_back(PendingCall(DOOM, key, NULL, callback)); |
| 275 return net::ERR_IO_PENDING; | 278 return net::ERR_IO_PENDING; |
| 276 } | 279 } |
| 277 | 280 |
| 278 if (!disk_cache_) | 281 if (!disk_cache_) |
| 279 return net::ERR_FAILED; | 282 return net::ERR_FAILED; |
| 280 | 283 |
| 281 return (new ActiveCall(this))->DoomEntry(key, callback); | 284 return (new ActiveCall(this))->DoomEntry(key, callback); |
| 282 } | 285 } |
| 283 | 286 |
| 287 AppCacheDiskCache::AppCacheDiskCache(bool use_simple_cache) | |
| 288 : use_simple_cache_(use_simple_cache) { | |
| 289 } | |
| 290 | |
| 284 AppCacheDiskCache::PendingCall::PendingCall() | 291 AppCacheDiskCache::PendingCall::PendingCall() |
| 285 : call_type(CREATE), | 292 : call_type(CREATE), |
| 286 key(0), | 293 key(0), |
| 287 entry(NULL) { | 294 entry(NULL) { |
| 288 } | 295 } |
| 289 | 296 |
| 290 AppCacheDiskCache::PendingCall::PendingCall(PendingCallType call_type, | 297 AppCacheDiskCache::PendingCall::PendingCall(PendingCallType call_type, |
| 291 int64 key, | 298 int64 key, |
| 292 Entry** entry, | 299 Entry** entry, |
| 293 const net::CompletionCallback& callback) | 300 const net::CompletionCallback& callback) |
| 294 : call_type(call_type), | 301 : call_type(call_type), |
| 295 key(key), | 302 key(key), |
| 296 entry(entry), | 303 entry(entry), |
| 297 callback(callback) { | 304 callback(callback) { |
| 298 } | 305 } |
| 299 | 306 |
| 300 AppCacheDiskCache::PendingCall::~PendingCall() {} | 307 AppCacheDiskCache::PendingCall::~PendingCall() {} |
| 301 | 308 |
| 302 int AppCacheDiskCache::Init( | 309 int AppCacheDiskCache::Init( |
| 303 net::CacheType cache_type, | 310 net::CacheType cache_type, |
| 304 const base::FilePath& cache_directory, | 311 const base::FilePath& cache_directory, |
| 305 int cache_size, | 312 int cache_size, |
| 306 bool force, | 313 bool force, |
| 307 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, | 314 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, |
| 308 const net::CompletionCallback& callback) { | 315 const net::CompletionCallback& callback) { |
| 309 DCHECK(!is_initializing() && !disk_cache_.get()); | 316 DCHECK(!is_initializing() && !disk_cache_.get()); |
| 310 is_disabled_ = false; | 317 is_disabled_ = false; |
| 311 create_backend_callback_ = new CreateBackendCallbackShim(this); | 318 create_backend_callback_ = new CreateBackendCallbackShim(this); |
| 312 | 319 |
| 313 #if defined(APPCACHE_USE_SIMPLE_CACHE) | |
| 314 const net::BackendType backend_type = net::CACHE_BACKEND_SIMPLE; | |
| 315 #else | |
| 316 const net::BackendType backend_type = net::CACHE_BACKEND_DEFAULT; | |
| 317 #endif | |
| 318 int rv = disk_cache::CreateCacheBackend( | 320 int rv = disk_cache::CreateCacheBackend( |
| 319 cache_type, | 321 cache_type, |
| 320 backend_type, | 322 use_simple_cache_ ? net::CACHE_BACKEND_SIMPLE |
| 323 : net::CACHE_BACKEND_DEFAULT, | |
| 321 cache_directory, | 324 cache_directory, |
| 322 cache_size, | 325 cache_size, |
| 323 force, | 326 force, |
| 324 cache_thread, | 327 cache_thread, |
| 325 NULL, | 328 NULL, |
| 326 &(create_backend_callback_->backend_ptr_), | 329 &(create_backend_callback_->backend_ptr_), |
| 327 base::Bind(&CreateBackendCallbackShim::Callback, | 330 base::Bind(&CreateBackendCallbackShim::Callback, |
| 328 create_backend_callback_)); | 331 create_backend_callback_)); |
| 329 if (rv == net::ERR_IO_PENDING) | 332 if (rv == net::ERR_IO_PENDING) |
| 330 init_callback_ = callback; | 333 init_callback_ = callback; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 NOTREACHED(); | 366 NOTREACHED(); |
| 364 break; | 367 break; |
| 365 } | 368 } |
| 366 if (rv != net::ERR_IO_PENDING) | 369 if (rv != net::ERR_IO_PENDING) |
| 367 iter->callback.Run(rv); | 370 iter->callback.Run(rv); |
| 368 } | 371 } |
| 369 pending_calls_.clear(); | 372 pending_calls_.clear(); |
| 370 } | 373 } |
| 371 | 374 |
| 372 } // namespace content | 375 } // namespace content |
| OLD | NEW |