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

Side by Side Diff: webkit/appcache/appcache_storage_impl.cc

Issue 2249005: AppCache: Use a dedicated thread for the disk cache. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Bound to IO thread Created 10 years, 6 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 | Annotate | Revision Log
OLDNEW
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_storage_impl.h" 5 #include "webkit/appcache/appcache_storage_impl.h"
6 6
7 #include "app/sql/connection.h" 7 #include "app/sql/connection.h"
8 #include "app/sql/transaction.h" 8 #include "app/sql/transaction.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 STLDeleteElements(&pending_simple_tasks_); 837 STLDeleteElements(&pending_simple_tasks_);
838 838
839 std::for_each(scheduled_database_tasks_.begin(), 839 std::for_each(scheduled_database_tasks_.begin(),
840 scheduled_database_tasks_.end(), 840 scheduled_database_tasks_.end(),
841 std::mem_fun(&DatabaseTask::CancelCompletion)); 841 std::mem_fun(&DatabaseTask::CancelCompletion));
842 842
843 if (database_) 843 if (database_)
844 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_); 844 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_);
845 } 845 }
846 846
847 void AppCacheStorageImpl::Initialize(const FilePath& cache_directory) { 847 void AppCacheStorageImpl::Initialize(const FilePath& cache_directory,
848 base::MessageLoopProxy* cache_thread) {
848 cache_directory_ = cache_directory; 849 cache_directory_ = cache_directory;
850 cache_thread_ = cache_thread;
849 is_incognito_ = cache_directory_.empty(); 851 is_incognito_ = cache_directory_.empty();
850 852
851 FilePath db_file_path; 853 FilePath db_file_path;
852 if (!is_incognito_) 854 if (!is_incognito_)
853 db_file_path = cache_directory_.Append(kAppCacheDatabaseName); 855 db_file_path = cache_directory_.Append(kAppCacheDatabaseName);
854 database_ = new AppCacheDatabase(db_file_path); 856 database_ = new AppCacheDatabase(db_file_path);
855 857
856 scoped_refptr<InitTask> task = new InitTask(this); 858 scoped_refptr<InitTask> task = new InitTask(this);
857 task->Schedule(); 859 task->Schedule();
858 } 860 }
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 1268
1267 if (!disk_cache_.get()) { 1269 if (!disk_cache_.get()) {
1268 int rv = net::OK; 1270 int rv = net::OK;
1269 disk_cache_.reset(new AppCacheDiskCache); 1271 disk_cache_.reset(new AppCacheDiskCache);
1270 if (is_incognito_) { 1272 if (is_incognito_) {
1271 rv = disk_cache_->InitWithMemBackend( 1273 rv = disk_cache_->InitWithMemBackend(
1272 kMaxMemDiskCacheSize, &init_callback_); 1274 kMaxMemDiskCacheSize, &init_callback_);
1273 } else { 1275 } else {
1274 rv = disk_cache_->InitWithDiskBackend( 1276 rv = disk_cache_->InitWithDiskBackend(
1275 cache_directory_.Append(kDiskCacheDirectoryName), 1277 cache_directory_.Append(kDiskCacheDirectoryName),
1276 kMaxDiskCacheSize, false, &init_callback_); 1278 kMaxDiskCacheSize, false, cache_thread_, &init_callback_);
1277 } 1279 }
1278 1280
1281 // We should not keep this reference around.
1282 cache_thread_ = NULL;
1283
1279 if (rv != net::ERR_IO_PENDING) 1284 if (rv != net::ERR_IO_PENDING)
1280 OnDiskCacheInitialized(rv); 1285 OnDiskCacheInitialized(rv);
1281 } 1286 }
1282 return disk_cache_.get(); 1287 return disk_cache_.get();
1283 } 1288 }
1284 1289
1285 void AppCacheStorageImpl::OnDiskCacheInitialized(int rv) { 1290 void AppCacheStorageImpl::OnDiskCacheInitialized(int rv) {
1286 if (rv != net::OK) { 1291 if (rv != net::OK) {
1287 LOG(ERROR) << "Failed to open the appcache diskcache."; 1292 LOG(ERROR) << "Failed to open the appcache diskcache.";
1288 AppCacheHistograms::CountInitResult(AppCacheHistograms::DISK_CACHE_ERROR); 1293 AppCacheHistograms::CountInitResult(AppCacheHistograms::DISK_CACHE_ERROR);
1289 1294
1290 // We're unable to open the disk cache, this is a fatal error that we can't 1295 // We're unable to open the disk cache, this is a fatal error that we can't
1291 // really recover from. We handle it by disabling the appcache for this 1296 // really recover from. We handle it by disabling the appcache for this
1292 // browser session and deleting the directory on disk. The next browser 1297 // browser session and deleting the directory on disk. The next browser
1293 // session should start with a clean slate. 1298 // session should start with a clean slate.
1294 Disable(); 1299 Disable();
1295 if (!is_incognito_) { 1300 if (!is_incognito_) {
1296 LOG(INFO) << "Deleting existing appcache data and starting over."; 1301 LOG(INFO) << "Deleting existing appcache data and starting over.";
1297 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, 1302 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE,
1298 NewRunnableFunction(DeleteDirectory, cache_directory_)); 1303 NewRunnableFunction(DeleteDirectory, cache_directory_));
1299 } 1304 }
1300 } 1305 }
1301 } 1306 }
1302 1307
1303 } // namespace appcache 1308 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_storage_impl.h ('k') | webkit/appcache/appcache_storage_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698