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" |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 download_whitelist_listnames, lists); | 1094 download_whitelist_listnames, lists); |
1095 } | 1095 } |
1096 | 1096 |
1097 corruption_detected_ = false; | 1097 corruption_detected_ = false; |
1098 change_detected_ = false; | 1098 change_detected_ = false; |
1099 return true; | 1099 return true; |
1100 } | 1100 } |
1101 | 1101 |
1102 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { | 1102 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
1103 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 1103 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 1104 |
| 1105 // The update may have failed due to corrupt storage (for instance, |
| 1106 // an excessive number of invalid add_chunks and sub_chunks). |
| 1107 // Double-check that the databases are valid. |
| 1108 // TODO(shess): Providing a checksum for the add_chunk and sub_chunk |
| 1109 // sections would allow throwing a corruption error in |
| 1110 // UpdateStarted(). |
| 1111 if (!update_succeeded) { |
| 1112 if (!browse_store_->CheckValidity()) |
| 1113 DLOG(ERROR) << "Safe-browsing browse database corrupt."; |
| 1114 |
| 1115 if (download_store_.get() && !download_store_->CheckValidity()) |
| 1116 DLOG(ERROR) << "Safe-browsing download database corrupt."; |
| 1117 |
| 1118 if (csd_whitelist_store_.get() && !csd_whitelist_store_->CheckValidity()) |
| 1119 DLOG(ERROR) << "Safe-browsing csd whitelist database corrupt."; |
| 1120 |
| 1121 if (download_whitelist_store_.get() && |
| 1122 !download_whitelist_store_->CheckValidity()) { |
| 1123 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; |
| 1124 } |
| 1125 } |
| 1126 |
1104 if (corruption_detected_) | 1127 if (corruption_detected_) |
1105 return; | 1128 return; |
1106 | 1129 |
1107 // Unroll the transaction if there was a protocol error or if the | 1130 // Unroll the transaction if there was a protocol error or if the |
1108 // transaction was empty. This will leave the bloom filter, the | 1131 // transaction was empty. This will leave the bloom filter, the |
1109 // pending hashes, and the prefix miss cache in place. | 1132 // pending hashes, and the prefix miss cache in place. |
1110 if (!update_succeeded || !change_detected_) { | 1133 if (!update_succeeded || !change_detected_) { |
1111 // Track empty updates to answer questions at http://crbug.com/72216 . | 1134 // Track empty updates to answer questions at http://crbug.com/72216 . |
1112 if (update_succeeded && !change_detected_) | 1135 if (update_succeeded && !change_detected_) |
1113 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 1136 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1318 MessageLoop::current()->PostTask(FROM_HERE, | 1341 MessageLoop::current()->PostTask(FROM_HERE, |
1319 base::Bind(&SafeBrowsingDatabaseNew::OnHandleCorruptDatabase, | 1342 base::Bind(&SafeBrowsingDatabaseNew::OnHandleCorruptDatabase, |
1320 reset_factory_.GetWeakPtr())); | 1343 reset_factory_.GetWeakPtr())); |
1321 } | 1344 } |
1322 } | 1345 } |
1323 | 1346 |
1324 void SafeBrowsingDatabaseNew::OnHandleCorruptDatabase() { | 1347 void SafeBrowsingDatabaseNew::OnHandleCorruptDatabase() { |
1325 RecordFailure(FAILURE_DATABASE_CORRUPT_HANDLER); | 1348 RecordFailure(FAILURE_DATABASE_CORRUPT_HANDLER); |
1326 corruption_detected_ = true; // Stop updating the database. | 1349 corruption_detected_ = true; // Stop updating the database. |
1327 ResetDatabase(); | 1350 ResetDatabase(); |
1328 DCHECK(false) << "SafeBrowsing database was corrupt and reset"; | 1351 DLOG(FATAL) << "SafeBrowsing database was corrupt and reset"; |
1329 } | 1352 } |
1330 | 1353 |
1331 // TODO(shess): I'm not clear why this code doesn't have any | 1354 // TODO(shess): I'm not clear why this code doesn't have any |
1332 // real error-handling. | 1355 // real error-handling. |
1333 void SafeBrowsingDatabaseNew::LoadBloomFilter() { | 1356 void SafeBrowsingDatabaseNew::LoadBloomFilter() { |
1334 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 1357 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
1335 DCHECK(!bloom_filter_filename_.empty()); | 1358 DCHECK(!bloom_filter_filename_.empty()); |
1336 | 1359 |
1337 // If we're missing either of the database or filter files, we wait until the | 1360 // If we're missing either of the database or filter files, we wait until the |
1338 // next update to generate a new filter. | 1361 // next update to generate a new filter. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), | 1461 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), |
1439 kill_switch)) { | 1462 kill_switch)) { |
1440 // The kill switch is whitelisted hence we whitelist all URLs. | 1463 // The kill switch is whitelisted hence we whitelist all URLs. |
1441 WhitelistEverything(whitelist); | 1464 WhitelistEverything(whitelist); |
1442 } else { | 1465 } else { |
1443 base::AutoLock locked(lookup_lock_); | 1466 base::AutoLock locked(lookup_lock_); |
1444 whitelist->second = false; | 1467 whitelist->second = false; |
1445 whitelist->first.swap(new_whitelist); | 1468 whitelist->first.swap(new_whitelist); |
1446 } | 1469 } |
1447 } | 1470 } |
OLD | NEW |