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

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

Issue 7210006: AppCaches which belong to hosted apps are not protected from deletion (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Minor. Created 9 years, 5 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) 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 "app/sql/connection.h" 9 #include "app/sql/connection.h"
10 #include "app/sql/transaction.h" 10 #include "app/sql/transaction.h"
(...skipping 11 matching lines...) Expand all
22 #include "webkit/appcache/appcache_histograms.h" 22 #include "webkit/appcache/appcache_histograms.h"
23 #include "webkit/appcache/appcache_policy.h" 23 #include "webkit/appcache/appcache_policy.h"
24 #include "webkit/appcache/appcache_quota_client.h" 24 #include "webkit/appcache/appcache_quota_client.h"
25 #include "webkit/appcache/appcache_response.h" 25 #include "webkit/appcache/appcache_response.h"
26 #include "webkit/appcache/appcache_service.h" 26 #include "webkit/appcache/appcache_service.h"
27 #include "webkit/appcache/appcache_thread.h" 27 #include "webkit/appcache/appcache_thread.h"
28 #include "webkit/quota/quota_client.h" 28 #include "webkit/quota/quota_client.h"
29 #include "webkit/quota/quota_manager.h" 29 #include "webkit/quota/quota_manager.h"
30 #include "webkit/quota/special_storage_policy.h" 30 #include "webkit/quota/special_storage_policy.h"
31 31
32 namespace { 32 namespace {
michaeln 2011/07/14 22:53:16 If this anon namespace is moved down a couple of l
marja(google) 2011/07/15 11:03:42 Done.
33 // Helper with no return value for use with NewRunnableFunction. 33 // Helper with no return value for use with NewRunnableFunction.
34 void DeleteDirectory(const FilePath& path) { 34 void DeleteDirectory(const FilePath& path) {
35 file_util::Delete(path, true); 35 file_util::Delete(path, true);
36 } 36 }
37
38 void ClearOnExit(
39 appcache::AppCacheDatabase* database,
40 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) {
41 LOG(WARNING) << "ClearOnExit";
42 std::set<GURL> origins;
43 database->FindOriginsWithGroups(&origins);
44 if (origins.empty())
45 return; // nothing to delete
46
47 sql::Connection* connection = database->db_connection();
48 if (!connection) {
49 NOTREACHED() << "Missing database connection.";
50 return;
51 }
52
53 std::set<GURL>::const_iterator origin;
54 for (origin = origins.begin(); origin != origins.end(); ++origin) {
55 if (special_storage_policy &&
56 special_storage_policy->IsStorageProtected(*origin))
57 continue;
58
59 std::vector<appcache::AppCacheDatabase::GroupRecord> groups;
60 database->FindGroupsForOrigin(*origin, &groups);
61 std::vector<appcache::AppCacheDatabase::GroupRecord>::const_iterator group;
62 for (group = groups.begin(); group != groups.end(); ++group) {
63 sql::Transaction transaction(connection);
64 if (!transaction.Begin()) {
65 NOTREACHED() << "Failed to start transaction";
66 return;
67 }
68
69 bool success = false;
70
71 // Logic lifted from MakeGroupObsoleteTask::Run, could be shared.
michaeln 2011/07/14 22:53:16 Can you take a stab at sharing this logic with Mak
marja(google) 2011/07/15 11:03:42 Done. Btw, how about AppCacheGroup::AddNewlyDelet
michaeln 2011/07/15 19:15:46 By the time our ClearOnExit function is run, there
72 appcache::AppCacheDatabase::CacheRecord cache_record;
73 if (database->FindCacheForGroup(group->group_id, &cache_record)) {
74 std::vector<int64> response_ids;
75 database->FindResponseIdsForCacheAsVector(cache_record.cache_id,
76 &response_ids);
77 success =
78 database->DeleteGroup(group->group_id) &&
79 database->DeleteCache(cache_record.cache_id) &&
80 database->DeleteEntriesForCache(cache_record.cache_id) &&
81 database->DeleteFallbackNameSpacesForCache(cache_record.cache_id) &&
82 database->DeleteOnlineWhiteListForCache(cache_record.cache_id) &&
83 database->InsertDeletableResponseIds(response_ids);
84 } else {
85 NOTREACHED() << "A existing group without a cache is unexpected";
86 success = database->DeleteGroup(group->group_id);
87 }
88
89 success = success && transaction.Commit();
90 DCHECK(success);
91 } // for each group
92 } // for each origin
37 } 93 }
38 94
95 } // namespace
96
39 namespace appcache { 97 namespace appcache {
40 98
41 // Hard coded default when not using quota management. 99 // Hard coded default when not using quota management.
42 static const int kDefaultQuota = 5 * 1024 * 1024; 100 static const int kDefaultQuota = 5 * 1024 * 1024;
43 101
44 static const int kMaxDiskCacheSize = 250 * 1024 * 1024; 102 static const int kMaxDiskCacheSize = 250 * 1024 * 1024;
45 static const int kMaxMemDiskCacheSize = 10 * 1024 * 1024; 103 static const int kMaxMemDiskCacheSize = 10 * 1024 * 1024;
46 static const FilePath::CharType kDiskCacheDirectoryName[] = 104 static const FilePath::CharType kDiskCacheDirectoryName[] =
47 FILE_PATH_LITERAL("Cache"); 105 FILE_PATH_LITERAL("Cache");
48 106
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 AppCacheStorageImpl::~AppCacheStorageImpl() { 1139 AppCacheStorageImpl::~AppCacheStorageImpl() {
1082 STLDeleteElements(&pending_simple_tasks_); 1140 STLDeleteElements(&pending_simple_tasks_);
1083 1141
1084 std::for_each(pending_quota_queries_.begin(), 1142 std::for_each(pending_quota_queries_.begin(),
1085 pending_quota_queries_.end(), 1143 pending_quota_queries_.end(),
1086 std::mem_fun(&DatabaseTask::CancelCompletion)); 1144 std::mem_fun(&DatabaseTask::CancelCompletion));
1087 std::for_each(scheduled_database_tasks_.begin(), 1145 std::for_each(scheduled_database_tasks_.begin(),
1088 scheduled_database_tasks_.end(), 1146 scheduled_database_tasks_.end(),
1089 std::mem_fun(&DatabaseTask::CancelCompletion)); 1147 std::mem_fun(&DatabaseTask::CancelCompletion));
1090 1148
1149 if (service()->clear_local_state_on_exit() && database_) {
michaeln 2011/07/14 22:53:16 nit: maybe test if (database_) once and { if (cl
marja(google) 2011/07/15 11:03:42 Done.
1150 AppCacheThread::PostTask(
1151 AppCacheThread::db(),
1152 FROM_HERE,
1153 NewRunnableFunction(
1154 ClearOnExit,
1155 database_,
1156 make_scoped_refptr(service_->special_storage_policy())));
1157
1158 }
1091 if (database_) 1159 if (database_)
1092 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_); 1160 AppCacheThread::DeleteSoon(AppCacheThread::db(), FROM_HERE, database_);
1093 } 1161 }
1094 1162
1095 void AppCacheStorageImpl::Initialize(const FilePath& cache_directory, 1163 void AppCacheStorageImpl::Initialize(const FilePath& cache_directory,
1096 base::MessageLoopProxy* cache_thread) { 1164 base::MessageLoopProxy* cache_thread) {
1097 cache_directory_ = cache_directory; 1165 cache_directory_ = cache_directory;
1098 cache_thread_ = cache_thread; 1166 cache_thread_ = cache_thread;
1099 is_incognito_ = cache_directory_.empty(); 1167 is_incognito_ = cache_directory_.empty();
1100 1168
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 Disable(); 1639 Disable();
1572 if (!is_incognito_) { 1640 if (!is_incognito_) {
1573 VLOG(1) << "Deleting existing appcache data and starting over."; 1641 VLOG(1) << "Deleting existing appcache data and starting over.";
1574 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE, 1642 AppCacheThread::PostTask(AppCacheThread::db(), FROM_HERE,
1575 NewRunnableFunction(DeleteDirectory, cache_directory_)); 1643 NewRunnableFunction(DeleteDirectory, cache_directory_));
1576 } 1644 }
1577 } 1645 }
1578 } 1646 }
1579 1647
1580 } // namespace appcache 1648 } // namespace appcache
OLDNEW
« webkit/appcache/appcache_storage.h ('K') | « webkit/appcache/appcache_storage_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698