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

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

Issue 1673733002: Support new Safe Browsing list "goog-badresource-shavar" in SafeBrowsingDatabase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 10 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 FILE_PATH_LITERAL(" Extension Blacklist"); 63 FILE_PATH_LITERAL(" Extension Blacklist");
64 // Filename suffix for the side-effect free whitelist store. 64 // Filename suffix for the side-effect free whitelist store.
65 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] = 65 const base::FilePath::CharType kSideEffectFreeWhitelistDBFile[] =
66 FILE_PATH_LITERAL(" Side-Effect Free Whitelist"); 66 FILE_PATH_LITERAL(" Side-Effect Free Whitelist");
67 // Filename suffix for the csd malware IP blacklist store. 67 // Filename suffix for the csd malware IP blacklist store.
68 const base::FilePath::CharType kIPBlacklistDBFile[] = 68 const base::FilePath::CharType kIPBlacklistDBFile[] =
69 FILE_PATH_LITERAL(" IP Blacklist"); 69 FILE_PATH_LITERAL(" IP Blacklist");
70 // Filename suffix for the unwanted software blacklist store. 70 // Filename suffix for the unwanted software blacklist store.
71 const base::FilePath::CharType kUnwantedSoftwareDBFile[] = 71 const base::FilePath::CharType kUnwantedSoftwareDBFile[] =
72 FILE_PATH_LITERAL(" UwS List"); 72 FILE_PATH_LITERAL(" UwS List");
73 // Filename suffix for the resource blacklist store.
74 const base::FilePath::CharType kResourceBlacklistDBFile[] =
75 FILE_PATH_LITERAL(" Resource Blacklist");
73 76
74 // Filename suffix for browse store. 77 // Filename suffix for browse store.
75 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win. 78 // TODO(shess): "Safe Browsing Bloom Prefix Set" is full of win.
76 // Unfortunately, to change the name implies lots of transition code 79 // Unfortunately, to change the name implies lots of transition code
77 // for little benefit. If/when file formats change (say to put all 80 // for little benefit. If/when file formats change (say to put all
78 // the data in one file), that would be a convenient point to rectify 81 // the data in one file), that would be a convenient point to rectify
79 // this. 82 // this.
80 const base::FilePath::CharType kBrowseDBFile[] = FILE_PATH_LITERAL(" Bloom"); 83 const base::FilePath::CharType kBrowseDBFile[] = FILE_PATH_LITERAL(" Bloom");
81 84
82 // Maximum number of entries we allow in any of the whitelists. 85 // Maximum number of entries we allow in any of the whitelists.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 bool enable_ip_blacklist, 284 bool enable_ip_blacklist,
282 bool enable_unwanted_software_list) override { 285 bool enable_unwanted_software_list) override {
283 return new SafeBrowsingDatabaseNew( 286 return new SafeBrowsingDatabaseNew(
284 db_task_runner, CreateStore(true, db_task_runner), // browse_store 287 db_task_runner, CreateStore(true, db_task_runner), // browse_store
285 CreateStore(enable_download_protection, db_task_runner), 288 CreateStore(enable_download_protection, db_task_runner),
286 CreateStore(enable_client_side_whitelist, db_task_runner), 289 CreateStore(enable_client_side_whitelist, db_task_runner),
287 CreateStore(enable_download_whitelist, db_task_runner), 290 CreateStore(enable_download_whitelist, db_task_runner),
288 CreateStore(true, db_task_runner), // inclusion_whitelist_store 291 CreateStore(true, db_task_runner), // inclusion_whitelist_store
289 CreateStore(enable_extension_blacklist, db_task_runner), 292 CreateStore(enable_extension_blacklist, db_task_runner),
290 CreateStore(enable_ip_blacklist, db_task_runner), 293 CreateStore(enable_ip_blacklist, db_task_runner),
291 CreateStore(enable_unwanted_software_list, db_task_runner)); 294 CreateStore(enable_unwanted_software_list, db_task_runner),
295 CreateStore(true, db_task_runner)); // resource_blacklist_store
292 } 296 }
293 297
294 SafeBrowsingDatabaseFactoryImpl() {} 298 SafeBrowsingDatabaseFactoryImpl() {}
295 299
296 private: 300 private:
297 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); 301 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl);
298 }; 302 };
299 303
300 // static 304 // static
301 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; 305 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 return base::FilePath(db_filename.value() + kIPBlacklistDBFile); 389 return base::FilePath(db_filename.value() + kIPBlacklistDBFile);
386 } 390 }
387 391
388 // static 392 // static
389 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename( 393 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename(
390 const base::FilePath& db_filename) { 394 const base::FilePath& db_filename) {
391 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); 395 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile);
392 } 396 }
393 397
394 // static 398 // static
399 base::FilePath SafeBrowsingDatabase::ResourceBlacklistDBFilename(
400 const base::FilePath& db_filename) {
401 return base::FilePath(db_filename.value() + kResourceBlacklistDBFile);
402 }
403
404 // static
395 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( 405 void SafeBrowsingDatabase::GetDownloadUrlPrefixes(
396 const std::vector<GURL>& urls, 406 const std::vector<GURL>& urls,
397 std::vector<SBPrefix>* prefixes) { 407 std::vector<SBPrefix>* prefixes) {
398 std::vector<SBFullHash> full_hashes; 408 std::vector<SBFullHash> full_hashes;
399 for (size_t i = 0; i < urls.size(); ++i) 409 for (size_t i = 0; i < urls.size(); ++i)
400 UrlToFullHashes(urls[i], false, &full_hashes); 410 UrlToFullHashes(urls[i], false, &full_hashes);
401 411
402 for (size_t i = 0; i < full_hashes.size(); ++i) 412 for (size_t i = 0; i < full_hashes.size(); ++i)
403 prefixes->push_back(full_hashes[i].prefix); 413 prefixes->push_back(full_hashes[i].prefix);
404 } 414 }
(...skipping 11 matching lines...) Expand all
416 } else if (list_id == DOWNLOADWHITELIST) { 426 } else if (list_id == DOWNLOADWHITELIST) {
417 return download_whitelist_store_.get(); 427 return download_whitelist_store_.get();
418 } else if (list_id == INCLUSIONWHITELIST) { 428 } else if (list_id == INCLUSIONWHITELIST) {
419 return inclusion_whitelist_store_.get(); 429 return inclusion_whitelist_store_.get();
420 } else if (list_id == EXTENSIONBLACKLIST) { 430 } else if (list_id == EXTENSIONBLACKLIST) {
421 return extension_blacklist_store_.get(); 431 return extension_blacklist_store_.get();
422 } else if (list_id == IPBLACKLIST) { 432 } else if (list_id == IPBLACKLIST) {
423 return ip_blacklist_store_.get(); 433 return ip_blacklist_store_.get();
424 } else if (list_id == UNWANTEDURL) { 434 } else if (list_id == UNWANTEDURL) {
425 return unwanted_software_store_.get(); 435 return unwanted_software_store_.get();
436 } else if (list_id == RESOURCEBLACKLIST) {
437 return resource_blacklist_store_.get();
426 } 438 }
427 return NULL; 439 return NULL;
428 } 440 }
429 441
430 // static 442 // static
431 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { 443 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) {
432 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, 444 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type,
433 FAILURE_DATABASE_MAX); 445 FAILURE_DATABASE_MAX);
434 } 446 }
435 447
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 610
599 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( 611 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew(
600 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 612 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
601 SafeBrowsingStore* browse_store, 613 SafeBrowsingStore* browse_store,
602 SafeBrowsingStore* download_store, 614 SafeBrowsingStore* download_store,
603 SafeBrowsingStore* csd_whitelist_store, 615 SafeBrowsingStore* csd_whitelist_store,
604 SafeBrowsingStore* download_whitelist_store, 616 SafeBrowsingStore* download_whitelist_store,
605 SafeBrowsingStore* inclusion_whitelist_store, 617 SafeBrowsingStore* inclusion_whitelist_store,
606 SafeBrowsingStore* extension_blacklist_store, 618 SafeBrowsingStore* extension_blacklist_store,
607 SafeBrowsingStore* ip_blacklist_store, 619 SafeBrowsingStore* ip_blacklist_store,
608 SafeBrowsingStore* unwanted_software_store) 620 SafeBrowsingStore* unwanted_software_store,
621 SafeBrowsingStore* resource_blacklist_store)
609 : db_task_runner_(db_task_runner), 622 : db_task_runner_(db_task_runner),
610 state_manager_(db_task_runner_), 623 state_manager_(db_task_runner_),
611 db_state_manager_(db_task_runner_), 624 db_state_manager_(db_task_runner_),
612 browse_store_(browse_store), 625 browse_store_(browse_store),
613 download_store_(download_store), 626 download_store_(download_store),
614 csd_whitelist_store_(csd_whitelist_store), 627 csd_whitelist_store_(csd_whitelist_store),
615 download_whitelist_store_(download_whitelist_store), 628 download_whitelist_store_(download_whitelist_store),
616 inclusion_whitelist_store_(inclusion_whitelist_store), 629 inclusion_whitelist_store_(inclusion_whitelist_store),
617 extension_blacklist_store_(extension_blacklist_store), 630 extension_blacklist_store_(extension_blacklist_store),
618 ip_blacklist_store_(ip_blacklist_store), 631 ip_blacklist_store_(ip_blacklist_store),
619 unwanted_software_store_(unwanted_software_store), 632 unwanted_software_store_(unwanted_software_store),
633 resource_blacklist_store_(resource_blacklist_store),
620 reset_factory_(this) { 634 reset_factory_(this) {
621 DCHECK(browse_store_.get()); 635 DCHECK(browse_store_.get());
622 } 636 }
623 637
624 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { 638 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() {
625 // The DCHECK is disabled due to crbug.com/338486 . 639 // The DCHECK is disabled due to crbug.com/338486 .
626 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 640 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
627 } 641 }
628 642
629 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { 643 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, 770 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
757 base::Unretained(this))); 771 base::Unretained(this)));
758 772
759 std::vector<SBAddFullHash> full_hashes; 773 std::vector<SBAddFullHash> full_hashes;
760 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) { 774 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) {
761 LoadIpBlacklist(full_hashes); 775 LoadIpBlacklist(full_hashes);
762 } else { 776 } else {
763 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. 777 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list.
764 } 778 }
765 } 779 }
780
781 if (resource_blacklist_store_.get()) {
782 resource_blacklist_store_->Init(
783 ResourceBlacklistDBFilename(db_state_manager_.filename_base()),
784 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase,
785 base::Unretained(this)));
786 }
766 } 787 }
767 788
768 bool SafeBrowsingDatabaseNew::ResetDatabase() { 789 bool SafeBrowsingDatabaseNew::ResetDatabase() {
769 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 790 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
770 791
771 // Delete files on disk. 792 // Delete files on disk.
772 // TODO(shess): Hard to see where one might want to delete without a 793 // TODO(shess): Hard to see where one might want to delete without a
773 // reset. Perhaps inline |Delete()|? 794 // reset. Perhaps inline |Delete()|?
774 if (!Delete()) 795 if (!Delete())
775 return false; 796 return false;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 << " mask:" << base::HexEncode(mask.data(), mask.size()) 959 << " mask:" << base::HexEncode(mask.data(), mask.size())
939 << " subnet:" << base::HexEncode(subnet.data(), subnet.size()) 960 << " subnet:" << base::HexEncode(subnet.data(), subnet.size())
940 << " hash:" << base::HexEncode(hash.data(), hash.size()); 961 << " hash:" << base::HexEncode(hash.data(), hash.size());
941 if (it->second.count(hash) > 0) { 962 if (it->second.count(hash) > 0) {
942 return true; 963 return true;
943 } 964 }
944 } 965 }
945 return false; 966 return false;
946 } 967 }
947 968
969 bool SafeBrowsingDatabaseNew::ContainsResourceUrlPrefixes(
970 const std::vector<SBPrefix>& prefixes,
971 std::vector<SBPrefix>* prefix_hits) {
972 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
973
974 if (!resource_blacklist_store_)
975 return false;
976
977 return MatchAddPrefixes(resource_blacklist_store_.get(),
978 RESOURCEBLACKLIST % 2, prefixes, prefix_hits);
979 }
980
948 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( 981 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString(
949 const std::string& str) { 982 const std::string& str) {
950 std::vector<SBFullHash> hashes; 983 std::vector<SBFullHash> hashes;
951 hashes.push_back(SBFullHashForString(str)); 984 hashes.push_back(SBFullHashForString(str));
952 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes); 985 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes);
953 } 986 }
954 987
955 bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes( 988 bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes(
956 SBWhitelistId whitelist_id, 989 SBWhitelistId whitelist_id,
957 const std::vector<SBFullHash>& hashes) { 990 const std::vector<SBFullHash>& hashes) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 HandleCorruptDatabase(); 1201 HandleCorruptDatabase();
1169 return false; 1202 return false;
1170 } 1203 }
1171 1204
1172 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) { 1205 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) {
1173 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN); 1206 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN);
1174 HandleCorruptDatabase(); 1207 HandleCorruptDatabase();
1175 return false; 1208 return false;
1176 } 1209 }
1177 1210
1211 if (resource_blacklist_store_ && !resource_blacklist_store_->BeginUpdate()) {
1212 RecordFailure(FAILURE_RESOURCE_BLACKLIST_UPDATE_BEGIN);
1213 HandleCorruptDatabase();
1214 return false;
1215 }
1216
1178 // Cached fullhash results must be cleared on every database update (whether 1217 // Cached fullhash results must be cleared on every database update (whether
1179 // successful or not). 1218 // successful or not).
1180 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); 1219 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache();
1181 1220
1182 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, 1221 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList,
1183 lists); 1222 lists);
1184 1223
1185 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been 1224 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been
1186 // deprecated. Code to delete the list from the store shows ~15k hits/day as 1225 // deprecated. Code to delete the list from the store shows ~15k hits/day as
1187 // of Feb 2014, so it has been removed. Everything _should_ be resilient to 1226 // of Feb 2014, so it has been removed. Everything _should_ be resilient to
1188 // extra data of that sort. 1227 // extra data of that sort.
1189 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); 1228 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists);
1190 1229
1191 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); 1230 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists);
1192 1231
1193 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, 1232 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList,
1194 lists); 1233 lists);
1195 1234
1196 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), 1235 UpdateChunkRangesForList(inclusion_whitelist_store_.get(),
1197 kInclusionWhitelist, lists); 1236 kInclusionWhitelist, lists);
1198 1237
1199 UpdateChunkRangesForList(extension_blacklist_store_.get(), 1238 UpdateChunkRangesForList(extension_blacklist_store_.get(),
1200 kExtensionBlacklist, lists); 1239 kExtensionBlacklist, lists);
1201 1240
1202 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); 1241 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists);
1203 1242
1204 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, 1243 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList,
1205 lists); 1244 lists);
1206 1245
1246 UpdateChunkRangesForList(resource_blacklist_store_.get(), kResourceBlacklist,
1247 lists);
1248
1207 db_state_manager_.reset_corruption_detected(); 1249 db_state_manager_.reset_corruption_detected();
1208 db_state_manager_.reset_change_detected(); 1250 db_state_manager_.reset_change_detected();
1209 return true; 1251 return true;
1210 } 1252 }
1211 1253
1212 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { 1254 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) {
1213 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1255 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1214 1256
1215 // The update may have failed due to corrupt storage (for instance, 1257 // The update may have failed due to corrupt storage (for instance,
1216 // an excessive number of invalid add_chunks and sub_chunks). 1258 // an excessive number of invalid add_chunks and sub_chunks).
(...skipping 27 matching lines...) Expand all
1244 } 1286 }
1245 1287
1246 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { 1288 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) {
1247 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; 1289 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt.";
1248 } 1290 }
1249 1291
1250 if (unwanted_software_store_ && 1292 if (unwanted_software_store_ &&
1251 !unwanted_software_store_->CheckValidity()) { 1293 !unwanted_software_store_->CheckValidity()) {
1252 DLOG(ERROR) << "Unwanted software url list database corrupt."; 1294 DLOG(ERROR) << "Unwanted software url list database corrupt.";
1253 } 1295 }
1296
1297 if (resource_blacklist_store_ &&
1298 !resource_blacklist_store_->CheckValidity()) {
1299 DLOG(ERROR) << "Resources blacklist url list database corrupt.";
1300 }
1254 } 1301 }
1255 1302
1256 if (db_state_manager_.corruption_detected()) 1303 if (db_state_manager_.corruption_detected())
1257 return; 1304 return;
1258 1305
1259 // Unroll the transaction if there was a protocol error or if the 1306 // Unroll the transaction if there was a protocol error or if the
1260 // transaction was empty. This will leave the prefix set, the 1307 // transaction was empty. This will leave the prefix set, the
1261 // pending hashes, and the prefix miss cache in place. 1308 // pending hashes, and the prefix miss cache in place.
1262 if (!update_succeeded || !db_state_manager_.change_detected()) { 1309 if (!update_succeeded || !db_state_manager_.change_detected()) {
1263 // Track empty updates to answer questions at http://crbug.com/72216 . 1310 // Track empty updates to answer questions at http://crbug.com/72216 .
1264 if (update_succeeded && !db_state_manager_.change_detected()) 1311 if (update_succeeded && !db_state_manager_.change_detected())
1265 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); 1312 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0);
1266 browse_store_->CancelUpdate(); 1313 browse_store_->CancelUpdate();
1267 if (download_store_.get()) 1314 if (download_store_.get())
1268 download_store_->CancelUpdate(); 1315 download_store_->CancelUpdate();
1269 if (csd_whitelist_store_.get()) 1316 if (csd_whitelist_store_.get())
1270 csd_whitelist_store_->CancelUpdate(); 1317 csd_whitelist_store_->CancelUpdate();
1271 if (download_whitelist_store_.get()) 1318 if (download_whitelist_store_.get())
1272 download_whitelist_store_->CancelUpdate(); 1319 download_whitelist_store_->CancelUpdate();
1273 if (inclusion_whitelist_store_.get()) 1320 if (inclusion_whitelist_store_.get())
1274 inclusion_whitelist_store_->CancelUpdate(); 1321 inclusion_whitelist_store_->CancelUpdate();
1275 if (extension_blacklist_store_) 1322 if (extension_blacklist_store_)
1276 extension_blacklist_store_->CancelUpdate(); 1323 extension_blacklist_store_->CancelUpdate();
1277 if (ip_blacklist_store_) 1324 if (ip_blacklist_store_)
1278 ip_blacklist_store_->CancelUpdate(); 1325 ip_blacklist_store_->CancelUpdate();
1279 if (unwanted_software_store_) 1326 if (unwanted_software_store_)
1280 unwanted_software_store_->CancelUpdate(); 1327 unwanted_software_store_->CancelUpdate();
1328 if (resource_blacklist_store_)
1329 resource_blacklist_store_->CancelUpdate();
1281 return; 1330 return;
1282 } 1331 }
1283 1332
1284 if (download_store_) { 1333 if (download_store_) {
1285 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), 1334 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()),
1286 download_store_.get(), 1335 download_store_.get(),
1287 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); 1336 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH);
1288 } 1337 }
1289 1338
1290 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), 1339 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()),
(...skipping 21 matching lines...) Expand all
1312 if (ip_blacklist_store_) 1361 if (ip_blacklist_store_)
1313 UpdateIpBlacklistStore(); 1362 UpdateIpBlacklistStore();
1314 1363
1315 if (unwanted_software_store_) { 1364 if (unwanted_software_store_) {
1316 UpdatePrefixSetUrlStore( 1365 UpdatePrefixSetUrlStore(
1317 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), 1366 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()),
1318 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, 1367 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE,
1319 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, 1368 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH,
1320 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); 1369 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true);
1321 } 1370 }
1371
1372 if (resource_blacklist_store_) {
1373 UpdateHashPrefixStore(
1374 ResourceBlacklistDBFilename(db_state_manager_.filename_base()),
1375 resource_blacklist_store_.get(),
1376 FAILURE_RESOURCE_BLACKLIST_UPDATE_FINISH);
1377 }
1322 } 1378 }
1323 1379
1324 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( 1380 void SafeBrowsingDatabaseNew::UpdateWhitelistStore(
1325 const base::FilePath& store_filename, 1381 const base::FilePath& store_filename,
1326 SafeBrowsingStore* store, 1382 SafeBrowsingStore* store,
1327 SBWhitelistId whitelist_id) { 1383 SBWhitelistId whitelist_id) {
1328 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1384 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1329 1385
1330 if (!store) 1386 if (!store)
1331 return; 1387 return;
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 const bool r9 = base::DeleteFile( 1651 const bool r9 = base::DeleteFile(
1596 IpBlacklistDBFilename(db_state_manager_.filename_base()), false); 1652 IpBlacklistDBFilename(db_state_manager_.filename_base()), false);
1597 if (!r9) 1653 if (!r9)
1598 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); 1654 RecordFailure(FAILURE_IP_BLACKLIST_DELETE);
1599 1655
1600 const bool r10 = base::DeleteFile( 1656 const bool r10 = base::DeleteFile(
1601 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false); 1657 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false);
1602 if (!r10) 1658 if (!r10)
1603 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); 1659 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE);
1604 1660
1605 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10; 1661 const bool r11 = base::DeleteFile(
1662 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), false);
1663 if (!r11)
1664 RecordFailure(FAILURE_RESOURCE_BLACKLIST_DELETE);
1665
1666 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11;
1606 } 1667 }
1607 1668
1608 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, 1669 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename,
1609 PrefixSetId prefix_set_id, 1670 PrefixSetId prefix_set_id,
1610 FailureType write_failure_type) { 1671 FailureType write_failure_type) {
1611 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1672 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1612 1673
1613 // Do not grab the lock to avoid contention while writing to disk. This is 1674 // Do not grab the lock to avoid contention while writing to disk. This is
1614 // safe as only this task runner can ever modify |state_manager_|'s prefix 1675 // safe as only this task runner can ever modify |state_manager_|'s prefix
1615 // sets anyways. 1676 // sets anyways.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 histogram_name.append(".InclusionWhitelist"); 1822 histogram_name.append(".InclusionWhitelist");
1762 else if (base::EndsWith(filename, kExtensionBlacklistDBFile, 1823 else if (base::EndsWith(filename, kExtensionBlacklistDBFile,
1763 base::CompareCase::SENSITIVE)) 1824 base::CompareCase::SENSITIVE))
1764 histogram_name.append(".ExtensionBlacklist"); 1825 histogram_name.append(".ExtensionBlacklist");
1765 else if (base::EndsWith(filename, kIPBlacklistDBFile, 1826 else if (base::EndsWith(filename, kIPBlacklistDBFile,
1766 base::CompareCase::SENSITIVE)) 1827 base::CompareCase::SENSITIVE))
1767 histogram_name.append(".IPBlacklist"); 1828 histogram_name.append(".IPBlacklist");
1768 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, 1829 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile,
1769 base::CompareCase::SENSITIVE)) 1830 base::CompareCase::SENSITIVE))
1770 histogram_name.append(".UnwantedSoftware"); 1831 histogram_name.append(".UnwantedSoftware");
1832 else if (base::EndsWith(filename, kResourceBlacklistDBFile,
1833 base::CompareCase::SENSITIVE))
1834 histogram_name.append(".ResourceBlacklist");
1771 else 1835 else
1772 NOTREACHED(); // Add support for new lists above. 1836 NOTREACHED(); // Add support for new lists above.
1773 1837
1774 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. 1838 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro.
1775 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( 1839 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet(
1776 histogram_name, 1, 1000000, 50, 1840 histogram_name, 1, 1000000, 50,
1777 base::HistogramBase::kUmaTargetedHistogramFlag); 1841 base::HistogramBase::kUmaTargetedHistogramFlag);
1778 1842
1779 histogram_pointer->Add(file_size_kilobytes); 1843 histogram_pointer->Add(file_size_kilobytes);
1780 } 1844 }
1781 1845
1782 } // namespace safe_browsing 1846 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698