| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/appcache/appcache_disk_cache.h" | 5 #include "webkit/appcache/appcache_disk_cache.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 | 11 |
| 12 namespace appcache { | 12 namespace appcache { |
| 13 | 13 |
| 14 AppCacheDiskCache::AppCacheDiskCache() | 14 AppCacheDiskCache::AppCacheDiskCache() |
| 15 : is_disabled_(false), init_callback_(NULL) { | 15 : is_disabled_(false), init_callback_(NULL) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 AppCacheDiskCache::~AppCacheDiskCache() { | 18 AppCacheDiskCache::~AppCacheDiskCache() { |
| 19 if (create_backend_callback_) { | 19 if (create_backend_callback_) { |
| 20 create_backend_callback_->Cancel(); | 20 create_backend_callback_->Cancel(); |
| 21 create_backend_callback_.release(); | 21 create_backend_callback_.release(); |
| 22 OnCreateBackendComplete(net::ERR_ABORTED); | 22 OnCreateBackendComplete(net::ERR_ABORTED); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 int AppCacheDiskCache::InitWithDiskBackend( | 26 int AppCacheDiskCache::InitWithDiskBackend( |
| 27 const FilePath& disk_cache_directory, int disk_cache_size, bool force, | 27 const FilePath& disk_cache_directory, int disk_cache_size, bool force, |
| 28 net::CompletionCallback* callback) { | 28 base::MessageLoopProxy* cache_thread, net::CompletionCallback* callback) { |
| 29 return Init(net::APP_CACHE, disk_cache_directory, | 29 return Init(net::APP_CACHE, disk_cache_directory, |
| 30 disk_cache_size, force, callback); | 30 disk_cache_size, force, cache_thread, callback); |
| 31 } | 31 } |
| 32 | 32 |
| 33 int AppCacheDiskCache::InitWithMemBackend( | 33 int AppCacheDiskCache::InitWithMemBackend( |
| 34 int mem_cache_size, net::CompletionCallback* callback) { | 34 int mem_cache_size, net::CompletionCallback* callback) { |
| 35 return Init(net::MEMORY_CACHE, FilePath(), mem_cache_size, false, callback); | 35 return Init(net::MEMORY_CACHE, FilePath(), mem_cache_size, false, NULL, |
| 36 callback); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void AppCacheDiskCache::Disable() { | 39 void AppCacheDiskCache::Disable() { |
| 39 if (is_disabled_) | 40 if (is_disabled_) |
| 40 return; | 41 return; |
| 41 | 42 |
| 42 is_disabled_ = true; | 43 is_disabled_ = true; |
| 43 | 44 |
| 44 if (create_backend_callback_) { | 45 if (create_backend_callback_) { |
| 45 create_backend_callback_->Cancel(); | 46 create_backend_callback_->Cancel(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 93 |
| 93 if (!disk_cache_.get()) | 94 if (!disk_cache_.get()) |
| 94 return net::ERR_FAILED; | 95 return net::ERR_FAILED; |
| 95 | 96 |
| 96 return disk_cache_->DoomEntry(Int64ToString(key), callback); | 97 return disk_cache_->DoomEntry(Int64ToString(key), callback); |
| 97 } | 98 } |
| 98 | 99 |
| 99 int AppCacheDiskCache::Init(net::CacheType cache_type, | 100 int AppCacheDiskCache::Init(net::CacheType cache_type, |
| 100 const FilePath& cache_directory, | 101 const FilePath& cache_directory, |
| 101 int cache_size, bool force, | 102 int cache_size, bool force, |
| 103 base::MessageLoopProxy* cache_thread, |
| 102 net::CompletionCallback* callback) { | 104 net::CompletionCallback* callback) { |
| 103 DCHECK(!is_initializing() && !disk_cache_.get()); | 105 DCHECK(!is_initializing() && !disk_cache_.get()); |
| 104 is_disabled_ = false; | 106 is_disabled_ = false; |
| 105 create_backend_callback_ = new CreateBackendCallback( | 107 create_backend_callback_ = new CreateBackendCallback( |
| 106 this, &AppCacheDiskCache::OnCreateBackendComplete); | 108 this, &AppCacheDiskCache::OnCreateBackendComplete); |
| 107 | 109 |
| 108 // TODO(michaeln): Pass a valid cache_thread here. | |
| 109 int rv = disk_cache::CreateCacheBackend( | 110 int rv = disk_cache::CreateCacheBackend( |
| 110 cache_type, cache_directory, cache_size, force, NULL, | 111 cache_type, cache_directory, cache_size, force, cache_thread, |
| 111 &(create_backend_callback_->backend_ptr_), create_backend_callback_); | 112 &(create_backend_callback_->backend_ptr_), create_backend_callback_); |
| 112 if (rv == net::ERR_IO_PENDING) | 113 if (rv == net::ERR_IO_PENDING) |
| 113 init_callback_ = callback; | 114 init_callback_ = callback; |
| 114 else | 115 else |
| 115 OnCreateBackendComplete(rv); | 116 OnCreateBackendComplete(rv); |
| 116 return rv; | 117 return rv; |
| 117 } | 118 } |
| 118 | 119 |
| 119 void AppCacheDiskCache::OnCreateBackendComplete(int rv) { | 120 void AppCacheDiskCache::OnCreateBackendComplete(int rv) { |
| 120 if (rv == net::OK) { | 121 if (rv == net::OK) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 148 break; | 149 break; |
| 149 } | 150 } |
| 150 if (rv != net::ERR_IO_PENDING) | 151 if (rv != net::ERR_IO_PENDING) |
| 151 iter->callback->Run(rv); | 152 iter->callback->Run(rv); |
| 152 } | 153 } |
| 153 pending_calls_.clear(); | 154 pending_calls_.clear(); |
| 154 } | 155 } |
| 155 | 156 |
| 156 } // namespace appcache | 157 } // namespace appcache |
| 157 | 158 |
| OLD | NEW |