| 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_storage_impl.h" | 5 #include "content/browser/appcache/appcache_storage_impl.h" | 
| 6 | 6 | 
| 7 #include <stddef.h> | 7 #include <stddef.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 #include <functional> | 10 #include <functional> | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 37 #include "storage/browser/quota/quota_client.h" | 37 #include "storage/browser/quota/quota_client.h" | 
| 38 #include "storage/browser/quota/quota_manager.h" | 38 #include "storage/browser/quota/quota_manager.h" | 
| 39 #include "storage/browser/quota/quota_manager_proxy.h" | 39 #include "storage/browser/quota/quota_manager_proxy.h" | 
| 40 #include "storage/browser/quota/special_storage_policy.h" | 40 #include "storage/browser/quota/special_storage_policy.h" | 
| 41 | 41 | 
| 42 namespace content { | 42 namespace content { | 
| 43 | 43 | 
| 44 // Hard coded default when not using quota management. | 44 // Hard coded default when not using quota management. | 
| 45 static const int kDefaultQuota = 5 * 1024 * 1024; | 45 static const int kDefaultQuota = 5 * 1024 * 1024; | 
| 46 | 46 | 
| 47 static const int kMaxDiskCacheSize = 250 * 1024 * 1024; | 47 static const int kAppCacheMaxDiskCacheSize = 250 * 1024 * 1024; | 
| 48 static const int kMaxMemDiskCacheSize = 10 * 1024 * 1024; | 48 static const int kAppCacheMaxMemDiskCacheSize = 10 * 1024 * 1024; | 
| 49 static const base::FilePath::CharType kDiskCacheDirectoryName[] = | 49 static const base::FilePath::CharType kDiskCacheDirectoryName[] = | 
| 50     FILE_PATH_LITERAL("Cache"); | 50     FILE_PATH_LITERAL("Cache"); | 
| 51 | 51 | 
| 52 namespace { | 52 namespace { | 
| 53 | 53 | 
| 54 // Helpers for clearing data from the AppCacheDatabase. | 54 // Helpers for clearing data from the AppCacheDatabase. | 
| 55 bool DeleteGroupAndRelatedRecords( | 55 bool DeleteGroupAndRelatedRecords( | 
| 56     AppCacheDatabase* database, | 56     AppCacheDatabase* database, | 
| 57     int64_t group_id, | 57     int64_t group_id, | 
| 58     std::vector<int64_t>* deletable_response_ids) { | 58     std::vector<int64_t>* deletable_response_ids) { | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 70         database->InsertDeletableResponseIds(*deletable_response_ids); | 70         database->InsertDeletableResponseIds(*deletable_response_ids); | 
| 71   } else { | 71   } else { | 
| 72     NOTREACHED() << "A existing group without a cache is unexpected"; | 72     NOTREACHED() << "A existing group without a cache is unexpected"; | 
| 73     success = database->DeleteGroup(group_id); | 73     success = database->DeleteGroup(group_id); | 
| 74   } | 74   } | 
| 75   return success; | 75   return success; | 
| 76 } | 76 } | 
| 77 | 77 | 
| 78 // Destroys |database|. If there is appcache data to be deleted | 78 // Destroys |database|. If there is appcache data to be deleted | 
| 79 // (|force_keep_session_state| is false), deletes session-only appcache data. | 79 // (|force_keep_session_state| is false), deletes session-only appcache data. | 
| 80 void ClearSessionOnlyOrigins( | 80 void AppCacheClearSessionOnlyOrigins( | 
| 81     AppCacheDatabase* database, | 81     AppCacheDatabase* database, | 
| 82     scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy, | 82     scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy, | 
| 83     bool force_keep_session_state) { | 83     bool force_keep_session_state) { | 
| 84   std::unique_ptr<AppCacheDatabase> database_to_delete(database); | 84   std::unique_ptr<AppCacheDatabase> database_to_delete(database); | 
| 85 | 85 | 
| 86   // If saving session state, only delete the database. | 86   // If saving session state, only delete the database. | 
| 87   if (force_keep_session_state) | 87   if (force_keep_session_state) | 
| 88     return; | 88     return; | 
| 89 | 89 | 
| 90   bool has_session_only_appcaches = | 90   bool has_session_only_appcaches = | 
| (...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1401 | 1401 | 
| 1402 AppCacheStorageImpl::~AppCacheStorageImpl() { | 1402 AppCacheStorageImpl::~AppCacheStorageImpl() { | 
| 1403   for (auto* task : pending_quota_queries_) | 1403   for (auto* task : pending_quota_queries_) | 
| 1404     task->CancelCompletion(); | 1404     task->CancelCompletion(); | 
| 1405   for (auto* task : scheduled_database_tasks_) | 1405   for (auto* task : scheduled_database_tasks_) | 
| 1406     task->CancelCompletion(); | 1406     task->CancelCompletion(); | 
| 1407 | 1407 | 
| 1408   if (database_ && | 1408   if (database_ && | 
| 1409       !db_task_runner_->PostTask( | 1409       !db_task_runner_->PostTask( | 
| 1410           FROM_HERE, | 1410           FROM_HERE, | 
| 1411           base::BindOnce(&ClearSessionOnlyOrigins, database_, | 1411           base::BindOnce(&AppCacheClearSessionOnlyOrigins, database_, | 
| 1412                          make_scoped_refptr(service_->special_storage_policy()), | 1412                          make_scoped_refptr(service_->special_storage_policy()), | 
| 1413                          service()->force_keep_session_state()))) { | 1413                          service()->force_keep_session_state()))) { | 
| 1414     delete database_; | 1414     delete database_; | 
| 1415   } | 1415   } | 
| 1416   database_ = NULL;  // So no further database tasks can be scheduled. | 1416   database_ = NULL;  // So no further database tasks can be scheduled. | 
| 1417 } | 1417 } | 
| 1418 | 1418 | 
| 1419 void AppCacheStorageImpl::Initialize( | 1419 void AppCacheStorageImpl::Initialize( | 
| 1420     const base::FilePath& cache_directory, | 1420     const base::FilePath& cache_directory, | 
| 1421     const scoped_refptr<base::SequencedTaskRunner>& db_task_runner) { | 1421     const scoped_refptr<base::SequencedTaskRunner>& db_task_runner) { | 
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1881 | 1881 | 
| 1882 AppCacheDiskCache* AppCacheStorageImpl::disk_cache() { | 1882 AppCacheDiskCache* AppCacheStorageImpl::disk_cache() { | 
| 1883   DCHECK(IsInitTaskComplete()); | 1883   DCHECK(IsInitTaskComplete()); | 
| 1884   DCHECK(!is_disabled_); | 1884   DCHECK(!is_disabled_); | 
| 1885 | 1885 | 
| 1886   if (!disk_cache_) { | 1886   if (!disk_cache_) { | 
| 1887     int rv = net::OK; | 1887     int rv = net::OK; | 
| 1888     disk_cache_.reset(new AppCacheDiskCache); | 1888     disk_cache_.reset(new AppCacheDiskCache); | 
| 1889     if (is_incognito_) { | 1889     if (is_incognito_) { | 
| 1890       rv = disk_cache_->InitWithMemBackend( | 1890       rv = disk_cache_->InitWithMemBackend( | 
| 1891           kMaxMemDiskCacheSize, | 1891           kAppCacheMaxMemDiskCacheSize, | 
| 1892           base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized, | 1892           base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized, | 
| 1893                      base::Unretained(this))); | 1893                      base::Unretained(this))); | 
| 1894     } else { | 1894     } else { | 
| 1895       expecting_cleanup_complete_on_disable_ = true; | 1895       expecting_cleanup_complete_on_disable_ = true; | 
| 1896       rv = disk_cache_->InitWithDiskBackend( | 1896       rv = disk_cache_->InitWithDiskBackend( | 
| 1897           cache_directory_.Append(kDiskCacheDirectoryName), kMaxDiskCacheSize, | 1897           cache_directory_.Append(kDiskCacheDirectoryName), | 
|  | 1898           kAppCacheMaxDiskCacheSize, | 
| 1898           false, | 1899           false, | 
| 1899           base::BindOnce(&AppCacheStorageImpl::OnDiskCacheCleanupComplete, | 1900           base::BindOnce(&AppCacheStorageImpl::OnDiskCacheCleanupComplete, | 
| 1900                          weak_factory_.GetWeakPtr()), | 1901                          weak_factory_.GetWeakPtr()), | 
| 1901           base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized, | 1902           base::Bind(&AppCacheStorageImpl::OnDiskCacheInitialized, | 
| 1902                      base::Unretained(this))); | 1903                      base::Unretained(this))); | 
| 1903     } | 1904     } | 
| 1904 | 1905 | 
| 1905     if (rv != net::ERR_IO_PENDING) | 1906     if (rv != net::ERR_IO_PENDING) | 
| 1906       OnDiskCacheInitialized(rv); | 1907       OnDiskCacheInitialized(rv); | 
| 1907   } | 1908   } | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1970 | 1971 | 
| 1971 void AppCacheStorageImpl::OnLazyCommitTimer() { | 1972 void AppCacheStorageImpl::OnLazyCommitTimer() { | 
| 1972   lazy_commit_timer_.Stop(); | 1973   lazy_commit_timer_.Stop(); | 
| 1973   if (is_disabled()) | 1974   if (is_disabled()) | 
| 1974     return; | 1975     return; | 
| 1975   scoped_refptr<DatabaseTask> task(new CommitLastAccessTimesTask(this)); | 1976   scoped_refptr<DatabaseTask> task(new CommitLastAccessTimesTask(this)); | 
| 1976   task->Schedule(); | 1977   task->Schedule(); | 
| 1977 } | 1978 } | 
| 1978 | 1979 | 
| 1979 }  // namespace content | 1980 }  // namespace content | 
| OLD | NEW | 
|---|