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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database.cc

Issue 10806071: Delete stale chunks from safe-browsing downloads store. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/safe_browsing/safe_browsing_database.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 DCHECK_EQ(safe_browsing_util::GetListId(listname) % 2, 216 DCHECK_EQ(safe_browsing_util::GetListId(listname) % 2,
217 static_cast<int>(i % 2)); 217 static_cast<int>(i % 2));
218 DCHECK_NE(safe_browsing_util::GetListId(listname), 218 DCHECK_NE(safe_browsing_util::GetListId(listname),
219 safe_browsing_util::INVALID); 219 safe_browsing_util::INVALID);
220 lists->push_back(SBListChunkRanges(listname)); 220 lists->push_back(SBListChunkRanges(listname));
221 lists->back().adds.swap(adds[i]); 221 lists->back().adds.swap(adds[i]);
222 lists->back().subs.swap(subs[i]); 222 lists->back().subs.swap(subs[i]);
223 } 223 }
224 } 224 }
225 225
226 // Helper for deleting chunks left over from obsolete lists.
227 void DeleteChunksFromStore(SafeBrowsingStore* store, int listid){
228 std::vector<int> add_chunks;
229 size_t adds_deleted = 0;
230 store->GetAddChunks(&add_chunks);
231 for (std::vector<int>::const_iterator iter = add_chunks.begin();
232 iter != add_chunks.end(); ++iter) {
233 if (GetListIdBit(*iter) == GetListIdBit(listid)) {
234 adds_deleted++;
235 store->DeleteAddChunk(*iter);
236 }
237 }
238 if (adds_deleted > 0)
239 UMA_HISTOGRAM_COUNTS("SB2.DownloadBinhashAddsDeleted", adds_deleted);
240
241 std::vector<int> sub_chunks;
242 size_t subs_deleted = 0;
243 store->GetSubChunks(&sub_chunks);
244 for (std::vector<int>::const_iterator iter = sub_chunks.begin();
245 iter != sub_chunks.end(); ++iter) {
246 if (GetListIdBit(*iter) == GetListIdBit(listid)) {
247 subs_deleted++;
248 store->DeleteSubChunk(*iter);
249 }
250 }
251 if (subs_deleted > 0)
252 UMA_HISTOGRAM_COUNTS("SB2.DownloadBinhashSubsDeleted", subs_deleted);
253 }
254
226 // Order |SBAddFullHash| on the prefix part. |SBAddPrefixLess()| from 255 // Order |SBAddFullHash| on the prefix part. |SBAddPrefixLess()| from
227 // safe_browsing_store.h orders on both chunk-id and prefix. 256 // safe_browsing_store.h orders on both chunk-id and prefix.
228 bool SBAddFullHashPrefixLess(const SBAddFullHash& a, const SBAddFullHash& b) { 257 bool SBAddFullHashPrefixLess(const SBAddFullHash& a, const SBAddFullHash& b) {
229 return a.full_hash.prefix < b.full_hash.prefix; 258 return a.full_hash.prefix < b.full_hash.prefix;
230 } 259 }
231 260
232 // As compared to the bloom filter, PrefixSet should have these 261 // As compared to the bloom filter, PrefixSet should have these
233 // properties: 262 // properties:
234 // - Any bloom filter miss should be a prefix set miss. 263 // - Any bloom filter miss should be a prefix set miss.
235 // - Any prefix set hit should be a bloom filter hit. 264 // - Any prefix set hit should be a bloom filter hit.
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 HandleCorruptDatabase(); 1087 HandleCorruptDatabase();
1059 return false; 1088 return false;
1060 } 1089 }
1061 1090
1062 std::vector<std::string> browse_listnames; 1091 std::vector<std::string> browse_listnames;
1063 browse_listnames.push_back(safe_browsing_util::kMalwareList); 1092 browse_listnames.push_back(safe_browsing_util::kMalwareList);
1064 browse_listnames.push_back(safe_browsing_util::kPhishingList); 1093 browse_listnames.push_back(safe_browsing_util::kPhishingList);
1065 UpdateChunkRanges(browse_store_.get(), browse_listnames, lists); 1094 UpdateChunkRanges(browse_store_.get(), browse_listnames, lists);
1066 1095
1067 if (download_store_.get()) { 1096 if (download_store_.get()) {
1097 // This store used to contain kBinHashList in addition to
1098 // kBinUrlList. Strip the stale data before generating the chunk
1099 // ranges to request. UpdateChunkRanges() will traverse the chunk
1100 // list, so this is very cheap if there are no kBinHashList chunks.
1101 const int listid =
1102 safe_browsing_util::GetListId(safe_browsing_util::kBinHashList);
1103 DeleteChunksFromStore(download_store_.get(), listid);
mattm 2012/08/07 02:29:25 So, regarding the comments about this here: http:
Scott Hess - ex-Googler 2012/08/07 16:36:11 Per the comment below, DeleteChunksFromStore() jus
1104
1105 // The above marks the chunks for deletion, but they are not
1106 // actually deleted until the database is rewritten. The
1107 // following code removes the kBinHashList part of the request
1108 // before continuing so that UpdateChunkRanges() doesn't break.
1068 std::vector<std::string> download_listnames; 1109 std::vector<std::string> download_listnames;
1069 download_listnames.push_back(safe_browsing_util::kBinUrlList); 1110 download_listnames.push_back(safe_browsing_util::kBinUrlList);
1070 download_listnames.push_back(safe_browsing_util::kBinHashList); 1111 download_listnames.push_back(safe_browsing_util::kBinHashList);
1071 UpdateChunkRanges(download_store_.get(), download_listnames, lists); 1112 UpdateChunkRanges(download_store_.get(), download_listnames, lists);
1072 DCHECK_EQ(lists->back().name, 1113 DCHECK_EQ(lists->back().name,
1073 std::string(safe_browsing_util::kBinHashList)); 1114 std::string(safe_browsing_util::kBinHashList));
1074 // Remove kBinHashList entry so that we do not request updates for it from
1075 // the server. The existing data will still be retained by
1076 // SafeBrowsingStoreFile::DoUpdate.
1077 // TODO(mattm): write some code to remove the kBinHashList data from the
1078 // file?
1079 lists->pop_back(); 1115 lists->pop_back();
1116
1117 // TODO(shess): This problem could also be handled in
1118 // BeginUpdate() by detecting the chunks to delete and rewriting
1119 // the database before it's used. When I implemented that, it
1120 // felt brittle, it might be easier to just wait for some future
1121 // format change.
1080 } 1122 }
1081 1123
1082 if (csd_whitelist_store_.get()) { 1124 if (csd_whitelist_store_.get()) {
1083 std::vector<std::string> csd_whitelist_listnames; 1125 std::vector<std::string> csd_whitelist_listnames;
1084 csd_whitelist_listnames.push_back(safe_browsing_util::kCsdWhiteList); 1126 csd_whitelist_listnames.push_back(safe_browsing_util::kCsdWhiteList);
1085 UpdateChunkRanges(csd_whitelist_store_.get(), 1127 UpdateChunkRanges(csd_whitelist_store_.get(),
1086 csd_whitelist_listnames, lists); 1128 csd_whitelist_listnames, lists);
1087 } 1129 }
1088 1130
1089 if (download_whitelist_store_.get()) { 1131 if (download_whitelist_store_.get()) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), 1503 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(),
1462 kill_switch)) { 1504 kill_switch)) {
1463 // The kill switch is whitelisted hence we whitelist all URLs. 1505 // The kill switch is whitelisted hence we whitelist all URLs.
1464 WhitelistEverything(whitelist); 1506 WhitelistEverything(whitelist);
1465 } else { 1507 } else {
1466 base::AutoLock locked(lookup_lock_); 1508 base::AutoLock locked(lookup_lock_);
1467 whitelist->second = false; 1509 whitelist->second = false;
1468 whitelist->first.swap(new_whitelist); 1510 whitelist->first.swap(new_whitelist);
1469 } 1511 }
1470 } 1512 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698