OLD | NEW |
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" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/metrics/stats_counters.h" | 14 #include "base/metrics/stats_counters.h" |
15 #include "base/process_util.h" | 15 #include "base/process_util.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "chrome/browser/safe_browsing/bloom_filter.h" | |
18 #include "chrome/browser/safe_browsing/prefix_set.h" | 17 #include "chrome/browser/safe_browsing/prefix_set.h" |
19 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" |
20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
21 #include "crypto/sha2.h" | 20 #include "crypto/sha2.h" |
22 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
23 | 22 |
24 #if defined(OS_MACOSX) | 23 #if defined(OS_MACOSX) |
25 #include "base/mac/mac_util.h" | 24 #include "base/mac/mac_util.h" |
26 #endif | 25 #endif |
27 | 26 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if (subs_deleted > 0) | 256 if (subs_deleted > 0) |
258 UMA_HISTOGRAM_COUNTS("SB2.DownloadBinhashSubsDeleted", subs_deleted); | 257 UMA_HISTOGRAM_COUNTS("SB2.DownloadBinhashSubsDeleted", subs_deleted); |
259 } | 258 } |
260 | 259 |
261 // Order |SBAddFullHash| on the prefix part. |SBAddPrefixLess()| from | 260 // Order |SBAddFullHash| on the prefix part. |SBAddPrefixLess()| from |
262 // safe_browsing_store.h orders on both chunk-id and prefix. | 261 // safe_browsing_store.h orders on both chunk-id and prefix. |
263 bool SBAddFullHashPrefixLess(const SBAddFullHash& a, const SBAddFullHash& b) { | 262 bool SBAddFullHashPrefixLess(const SBAddFullHash& a, const SBAddFullHash& b) { |
264 return a.full_hash.prefix < b.full_hash.prefix; | 263 return a.full_hash.prefix < b.full_hash.prefix; |
265 } | 264 } |
266 | 265 |
267 // Track what LoadBloomFilterOrPrefixSet() loaded. | |
268 enum FilterLoad { | |
269 FILTER_LOAD, // All calls. | |
270 FILTER_LOADED_PREFIX_SET, // Cases loaded from prefix set. | |
271 FILTER_LOADED_BLOOM_FILTER, // Cases loaded from bloom filter. | |
272 | |
273 // Memory space for histograms is determined by the max. ALWAYS ADD | |
274 // NEW VALUES BEFORE THIS ONE. | |
275 FILTER_LOAD_MAX | |
276 }; | |
277 | |
278 void RecordFilterLoad(FilterLoad event_type) { | |
279 UMA_HISTOGRAM_ENUMERATION("SB2.FilterLoad", event_type, | |
280 FILTER_LOAD_MAX); | |
281 } | |
282 | |
283 // This code always checks for non-zero file size. This helper makes | 266 // This code always checks for non-zero file size. This helper makes |
284 // that less verbose. | 267 // that less verbose. |
285 int64 GetFileSizeOrZero(const FilePath& file_path) { | 268 int64 GetFileSizeOrZero(const FilePath& file_path) { |
286 int64 size_64; | 269 int64 size_64; |
287 if (!file_util::GetFileSize(file_path, &size_64)) | 270 if (!file_util::GetFileSize(file_path, &size_64)) |
288 return 0; | 271 return 0; |
289 return size_64; | 272 return size_64; |
290 } | 273 } |
291 | 274 |
292 } // namespace | 275 } // namespace |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 | 407 |
425 void SafeBrowsingDatabaseNew::Init(const FilePath& filename_base) { | 408 void SafeBrowsingDatabaseNew::Init(const FilePath& filename_base) { |
426 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 409 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
427 // Ensure we haven't been run before. | 410 // Ensure we haven't been run before. |
428 DCHECK(browse_filename_.empty()); | 411 DCHECK(browse_filename_.empty()); |
429 DCHECK(download_filename_.empty()); | 412 DCHECK(download_filename_.empty()); |
430 DCHECK(csd_whitelist_filename_.empty()); | 413 DCHECK(csd_whitelist_filename_.empty()); |
431 DCHECK(download_whitelist_filename_.empty()); | 414 DCHECK(download_whitelist_filename_.empty()); |
432 | 415 |
433 browse_filename_ = BrowseDBFilename(filename_base); | 416 browse_filename_ = BrowseDBFilename(filename_base); |
434 bloom_filter_filename_ = BloomFilterForFilename(browse_filename_); | |
435 prefix_set_filename_ = PrefixSetForFilename(browse_filename_); | 417 prefix_set_filename_ = PrefixSetForFilename(browse_filename_); |
436 | 418 |
437 browse_store_->Init( | 419 browse_store_->Init( |
438 browse_filename_, | 420 browse_filename_, |
439 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | 421 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
440 base::Unretained(this))); | 422 base::Unretained(this))); |
441 DVLOG(1) << "Init browse store: " << browse_filename_.value(); | 423 DVLOG(1) << "Init browse store: " << browse_filename_.value(); |
442 | 424 |
443 { | 425 { |
444 // NOTE: There is no need to grab the lock in this function, since | 426 // NOTE: There is no need to grab the lock in this function, since |
445 // until it returns, there are no pointers to this class on other | 427 // until it returns, there are no pointers to this class on other |
446 // threads. Then again, that means there is no possibility of | 428 // threads. Then again, that means there is no possibility of |
447 // contention on the lock... | 429 // contention on the lock... |
448 base::AutoLock locked(lookup_lock_); | 430 base::AutoLock locked(lookup_lock_); |
449 full_browse_hashes_.clear(); | 431 full_browse_hashes_.clear(); |
450 pending_browse_hashes_.clear(); | 432 pending_browse_hashes_.clear(); |
451 LoadBloomFilterOrPrefixSet(); | 433 LoadPrefixSet(); |
452 } | 434 } |
453 | 435 |
454 if (download_store_.get()) { | 436 if (download_store_.get()) { |
455 download_filename_ = DownloadDBFilename(filename_base); | 437 download_filename_ = DownloadDBFilename(filename_base); |
456 download_store_->Init( | 438 download_store_->Init( |
457 download_filename_, | 439 download_filename_, |
458 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | 440 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
459 base::Unretained(this))); | 441 base::Unretained(this))); |
460 DVLOG(1) << "Init download store: " << download_filename_.value(); | 442 DVLOG(1) << "Init download store: " << download_filename_.value(); |
461 } | 443 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 // reset. Perhaps inline |Delete()|? | 486 // reset. Perhaps inline |Delete()|? |
505 if (!Delete()) | 487 if (!Delete()) |
506 return false; | 488 return false; |
507 | 489 |
508 // Reset objects in memory. | 490 // Reset objects in memory. |
509 { | 491 { |
510 base::AutoLock locked(lookup_lock_); | 492 base::AutoLock locked(lookup_lock_); |
511 full_browse_hashes_.clear(); | 493 full_browse_hashes_.clear(); |
512 pending_browse_hashes_.clear(); | 494 pending_browse_hashes_.clear(); |
513 prefix_miss_cache_.clear(); | 495 prefix_miss_cache_.clear(); |
514 browse_bloom_filter_ = NULL; | |
515 prefix_set_.reset(); | 496 prefix_set_.reset(); |
516 } | 497 } |
517 // Wants to acquire the lock itself. | 498 // Wants to acquire the lock itself. |
518 WhitelistEverything(&csd_whitelist_); | 499 WhitelistEverything(&csd_whitelist_); |
519 WhitelistEverything(&download_whitelist_); | 500 WhitelistEverything(&download_whitelist_); |
520 | 501 |
521 return true; | 502 return true; |
522 } | 503 } |
523 | 504 |
524 // TODO(lzheng): Remove matching_list, it is not used anywhere. | 505 // TODO(lzheng): Remove matching_list, it is not used anywhere. |
(...skipping 10 matching lines...) Expand all Loading... |
535 | 516 |
536 std::vector<SBFullHash> full_hashes; | 517 std::vector<SBFullHash> full_hashes; |
537 BrowseFullHashesToCheck(url, false, &full_hashes); | 518 BrowseFullHashesToCheck(url, false, &full_hashes); |
538 if (full_hashes.empty()) | 519 if (full_hashes.empty()) |
539 return false; | 520 return false; |
540 | 521 |
541 // This function is called on the I/O thread, prevent changes to | 522 // This function is called on the I/O thread, prevent changes to |
542 // filter and caches. | 523 // filter and caches. |
543 base::AutoLock locked(lookup_lock_); | 524 base::AutoLock locked(lookup_lock_); |
544 | 525 |
545 // TODO(shess): During transition, users will have a bloom filter | 526 // |prefix_set_| is empty until it is either read from disk, or the |
546 // but no prefix set until first update, after which they'll have a | 527 // first update populates it. Bail out without a hit if not yet |
547 // prefix set but no bloom filter. | 528 // available. |
548 const bool use_prefix_set = prefix_set_.get() != NULL; | 529 if (!prefix_set_.get()) |
549 if (!use_prefix_set && !browse_bloom_filter_.get()) | |
550 return false; | 530 return false; |
551 | 531 |
552 size_t miss_count = 0; | 532 size_t miss_count = 0; |
553 for (size_t i = 0; i < full_hashes.size(); ++i) { | 533 for (size_t i = 0; i < full_hashes.size(); ++i) { |
554 const SBPrefix prefix = full_hashes[i].prefix; | 534 const SBPrefix prefix = full_hashes[i].prefix; |
555 if ((use_prefix_set && prefix_set_->Exists(prefix)) || | 535 if (prefix_set_->Exists(prefix)) { |
556 (!use_prefix_set && browse_bloom_filter_->Exists(prefix))) { | |
557 prefix_hits->push_back(prefix); | 536 prefix_hits->push_back(prefix); |
558 if (prefix_miss_cache_.count(prefix) > 0) | 537 if (prefix_miss_cache_.count(prefix) > 0) |
559 ++miss_count; | 538 ++miss_count; |
560 } | 539 } |
561 } | 540 } |
562 | 541 |
563 // If all the prefixes are cached as 'misses', don't issue a GetHash. | 542 // If all the prefixes are cached as 'misses', don't issue a GetHash. |
564 if (miss_count == prefix_hits->size()) | 543 if (miss_count == prefix_hits->size()) |
565 return false; | 544 return false; |
566 | 545 |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 if (download_whitelist_store_.get() && | 984 if (download_whitelist_store_.get() && |
1006 !download_whitelist_store_->CheckValidity()) { | 985 !download_whitelist_store_->CheckValidity()) { |
1007 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; | 986 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; |
1008 } | 987 } |
1009 } | 988 } |
1010 | 989 |
1011 if (corruption_detected_) | 990 if (corruption_detected_) |
1012 return; | 991 return; |
1013 | 992 |
1014 // Unroll the transaction if there was a protocol error or if the | 993 // Unroll the transaction if there was a protocol error or if the |
1015 // transaction was empty. This will leave the bloom filter, the | 994 // transaction was empty. This will leave the prefix set, the |
1016 // pending hashes, and the prefix miss cache in place. | 995 // pending hashes, and the prefix miss cache in place. |
1017 if (!update_succeeded || !change_detected_) { | 996 if (!update_succeeded || !change_detected_) { |
1018 // Track empty updates to answer questions at http://crbug.com/72216 . | 997 // Track empty updates to answer questions at http://crbug.com/72216 . |
1019 if (update_succeeded && !change_detected_) | 998 if (update_succeeded && !change_detected_) |
1020 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 999 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
1021 browse_store_->CancelUpdate(); | 1000 browse_store_->CancelUpdate(); |
1022 if (download_store_.get()) | 1001 if (download_store_.get()) |
1023 download_store_->CancelUpdate(); | 1002 download_store_->CancelUpdate(); |
1024 if (csd_whitelist_store_.get()) | 1003 if (csd_whitelist_store_.get()) |
1025 csd_whitelist_store_->CancelUpdate(); | 1004 csd_whitelist_store_->CancelUpdate(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 base::AutoLock locked(lookup_lock_); | 1144 base::AutoLock locked(lookup_lock_); |
1166 full_browse_hashes_.swap(add_full_hashes); | 1145 full_browse_hashes_.swap(add_full_hashes); |
1167 | 1146 |
1168 // TODO(shess): If |CacheHashResults()| is posted between the | 1147 // TODO(shess): If |CacheHashResults()| is posted between the |
1169 // earlier lock and this clear, those pending hashes will be lost. | 1148 // earlier lock and this clear, those pending hashes will be lost. |
1170 // It could be fixed by only removing hashes which were collected | 1149 // It could be fixed by only removing hashes which were collected |
1171 // at the earlier point. I believe that is fail-safe as-is (the | 1150 // at the earlier point. I believe that is fail-safe as-is (the |
1172 // hash will be fetched again). | 1151 // hash will be fetched again). |
1173 pending_browse_hashes_.clear(); | 1152 pending_browse_hashes_.clear(); |
1174 prefix_miss_cache_.clear(); | 1153 prefix_miss_cache_.clear(); |
1175 browse_bloom_filter_ = NULL; // Stop using the bloom filter. | |
1176 prefix_set_.swap(prefix_set); | 1154 prefix_set_.swap(prefix_set); |
1177 } | 1155 } |
1178 | 1156 |
1179 DVLOG(1) << "SafeBrowsingDatabaseImpl built prefix set in " | 1157 DVLOG(1) << "SafeBrowsingDatabaseImpl built prefix set in " |
1180 << (base::TimeTicks::Now() - before).InMilliseconds() | 1158 << (base::TimeTicks::Now() - before).InMilliseconds() |
1181 << " ms total. prefix count: " << add_prefixes.size(); | 1159 << " ms total. prefix count: " << add_prefixes.size(); |
1182 UMA_HISTOGRAM_LONG_TIMES("SB2.BuildFilter", base::TimeTicks::Now() - before); | 1160 UMA_HISTOGRAM_LONG_TIMES("SB2.BuildFilter", base::TimeTicks::Now() - before); |
1183 | 1161 |
1184 // Persist the prefix set to disk. Since only this thread changes | 1162 // Persist the prefix set to disk. Since only this thread changes |
1185 // |prefix_set_|, there is no need to lock. | 1163 // |prefix_set_|, there is no need to lock. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 | 1204 |
1227 void SafeBrowsingDatabaseNew::OnHandleCorruptDatabase() { | 1205 void SafeBrowsingDatabaseNew::OnHandleCorruptDatabase() { |
1228 RecordFailure(FAILURE_DATABASE_CORRUPT_HANDLER); | 1206 RecordFailure(FAILURE_DATABASE_CORRUPT_HANDLER); |
1229 corruption_detected_ = true; // Stop updating the database. | 1207 corruption_detected_ = true; // Stop updating the database. |
1230 ResetDatabase(); | 1208 ResetDatabase(); |
1231 DLOG(FATAL) << "SafeBrowsing database was corrupt and reset"; | 1209 DLOG(FATAL) << "SafeBrowsing database was corrupt and reset"; |
1232 } | 1210 } |
1233 | 1211 |
1234 // TODO(shess): I'm not clear why this code doesn't have any | 1212 // TODO(shess): I'm not clear why this code doesn't have any |
1235 // real error-handling. | 1213 // real error-handling. |
1236 // TODO(shess): After a transition period, this can convert to just | 1214 void SafeBrowsingDatabaseNew::LoadPrefixSet() { |
1237 // giving up if the prefix set is not on disk. | |
1238 void SafeBrowsingDatabaseNew::LoadBloomFilterOrPrefixSet() { | |
1239 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 1215 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
1240 DCHECK(!bloom_filter_filename_.empty()); | |
1241 DCHECK(!prefix_set_filename_.empty()); | 1216 DCHECK(!prefix_set_filename_.empty()); |
1242 | 1217 |
1243 // If there is no database, the filter cannot be used. | 1218 // If there is no database, the filter cannot be used. |
1244 base::PlatformFileInfo db_info; | 1219 base::PlatformFileInfo db_info; |
1245 if (!file_util::GetFileInfo(browse_filename_, &db_info) || db_info.size == 0) | 1220 if (!file_util::GetFileInfo(browse_filename_, &db_info) || db_info.size == 0) |
1246 return; | 1221 return; |
1247 | 1222 |
1248 RecordFilterLoad(FILTER_LOAD); | 1223 // Cleanup any stale bloom filter (no longer used). |
1249 | 1224 // TODO(shess): Track failure to delete? |
1250 // If there is no prefix set, or if the file is too old, check for a | 1225 FilePath bloom_filter_filename = BloomFilterForFilename(browse_filename_); |
1251 // bloom filter. | 1226 file_util::Delete(bloom_filter_filename, false); |
1252 // TODO(shess): The time check is in case this code gets reverted | |
1253 // and re-landed. It might be good to keep as a sanity check. | |
1254 // Better would be to put the db's checksum in the filter file. | |
1255 base::PlatformFileInfo prefix_set_info; | |
1256 if (!file_util::GetFileInfo(prefix_set_filename_, &prefix_set_info) || | |
1257 prefix_set_info.size == 0 || | |
1258 prefix_set_info.last_modified < db_info.last_modified) { | |
1259 // No prefix set. | |
1260 prefix_set_.reset(); | |
1261 | |
1262 int64 file_size = GetFileSizeOrZero(bloom_filter_filename_); | |
1263 if (!file_size) { | |
1264 RecordFailure(FAILURE_DATABASE_FILTER_MISSING); | |
1265 return; | |
1266 } | |
1267 | |
1268 const base::TimeTicks before = base::TimeTicks::Now(); | |
1269 browse_bloom_filter_ = BloomFilter::LoadFile(bloom_filter_filename_); | |
1270 DVLOG(1) << "SafeBrowsingDatabaseNew read bloom filter in " | |
1271 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; | |
1272 UMA_HISTOGRAM_TIMES("SB2.BloomFilterLoad", base::TimeTicks::Now() - before); | |
1273 | |
1274 if (!browse_bloom_filter_.get()) | |
1275 RecordFailure(FAILURE_DATABASE_FILTER_READ); | |
1276 else | |
1277 RecordFilterLoad(FILTER_LOADED_BLOOM_FILTER); | |
1278 | |
1279 return; | |
1280 } | |
1281 | |
1282 // Once there is a prefix set stored, never use the bloom filter. | |
1283 browse_bloom_filter_ = NULL; | |
1284 | |
1285 // TODO(shess): The bloom filter file should have been deleted in | |
1286 // WritePrefixSet(), unless this code is reverted and re-landed. | |
1287 // Just paranoid. | |
1288 file_util::Delete(bloom_filter_filename_, false); | |
1289 | 1227 |
1290 const base::TimeTicks before = base::TimeTicks::Now(); | 1228 const base::TimeTicks before = base::TimeTicks::Now(); |
1291 prefix_set_.reset(safe_browsing::PrefixSet::LoadFile(prefix_set_filename_)); | 1229 prefix_set_.reset(safe_browsing::PrefixSet::LoadFile(prefix_set_filename_)); |
1292 DVLOG(1) << "SafeBrowsingDatabaseNew read prefix set in " | 1230 DVLOG(1) << "SafeBrowsingDatabaseNew read prefix set in " |
1293 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; | 1231 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; |
1294 UMA_HISTOGRAM_TIMES("SB2.PrefixSetLoad", base::TimeTicks::Now() - before); | 1232 UMA_HISTOGRAM_TIMES("SB2.PrefixSetLoad", base::TimeTicks::Now() - before); |
1295 | 1233 |
1296 if (!prefix_set_.get()) | 1234 if (!prefix_set_.get()) |
1297 RecordFailure(FAILURE_DATABASE_PREFIX_SET_READ); | 1235 RecordFailure(FAILURE_DATABASE_PREFIX_SET_READ); |
1298 else | |
1299 RecordFilterLoad(FILTER_LOADED_PREFIX_SET); | |
1300 } | 1236 } |
1301 | 1237 |
1302 bool SafeBrowsingDatabaseNew::Delete() { | 1238 bool SafeBrowsingDatabaseNew::Delete() { |
1303 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 1239 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
1304 | 1240 |
1305 const bool r1 = browse_store_->Delete(); | 1241 const bool r1 = browse_store_->Delete(); |
1306 if (!r1) | 1242 if (!r1) |
1307 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1243 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
1308 | 1244 |
1309 const bool r2 = download_store_.get() ? download_store_->Delete() : true; | 1245 const bool r2 = download_store_.get() ? download_store_->Delete() : true; |
1310 if (!r2) | 1246 if (!r2) |
1311 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1247 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
1312 | 1248 |
1313 const bool r3 = csd_whitelist_store_.get() ? | 1249 const bool r3 = csd_whitelist_store_.get() ? |
1314 csd_whitelist_store_->Delete() : true; | 1250 csd_whitelist_store_->Delete() : true; |
1315 if (!r3) | 1251 if (!r3) |
1316 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1252 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
1317 | 1253 |
1318 const bool r4 = download_whitelist_store_.get() ? | 1254 const bool r4 = download_whitelist_store_.get() ? |
1319 download_whitelist_store_->Delete() : true; | 1255 download_whitelist_store_->Delete() : true; |
1320 if (!r4) | 1256 if (!r4) |
1321 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1257 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
1322 | 1258 |
1323 const bool r5 = file_util::Delete(bloom_filter_filename_, false); | 1259 FilePath bloom_filter_filename = BloomFilterForFilename(browse_filename_); |
| 1260 const bool r5 = file_util::Delete(bloom_filter_filename, false); |
1324 if (!r5) | 1261 if (!r5) |
1325 RecordFailure(FAILURE_DATABASE_FILTER_DELETE); | 1262 RecordFailure(FAILURE_DATABASE_FILTER_DELETE); |
1326 | 1263 |
1327 const bool r6 = file_util::Delete(prefix_set_filename_, false); | 1264 const bool r6 = file_util::Delete(prefix_set_filename_, false); |
1328 if (!r6) | 1265 if (!r6) |
1329 RecordFailure(FAILURE_DATABASE_PREFIX_SET_DELETE); | 1266 RecordFailure(FAILURE_DATABASE_PREFIX_SET_DELETE); |
1330 return r1 && r2 && r3 && r4 && r5 && r6; | 1267 return r1 && r2 && r3 && r4 && r5 && r6; |
1331 } | 1268 } |
1332 | 1269 |
1333 void SafeBrowsingDatabaseNew::WritePrefixSet() { | 1270 void SafeBrowsingDatabaseNew::WritePrefixSet() { |
1334 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 1271 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
1335 | 1272 |
1336 if (!prefix_set_.get()) | 1273 if (!prefix_set_.get()) |
1337 return; | 1274 return; |
1338 | 1275 |
1339 const base::TimeTicks before = base::TimeTicks::Now(); | 1276 const base::TimeTicks before = base::TimeTicks::Now(); |
1340 const bool write_ok = prefix_set_->WriteFile(prefix_set_filename_); | 1277 const bool write_ok = prefix_set_->WriteFile(prefix_set_filename_); |
1341 DVLOG(1) << "SafeBrowsingDatabaseNew wrote prefix set in " | 1278 DVLOG(1) << "SafeBrowsingDatabaseNew wrote prefix set in " |
1342 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; | 1279 << (base::TimeTicks::Now() - before).InMilliseconds() << " ms"; |
1343 UMA_HISTOGRAM_TIMES("SB2.PrefixSetWrite", base::TimeTicks::Now() - before); | 1280 UMA_HISTOGRAM_TIMES("SB2.PrefixSetWrite", base::TimeTicks::Now() - before); |
1344 | 1281 |
1345 if (!write_ok) | 1282 if (!write_ok) |
1346 RecordFailure(FAILURE_DATABASE_PREFIX_SET_WRITE); | 1283 RecordFailure(FAILURE_DATABASE_PREFIX_SET_WRITE); |
1347 | 1284 |
1348 // Delete any stale bloom filter (checking before deleting is | |
1349 // unlikely to be faster). | |
1350 file_util::Delete(bloom_filter_filename_, false); | |
1351 | |
1352 #if defined(OS_MACOSX) | 1285 #if defined(OS_MACOSX) |
1353 base::mac::SetFileBackupExclusion(prefix_set_filename_); | 1286 base::mac::SetFileBackupExclusion(prefix_set_filename_); |
1354 #endif | 1287 #endif |
1355 } | 1288 } |
1356 | 1289 |
1357 void SafeBrowsingDatabaseNew::WhitelistEverything(SBWhitelist* whitelist) { | 1290 void SafeBrowsingDatabaseNew::WhitelistEverything(SBWhitelist* whitelist) { |
1358 base::AutoLock locked(lookup_lock_); | 1291 base::AutoLock locked(lookup_lock_); |
1359 whitelist->second = true; | 1292 whitelist->second = true; |
1360 whitelist->first.clear(); | 1293 whitelist->first.clear(); |
1361 } | 1294 } |
(...skipping 21 matching lines...) Expand all Loading... |
1383 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), | 1316 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), |
1384 kill_switch)) { | 1317 kill_switch)) { |
1385 // The kill switch is whitelisted hence we whitelist all URLs. | 1318 // The kill switch is whitelisted hence we whitelist all URLs. |
1386 WhitelistEverything(whitelist); | 1319 WhitelistEverything(whitelist); |
1387 } else { | 1320 } else { |
1388 base::AutoLock locked(lookup_lock_); | 1321 base::AutoLock locked(lookup_lock_); |
1389 whitelist->second = false; | 1322 whitelist->second = false; |
1390 whitelist->first.swap(new_whitelist); | 1323 whitelist->first.swap(new_whitelist); |
1391 } | 1324 } |
1392 } | 1325 } |
OLD | NEW |