| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 disk_cache_.reset(); | 253 disk_cache_.reset(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 int AppCacheDiskCache::CreateEntry(int64 key, Entry** entry, | 256 int AppCacheDiskCache::CreateEntry(int64 key, Entry** entry, |
| 257 const net::CompletionCallback& callback) { | 257 const net::CompletionCallback& callback) { |
| 258 DCHECK(entry); | 258 DCHECK(entry); |
| 259 DCHECK(!callback.is_null()); | 259 DCHECK(!callback.is_null()); |
| 260 if (is_disabled_) | 260 if (is_disabled_) |
| 261 return net::ERR_ABORTED; | 261 return net::ERR_ABORTED; |
| 262 | 262 |
| 263 if (is_initializing()) { | 263 if (is_initializing_or_waiting_to_initialize()) { |
| 264 pending_calls_.push_back(PendingCall(CREATE, key, entry, callback)); | 264 pending_calls_.push_back(PendingCall(CREATE, key, entry, callback)); |
| 265 return net::ERR_IO_PENDING; | 265 return net::ERR_IO_PENDING; |
| 266 } | 266 } |
| 267 | 267 |
| 268 if (!disk_cache_) | 268 if (!disk_cache_) |
| 269 return net::ERR_FAILED; | 269 return net::ERR_FAILED; |
| 270 | 270 |
| 271 return ActiveCall::CreateEntry( | 271 return ActiveCall::CreateEntry( |
| 272 weak_factory_.GetWeakPtr(), key, entry, callback); | 272 weak_factory_.GetWeakPtr(), key, entry, callback); |
| 273 } | 273 } |
| 274 | 274 |
| 275 int AppCacheDiskCache::OpenEntry(int64 key, Entry** entry, | 275 int AppCacheDiskCache::OpenEntry(int64 key, Entry** entry, |
| 276 const net::CompletionCallback& callback) { | 276 const net::CompletionCallback& callback) { |
| 277 DCHECK(entry); | 277 DCHECK(entry); |
| 278 DCHECK(!callback.is_null()); | 278 DCHECK(!callback.is_null()); |
| 279 if (is_disabled_) | 279 if (is_disabled_) |
| 280 return net::ERR_ABORTED; | 280 return net::ERR_ABORTED; |
| 281 | 281 |
| 282 if (is_initializing()) { | 282 if (is_initializing_or_waiting_to_initialize()) { |
| 283 pending_calls_.push_back(PendingCall(OPEN, key, entry, callback)); | 283 pending_calls_.push_back(PendingCall(OPEN, key, entry, callback)); |
| 284 return net::ERR_IO_PENDING; | 284 return net::ERR_IO_PENDING; |
| 285 } | 285 } |
| 286 | 286 |
| 287 if (!disk_cache_) | 287 if (!disk_cache_) |
| 288 return net::ERR_FAILED; | 288 return net::ERR_FAILED; |
| 289 | 289 |
| 290 return ActiveCall::OpenEntry( | 290 return ActiveCall::OpenEntry( |
| 291 weak_factory_.GetWeakPtr(), key, entry, callback); | 291 weak_factory_.GetWeakPtr(), key, entry, callback); |
| 292 } | 292 } |
| 293 | 293 |
| 294 int AppCacheDiskCache::DoomEntry(int64 key, | 294 int AppCacheDiskCache::DoomEntry(int64 key, |
| 295 const net::CompletionCallback& callback) { | 295 const net::CompletionCallback& callback) { |
| 296 DCHECK(!callback.is_null()); | 296 DCHECK(!callback.is_null()); |
| 297 if (is_disabled_) | 297 if (is_disabled_) |
| 298 return net::ERR_ABORTED; | 298 return net::ERR_ABORTED; |
| 299 | 299 |
| 300 if (is_initializing()) { | 300 if (is_initializing_or_waiting_to_initialize()) { |
| 301 pending_calls_.push_back(PendingCall(DOOM, key, NULL, callback)); | 301 pending_calls_.push_back(PendingCall(DOOM, key, NULL, callback)); |
| 302 return net::ERR_IO_PENDING; | 302 return net::ERR_IO_PENDING; |
| 303 } | 303 } |
| 304 | 304 |
| 305 if (!disk_cache_) | 305 if (!disk_cache_) |
| 306 return net::ERR_FAILED; | 306 return net::ERR_FAILED; |
| 307 | 307 |
| 308 return ActiveCall::DoomEntry(weak_factory_.GetWeakPtr(), key, callback); | 308 return ActiveCall::DoomEntry(weak_factory_.GetWeakPtr(), key, callback); |
| 309 } | 309 } |
| 310 | 310 |
| 311 AppCacheDiskCache::AppCacheDiskCache(bool use_simple_cache) | 311 AppCacheDiskCache::AppCacheDiskCache(bool use_simple_cache) |
| 312 : use_simple_cache_(use_simple_cache), | 312 : use_simple_cache_(use_simple_cache), |
| 313 is_disabled_(false), | 313 is_disabled_(false), |
| 314 is_waiting_to_initialize_(false), |
| 314 weak_factory_(this) { | 315 weak_factory_(this) { |
| 315 } | 316 } |
| 316 | 317 |
| 317 AppCacheDiskCache::PendingCall::PendingCall() | 318 AppCacheDiskCache::PendingCall::PendingCall() |
| 318 : call_type(CREATE), | 319 : call_type(CREATE), |
| 319 key(0), | 320 key(0), |
| 320 entry(NULL) { | 321 entry(NULL) { |
| 321 } | 322 } |
| 322 | 323 |
| 323 AppCacheDiskCache::PendingCall::PendingCall(PendingCallType call_type, | 324 AppCacheDiskCache::PendingCall::PendingCall(PendingCallType call_type, |
| 324 int64 key, | 325 int64 key, |
| 325 Entry** entry, | 326 Entry** entry, |
| 326 const net::CompletionCallback& callback) | 327 const net::CompletionCallback& callback) |
| 327 : call_type(call_type), | 328 : call_type(call_type), |
| 328 key(key), | 329 key(key), |
| 329 entry(entry), | 330 entry(entry), |
| 330 callback(callback) { | 331 callback(callback) { |
| 331 } | 332 } |
| 332 | 333 |
| 333 AppCacheDiskCache::PendingCall::~PendingCall() {} | 334 AppCacheDiskCache::PendingCall::~PendingCall() {} |
| 334 | 335 |
| 335 int AppCacheDiskCache::Init( | 336 int AppCacheDiskCache::Init( |
| 336 net::CacheType cache_type, | 337 net::CacheType cache_type, |
| 337 const base::FilePath& cache_directory, | 338 const base::FilePath& cache_directory, |
| 338 int cache_size, | 339 int cache_size, |
| 339 bool force, | 340 bool force, |
| 340 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, | 341 const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread, |
| 341 const net::CompletionCallback& callback) { | 342 const net::CompletionCallback& callback) { |
| 342 DCHECK(!is_initializing() && !disk_cache_.get()); | 343 DCHECK(!is_initializing_or_waiting_to_initialize() && !disk_cache_.get()); |
| 343 is_disabled_ = false; | 344 is_disabled_ = false; |
| 344 create_backend_callback_ = new CreateBackendCallbackShim(this); | 345 create_backend_callback_ = new CreateBackendCallbackShim(this); |
| 345 | 346 |
| 346 int rv = disk_cache::CreateCacheBackend( | 347 int rv = disk_cache::CreateCacheBackend( |
| 347 cache_type, | 348 cache_type, |
| 348 use_simple_cache_ ? net::CACHE_BACKEND_SIMPLE | 349 use_simple_cache_ ? net::CACHE_BACKEND_SIMPLE |
| 349 : net::CACHE_BACKEND_DEFAULT, | 350 : net::CACHE_BACKEND_DEFAULT, |
| 350 cache_directory, | 351 cache_directory, |
| 351 cache_size, | 352 cache_size, |
| 352 force, | 353 force, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 NOTREACHED(); | 393 NOTREACHED(); |
| 393 break; | 394 break; |
| 394 } | 395 } |
| 395 if (rv != net::ERR_IO_PENDING) | 396 if (rv != net::ERR_IO_PENDING) |
| 396 iter->callback.Run(rv); | 397 iter->callback.Run(rv); |
| 397 } | 398 } |
| 398 pending_calls_.clear(); | 399 pending_calls_.clear(); |
| 399 } | 400 } |
| 400 | 401 |
| 401 } // namespace content | 402 } // namespace content |
| OLD | NEW |