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. | |
michaeln
2011/08/29 17:43:15
This doc comment is pretty clear, consider removin
marja
2011/08/30 09:45:09
Done.
| |
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 // Schedule the deletion of database, no matter how we return from this | |
78 // function. | |
79 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database); | |
michaeln
2011/08/29 17:43:15
Please use a local scoped_ptr<> here since it's li
marja
2011/08/30 09:45:09
Done.
| |
80 | |
74 std::set<GURL> origins; | 81 std::set<GURL> origins; |
75 database->FindOriginsWithGroups(&origins); | 82 database->FindOriginsWithGroups(&origins); |
76 if (origins.empty()) | 83 if (origins.empty()) |
77 return; // nothing to delete | 84 return; // nothing to delete |
78 | 85 |
79 sql::Connection* connection = database->db_connection(); | 86 sql::Connection* connection = database->db_connection(); |
80 if (!connection) { | 87 if (!connection) { |
81 NOTREACHED() << "Missing database connection."; | 88 NOTREACHED() << "Missing database connection."; |
82 return; | 89 return; |
83 } | 90 } |
84 | 91 |
92 // We're deleting only session-only data, and there is no policy. Delete | |
93 // nothing. | |
94 if (!clear_all_appcaches && !special_storage_policy) | |
michaeln
2011/08/29 17:43:15
Looks like this could be moved up above the databa
marja
2011/08/30 09:45:09
Done.
| |
95 return; | |
96 | |
85 std::set<GURL>::const_iterator origin; | 97 std::set<GURL>::const_iterator origin; |
86 for (origin = origins.begin(); origin != origins.end(); ++origin) { | 98 for (origin = origins.begin(); origin != origins.end(); ++origin) { |
99 // We're deleting session-only origins, and this origin is not a | |
100 // session-only origin. | |
101 if (!clear_all_appcaches && | |
102 !special_storage_policy->IsStorageSessionOnly(*origin)) | |
103 continue; | |
87 if (special_storage_policy && | 104 if (special_storage_policy && |
88 special_storage_policy->IsStorageProtected(*origin)) | 105 special_storage_policy->IsStorageProtected(*origin)) |
89 continue; | 106 continue; |
90 | 107 |
91 std::vector<AppCacheDatabase::GroupRecord> groups; | 108 std::vector<AppCacheDatabase::GroupRecord> groups; |
92 database->FindGroupsForOrigin(*origin, &groups); | 109 database->FindGroupsForOrigin(*origin, &groups); |
93 std::vector<AppCacheDatabase::GroupRecord>::const_iterator group; | 110 std::vector<AppCacheDatabase::GroupRecord>::const_iterator group; |
94 for (group = groups.begin(); group != groups.end(); ++group) { | 111 for (group = groups.begin(); group != groups.end(); ++group) { |
95 sql::Transaction transaction(connection); | 112 sql::Transaction transaction(connection); |
96 if (!transaction.Begin()) { | 113 if (!transaction.Begin()) { |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1141 STLDeleteElements(&pending_simple_tasks_); | 1158 STLDeleteElements(&pending_simple_tasks_); |
1142 | 1159 |
1143 std::for_each(pending_quota_queries_.begin(), | 1160 std::for_each(pending_quota_queries_.begin(), |
1144 pending_quota_queries_.end(), | 1161 pending_quota_queries_.end(), |
1145 std::mem_fun(&DatabaseTask::CancelCompletion)); | 1162 std::mem_fun(&DatabaseTask::CancelCompletion)); |
1146 std::for_each(scheduled_database_tasks_.begin(), | 1163 std::for_each(scheduled_database_tasks_.begin(), |
1147 scheduled_database_tasks_.end(), | 1164 scheduled_database_tasks_.end(), |
1148 std::mem_fun(&DatabaseTask::CancelCompletion)); | 1165 std::mem_fun(&DatabaseTask::CancelCompletion)); |
1149 | 1166 |
1150 if (database_) { | 1167 if (database_) { |
1151 if (service()->clear_local_state_on_exit()) { | 1168 AppCacheThread::PostTask( |
1152 AppCacheThread::PostTask( | 1169 AppCacheThread::db(), |
1153 AppCacheThread::db(), | 1170 FROM_HERE, |
1154 FROM_HERE, | 1171 NewRunnableFunction( |
1155 NewRunnableFunction( | 1172 CleanUpOnDatabaseThread, |
1156 ClearOnExit, | 1173 database_, |
1157 database_, | 1174 make_scoped_refptr(service_->special_storage_policy()), |
1158 make_scoped_refptr(service_->special_storage_policy()))); | 1175 service()->clear_local_state_on_exit())); |
1159 } | |
1160 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_); | |
1161 } | 1176 } |
1162 } | 1177 } |
1163 | 1178 |
1164 void AppCacheStorageImpl::Initialize(const FilePath& cache_directory, | 1179 void AppCacheStorageImpl::Initialize(const FilePath& cache_directory, |
1165 base::MessageLoopProxy* cache_thread) { | 1180 base::MessageLoopProxy* cache_thread) { |
1166 cache_directory_ = cache_directory; | 1181 cache_directory_ = cache_directory; |
1167 cache_thread_ = cache_thread; | 1182 cache_thread_ = cache_thread; |
1168 is_incognito_ = cache_directory_.empty(); | 1183 is_incognito_ = cache_directory_.empty(); |
1169 | 1184 |
1170 FilePath db_file_path; | 1185 FilePath db_file_path; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1640 Disable(); | 1655 Disable(); |
1641 if (!is_incognito_) { | 1656 if (!is_incognito_) { |
1642 VLOG(1) << "Deleting existing appcache data and starting over."; | 1657 VLOG(1) << "Deleting existing appcache data and starting over."; |
1643 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, | 1658 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, |
1644 NewRunnableFunction(DeleteDirectory, cache_directory_)); | 1659 NewRunnableFunction(DeleteDirectory, cache_directory_)); |
1645 } | 1660 } |
1646 } | 1661 } |
1647 } | 1662 } |
1648 | 1663 |
1649 } // namespace appcache | 1664 } // namespace appcache |
OLD | NEW |