Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "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/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 // that the resulting prefix set is valid, so that the | 262 // that the resulting prefix set is valid, so that the |
| 263 // PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT_INVALID histogram in | 263 // PREFIX_SET_EVENT_BLOOM_MISS_PREFIX_HIT_INVALID histogram in |
| 264 // ContainsBrowseUrl() can be trustworthy. | 264 // ContainsBrowseUrl() can be trustworthy. |
| 265 safe_browsing::PrefixSet* PrefixSetFromAddPrefixes( | 265 safe_browsing::PrefixSet* PrefixSetFromAddPrefixes( |
| 266 const std::vector<SBAddPrefix>& add_prefixes) { | 266 const std::vector<SBAddPrefix>& add_prefixes) { |
| 267 // TODO(shess): If |add_prefixes| were sorted by the prefix, it | 267 // TODO(shess): If |add_prefixes| were sorted by the prefix, it |
| 268 // could be passed directly to |PrefixSet()|, removing the need for | 268 // could be passed directly to |PrefixSet()|, removing the need for |
| 269 // |prefixes|. For now, |prefixes| is useful while debugging | 269 // |prefixes|. For now, |prefixes| is useful while debugging |
| 270 // things. | 270 // things. |
| 271 std::vector<SBPrefix> prefixes; | 271 std::vector<SBPrefix> prefixes; |
| 272 prefixes.reserve(add_prefixes.size()); | |
| 272 for (size_t i = 0; i < add_prefixes.size(); ++i) { | 273 for (size_t i = 0; i < add_prefixes.size(); ++i) { |
| 273 prefixes.push_back(add_prefixes[i].prefix); | 274 prefixes.push_back(add_prefixes[i].prefix); |
| 274 } | 275 } |
| 275 | 276 |
| 276 std::sort(prefixes.begin(), prefixes.end()); | 277 std::sort(prefixes.begin(), prefixes.end()); |
| 277 prefixes.erase(std::unique(prefixes.begin(), prefixes.end()), | 278 prefixes.erase(std::unique(prefixes.begin(), prefixes.end()), |
| 278 prefixes.end()); | 279 prefixes.end()); |
| 279 | 280 |
| 280 scoped_ptr<safe_browsing::PrefixSet> | 281 scoped_ptr<safe_browsing::PrefixSet> |
| 281 prefix_set(new safe_browsing::PrefixSet(prefixes)); | 282 prefix_set(new safe_browsing::PrefixSet(prefixes)); |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1178 } | 1179 } |
| 1179 | 1180 |
| 1180 #if defined(OS_MACOSX) | 1181 #if defined(OS_MACOSX) |
| 1181 base::mac::SetFileBackupExclusion(download_filename_); | 1182 base::mac::SetFileBackupExclusion(download_filename_); |
| 1182 #endif | 1183 #endif |
| 1183 } | 1184 } |
| 1184 | 1185 |
| 1185 void SafeBrowsingDatabaseNew::UpdateBrowseStore() { | 1186 void SafeBrowsingDatabaseNew::UpdateBrowseStore() { |
| 1186 // Copy out the pending add hashes. Copy rather than swapping in | 1187 // Copy out the pending add hashes. Copy rather than swapping in |
| 1187 // case |ContainsBrowseURL()| is called before the new filter is complete. | 1188 // case |ContainsBrowseURL()| is called before the new filter is complete. |
| 1188 std::vector<SBAddFullHash> pending_add_hashes; | 1189 std::vector<SBAddFullHash> pending_add_hashes; |
|
noelutz
2011/09/22 21:14:09
What about this vector? Were you thinking that th
Scott Hess - ex-Googler
2011/09/22 21:23:09
Yeah, I looked at that one and figured that since
| |
| 1189 { | 1190 { |
| 1190 base::AutoLock locked(lookup_lock_); | 1191 base::AutoLock locked(lookup_lock_); |
| 1191 pending_add_hashes.insert(pending_add_hashes.end(), | 1192 pending_add_hashes.insert(pending_add_hashes.end(), |
| 1192 pending_browse_hashes_.begin(), | 1193 pending_browse_hashes_.begin(), |
| 1193 pending_browse_hashes_.end()); | 1194 pending_browse_hashes_.end()); |
| 1194 } | 1195 } |
| 1195 | 1196 |
| 1196 // Measure the amount of IO during the bloom filter build. | 1197 // Measure the amount of IO during the bloom filter build. |
| 1197 base::IoCounters io_before, io_after; | 1198 base::IoCounters io_before, io_after; |
| 1198 base::ProcessHandle handle = base::Process::Current().handle(); | 1199 base::ProcessHandle handle = base::Process::Current().handle(); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1399 void SafeBrowsingDatabaseNew::LoadWhitelist( | 1400 void SafeBrowsingDatabaseNew::LoadWhitelist( |
| 1400 const std::vector<SBAddFullHash>& full_hashes, | 1401 const std::vector<SBAddFullHash>& full_hashes, |
| 1401 SBWhitelist* whitelist) { | 1402 SBWhitelist* whitelist) { |
| 1402 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 1403 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 1403 if (full_hashes.size() > kMaxWhitelistSize) { | 1404 if (full_hashes.size() > kMaxWhitelistSize) { |
| 1404 WhitelistEverything(whitelist); | 1405 WhitelistEverything(whitelist); |
| 1405 return; | 1406 return; |
| 1406 } | 1407 } |
| 1407 | 1408 |
| 1408 std::vector<SBFullHash> new_whitelist; | 1409 std::vector<SBFullHash> new_whitelist; |
| 1410 new_whitelist.reserve(full_hashes.size()); | |
| 1409 for (std::vector<SBAddFullHash>::const_iterator it = full_hashes.begin(); | 1411 for (std::vector<SBAddFullHash>::const_iterator it = full_hashes.begin(); |
| 1410 it != full_hashes.end(); ++it) { | 1412 it != full_hashes.end(); ++it) { |
| 1411 new_whitelist.push_back(it->full_hash); | 1413 new_whitelist.push_back(it->full_hash); |
| 1412 } | 1414 } |
| 1413 std::sort(new_whitelist.begin(), new_whitelist.end()); | 1415 std::sort(new_whitelist.begin(), new_whitelist.end()); |
| 1414 | 1416 |
| 1415 SBFullHash kill_switch; | 1417 SBFullHash kill_switch; |
| 1416 crypto::SHA256HashString(kWhitelistKillSwitchUrl, &kill_switch, | 1418 crypto::SHA256HashString(kWhitelistKillSwitchUrl, &kill_switch, |
| 1417 sizeof(kill_switch)); | 1419 sizeof(kill_switch)); |
| 1418 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), | 1420 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), |
| 1419 kill_switch)) { | 1421 kill_switch)) { |
| 1420 // The kill switch is whitelisted hence we whitelist all URLs. | 1422 // The kill switch is whitelisted hence we whitelist all URLs. |
| 1421 WhitelistEverything(whitelist); | 1423 WhitelistEverything(whitelist); |
| 1422 } else { | 1424 } else { |
| 1423 base::AutoLock locked(lookup_lock_); | 1425 base::AutoLock locked(lookup_lock_); |
| 1424 whitelist->second = false; | 1426 whitelist->second = false; |
| 1425 whitelist->first.swap(new_whitelist); | 1427 whitelist->first.swap(new_whitelist); |
| 1426 } | 1428 } |
| 1427 } | 1429 } |
| OLD | NEW |