OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 database->DeleteFallbackNameSpacesForCache(cache_record.cache_id) && | 61 database->DeleteFallbackNameSpacesForCache(cache_record.cache_id) && |
62 database->DeleteOnlineWhiteListForCache(cache_record.cache_id) && | 62 database->DeleteOnlineWhiteListForCache(cache_record.cache_id) && |
63 database->InsertDeletableResponseIds(*deletable_response_ids); | 63 database->InsertDeletableResponseIds(*deletable_response_ids); |
64 } else { | 64 } else { |
65 NOTREACHED() << "A existing group without a cache is unexpected"; | 65 NOTREACHED() << "A existing group without a cache is unexpected"; |
66 success = database->DeleteGroup(group_id); | 66 success = database->DeleteGroup(group_id); |
67 } | 67 } |
68 return success; | 68 return success; |
69 } | 69 } |
70 | 70 |
71 void ClearOnExit( | 71 // Deletes all appcache data (if clear_all_data is true), or session-only |
| 72 // appcache data. Also, schedules the database to be destroyed. |
| 73 void CleanUpOnDatabaseThread( |
72 AppCacheDatabase* database, | 74 AppCacheDatabase* database, |
73 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { | 75 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy, |
| 76 bool clear_all_appcaches) { |
| 77 scoped_ptr<AppCacheDatabase> database_to_delete(database); |
| 78 |
| 79 if (!clear_all_appcaches && !special_storage_policy) |
| 80 return; |
| 81 |
74 std::set<GURL> origins; | 82 std::set<GURL> origins; |
75 database->FindOriginsWithGroups(&origins); | 83 database->FindOriginsWithGroups(&origins); |
76 if (origins.empty()) | 84 if (origins.empty()) |
77 return; // nothing to delete | 85 return; // nothing to delete |
78 | 86 |
79 sql::Connection* connection = database->db_connection(); | 87 sql::Connection* connection = database->db_connection(); |
80 if (!connection) { | 88 if (!connection) { |
81 NOTREACHED() << "Missing database connection."; | 89 NOTREACHED() << "Missing database connection."; |
82 return; | 90 return; |
83 } | 91 } |
84 | 92 |
85 std::set<GURL>::const_iterator origin; | 93 std::set<GURL>::const_iterator origin; |
86 for (origin = origins.begin(); origin != origins.end(); ++origin) { | 94 for (origin = origins.begin(); origin != origins.end(); ++origin) { |
| 95 if (!clear_all_appcaches && |
| 96 !special_storage_policy->IsStorageSessionOnly(*origin)) |
| 97 continue; |
87 if (special_storage_policy && | 98 if (special_storage_policy && |
88 special_storage_policy->IsStorageProtected(*origin)) | 99 special_storage_policy->IsStorageProtected(*origin)) |
89 continue; | 100 continue; |
90 | 101 |
91 std::vector<AppCacheDatabase::GroupRecord> groups; | 102 std::vector<AppCacheDatabase::GroupRecord> groups; |
92 database->FindGroupsForOrigin(*origin, &groups); | 103 database->FindGroupsForOrigin(*origin, &groups); |
93 std::vector<AppCacheDatabase::GroupRecord>::const_iterator group; | 104 std::vector<AppCacheDatabase::GroupRecord>::const_iterator group; |
94 for (group = groups.begin(); group != groups.end(); ++group) { | 105 for (group = groups.begin(); group != groups.end(); ++group) { |
95 sql::Transaction transaction(connection); | 106 sql::Transaction transaction(connection); |
96 if (!transaction.Begin()) { | 107 if (!transaction.Begin()) { |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 STLDeleteElements(&pending_simple_tasks_); | 1152 STLDeleteElements(&pending_simple_tasks_); |
1142 | 1153 |
1143 std::for_each(pending_quota_queries_.begin(), | 1154 std::for_each(pending_quota_queries_.begin(), |
1144 pending_quota_queries_.end(), | 1155 pending_quota_queries_.end(), |
1145 std::mem_fun(&DatabaseTask::CancelCompletion)); | 1156 std::mem_fun(&DatabaseTask::CancelCompletion)); |
1146 std::for_each(scheduled_database_tasks_.begin(), | 1157 std::for_each(scheduled_database_tasks_.begin(), |
1147 scheduled_database_tasks_.end(), | 1158 scheduled_database_tasks_.end(), |
1148 std::mem_fun(&DatabaseTask::CancelCompletion)); | 1159 std::mem_fun(&DatabaseTask::CancelCompletion)); |
1149 | 1160 |
1150 if (database_) { | 1161 if (database_) { |
1151 if (service()->clear_local_state_on_exit()) { | 1162 AppCacheThread::PostTask( |
1152 AppCacheThread::PostTask( | 1163 AppCacheThread::db(), |
1153 AppCacheThread::db(), | 1164 FROM_HERE, |
1154 FROM_HERE, | 1165 NewRunnableFunction( |
1155 NewRunnableFunction( | 1166 CleanUpOnDatabaseThread, |
1156 ClearOnExit, | 1167 database_, |
1157 database_, | 1168 make_scoped_refptr(service_->special_storage_policy()), |
1158 make_scoped_refptr(service_->special_storage_policy()))); | 1169 service()->clear_local_state_on_exit())); |
1159 } | |
1160 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_); | |
1161 } | 1170 } |
1162 } | 1171 } |
1163 | 1172 |
1164 void AppCacheStorageImpl::Initialize(const FilePath& cache_directory, | 1173 void AppCacheStorageImpl::Initialize(const FilePath& cache_directory, |
1165 base::MessageLoopProxy* cache_thread) { | 1174 base::MessageLoopProxy* cache_thread) { |
1166 cache_directory_ = cache_directory; | 1175 cache_directory_ = cache_directory; |
1167 cache_thread_ = cache_thread; | 1176 cache_thread_ = cache_thread; |
1168 is_incognito_ = cache_directory_.empty(); | 1177 is_incognito_ = cache_directory_.empty(); |
1169 | 1178 |
1170 FilePath db_file_path; | 1179 FilePath db_file_path; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 Disable(); | 1649 Disable(); |
1641 if (!is_incognito_) { | 1650 if (!is_incognito_) { |
1642 VLOG(1) << "Deleting existing appcache data and starting over."; | 1651 VLOG(1) << "Deleting existing appcache data and starting over."; |
1643 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, | 1652 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, |
1644 NewRunnableFunction(DeleteDirectory, cache_directory_)); | 1653 NewRunnableFunction(DeleteDirectory, cache_directory_)); |
1645 } | 1654 } |
1646 } | 1655 } |
1647 } | 1656 } |
1648 | 1657 |
1649 } // namespace appcache | 1658 } // namespace appcache |
OLD | NEW |