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 <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 Loading... |
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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // The default SafeBrowsingDatabaseFactory. | 275 // The default SafeBrowsingDatabaseFactory. |
273 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { | 276 class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { |
274 public: | 277 public: |
275 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( | 278 SafeBrowsingDatabase* CreateSafeBrowsingDatabase( |
276 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 279 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
277 bool enable_download_protection, | 280 bool enable_download_protection, |
278 bool enable_client_side_whitelist, | 281 bool enable_client_side_whitelist, |
279 bool enable_download_whitelist, | 282 bool enable_download_whitelist, |
280 bool enable_extension_blacklist, | 283 bool enable_extension_blacklist, |
281 bool enable_ip_blacklist, | 284 bool enable_ip_blacklist, |
282 bool enable_unwanted_software_list) override { | 285 bool enable_unwanted_software_list, |
| 286 bool enable_resource_blacklist) override { |
283 return new SafeBrowsingDatabaseNew( | 287 return new SafeBrowsingDatabaseNew( |
284 db_task_runner, CreateStore(true, db_task_runner), // browse_store | 288 db_task_runner, CreateStore(true, db_task_runner), // browse_store |
285 CreateStore(enable_download_protection, db_task_runner), | 289 CreateStore(enable_download_protection, db_task_runner), |
286 CreateStore(enable_client_side_whitelist, db_task_runner), | 290 CreateStore(enable_client_side_whitelist, db_task_runner), |
287 CreateStore(enable_download_whitelist, db_task_runner), | 291 CreateStore(enable_download_whitelist, db_task_runner), |
288 CreateStore(true, db_task_runner), // inclusion_whitelist_store | 292 CreateStore(true, db_task_runner), // inclusion_whitelist_store |
289 CreateStore(enable_extension_blacklist, db_task_runner), | 293 CreateStore(enable_extension_blacklist, db_task_runner), |
290 CreateStore(enable_ip_blacklist, db_task_runner), | 294 CreateStore(enable_ip_blacklist, db_task_runner), |
291 CreateStore(enable_unwanted_software_list, db_task_runner)); | 295 CreateStore(enable_unwanted_software_list, db_task_runner), |
| 296 CreateStore(enable_resource_blacklist, db_task_runner)); |
292 } | 297 } |
293 | 298 |
294 SafeBrowsingDatabaseFactoryImpl() {} | 299 SafeBrowsingDatabaseFactoryImpl() {} |
295 | 300 |
296 private: | 301 private: |
297 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); | 302 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingDatabaseFactoryImpl); |
298 }; | 303 }; |
299 | 304 |
300 // static | 305 // static |
301 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; | 306 SafeBrowsingDatabaseFactory* SafeBrowsingDatabase::factory_ = NULL; |
302 | 307 |
303 // Factory method, should be called on the Safe Browsing sequenced task runner, | 308 // Factory method, should be called on the Safe Browsing sequenced task runner, |
304 // which is also passed to the function as |current_task_runner|. | 309 // which is also passed to the function as |current_task_runner|. |
305 // TODO(shess): There's no need for a factory any longer. Convert | 310 // TODO(shess): There's no need for a factory any longer. Convert |
306 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create() | 311 // SafeBrowsingDatabaseNew to SafeBrowsingDatabase, and have Create() |
307 // callers just construct things directly. | 312 // callers just construct things directly. |
308 SafeBrowsingDatabase* SafeBrowsingDatabase::Create( | 313 SafeBrowsingDatabase* SafeBrowsingDatabase::Create( |
309 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner, | 314 const scoped_refptr<base::SequencedTaskRunner>& current_task_runner, |
310 bool enable_download_protection, | 315 bool enable_download_protection, |
311 bool enable_client_side_whitelist, | 316 bool enable_client_side_whitelist, |
312 bool enable_download_whitelist, | 317 bool enable_download_whitelist, |
313 bool enable_extension_blacklist, | 318 bool enable_extension_blacklist, |
314 bool enable_ip_blacklist, | 319 bool enable_ip_blacklist, |
315 bool enable_unwanted_software_list) { | 320 bool enable_unwanted_software_list, |
| 321 bool enable_resource_blacklist) { |
316 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); | 322 DCHECK(current_task_runner->RunsTasksOnCurrentThread()); |
317 if (!factory_) | 323 if (!factory_) |
318 factory_ = new SafeBrowsingDatabaseFactoryImpl(); | 324 factory_ = new SafeBrowsingDatabaseFactoryImpl(); |
319 return factory_->CreateSafeBrowsingDatabase( | 325 return factory_->CreateSafeBrowsingDatabase( |
320 current_task_runner, enable_download_protection, | 326 current_task_runner, enable_download_protection, |
321 enable_client_side_whitelist, enable_download_whitelist, | 327 enable_client_side_whitelist, enable_download_whitelist, |
322 enable_extension_blacklist, enable_ip_blacklist, | 328 enable_extension_blacklist, enable_ip_blacklist, |
323 enable_unwanted_software_list); | 329 enable_unwanted_software_list, |
| 330 enable_resource_blacklist); |
324 } | 331 } |
325 | 332 |
326 SafeBrowsingDatabase::~SafeBrowsingDatabase() {} | 333 SafeBrowsingDatabase::~SafeBrowsingDatabase() {} |
327 | 334 |
328 // static | 335 // static |
329 base::FilePath SafeBrowsingDatabase::BrowseDBFilename( | 336 base::FilePath SafeBrowsingDatabase::BrowseDBFilename( |
330 const base::FilePath& db_base_filename) { | 337 const base::FilePath& db_base_filename) { |
331 return base::FilePath(db_base_filename.value() + kBrowseDBFile); | 338 return base::FilePath(db_base_filename.value() + kBrowseDBFile); |
332 } | 339 } |
333 | 340 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return base::FilePath(db_filename.value() + kIPBlacklistDBFile); | 392 return base::FilePath(db_filename.value() + kIPBlacklistDBFile); |
386 } | 393 } |
387 | 394 |
388 // static | 395 // static |
389 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename( | 396 base::FilePath SafeBrowsingDatabase::UnwantedSoftwareDBFilename( |
390 const base::FilePath& db_filename) { | 397 const base::FilePath& db_filename) { |
391 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); | 398 return base::FilePath(db_filename.value() + kUnwantedSoftwareDBFile); |
392 } | 399 } |
393 | 400 |
394 // static | 401 // static |
| 402 base::FilePath SafeBrowsingDatabase::ResourceBlacklistDBFilename( |
| 403 const base::FilePath& db_filename) { |
| 404 return base::FilePath(db_filename.value() + kResourceBlacklistDBFile); |
| 405 } |
| 406 |
| 407 // static |
395 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( | 408 void SafeBrowsingDatabase::GetDownloadUrlPrefixes( |
396 const std::vector<GURL>& urls, | 409 const std::vector<GURL>& urls, |
397 std::vector<SBPrefix>* prefixes) { | 410 std::vector<SBPrefix>* prefixes) { |
398 std::vector<SBFullHash> full_hashes; | 411 std::vector<SBFullHash> full_hashes; |
399 for (size_t i = 0; i < urls.size(); ++i) | 412 for (size_t i = 0; i < urls.size(); ++i) |
400 UrlToFullHashes(urls[i], false, &full_hashes); | 413 UrlToFullHashes(urls[i], false, &full_hashes); |
401 | 414 |
402 for (size_t i = 0; i < full_hashes.size(); ++i) | 415 for (size_t i = 0; i < full_hashes.size(); ++i) |
403 prefixes->push_back(full_hashes[i].prefix); | 416 prefixes->push_back(full_hashes[i].prefix); |
404 } | 417 } |
(...skipping 11 matching lines...) Expand all Loading... |
416 } else if (list_id == DOWNLOADWHITELIST) { | 429 } else if (list_id == DOWNLOADWHITELIST) { |
417 return download_whitelist_store_.get(); | 430 return download_whitelist_store_.get(); |
418 } else if (list_id == INCLUSIONWHITELIST) { | 431 } else if (list_id == INCLUSIONWHITELIST) { |
419 return inclusion_whitelist_store_.get(); | 432 return inclusion_whitelist_store_.get(); |
420 } else if (list_id == EXTENSIONBLACKLIST) { | 433 } else if (list_id == EXTENSIONBLACKLIST) { |
421 return extension_blacklist_store_.get(); | 434 return extension_blacklist_store_.get(); |
422 } else if (list_id == IPBLACKLIST) { | 435 } else if (list_id == IPBLACKLIST) { |
423 return ip_blacklist_store_.get(); | 436 return ip_blacklist_store_.get(); |
424 } else if (list_id == UNWANTEDURL) { | 437 } else if (list_id == UNWANTEDURL) { |
425 return unwanted_software_store_.get(); | 438 return unwanted_software_store_.get(); |
| 439 } else if (list_id == RESOURCEBLACKLIST) { |
| 440 return resource_blacklist_store_.get(); |
426 } | 441 } |
427 return NULL; | 442 return NULL; |
428 } | 443 } |
429 | 444 |
430 // static | 445 // static |
431 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { | 446 void SafeBrowsingDatabase::RecordFailure(FailureType failure_type) { |
432 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, | 447 UMA_HISTOGRAM_ENUMERATION("SB2.DatabaseFailure", failure_type, |
433 FAILURE_DATABASE_MAX); | 448 FAILURE_DATABASE_MAX); |
434 } | 449 } |
435 | 450 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 613 |
599 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( | 614 SafeBrowsingDatabaseNew::SafeBrowsingDatabaseNew( |
600 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 615 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
601 SafeBrowsingStore* browse_store, | 616 SafeBrowsingStore* browse_store, |
602 SafeBrowsingStore* download_store, | 617 SafeBrowsingStore* download_store, |
603 SafeBrowsingStore* csd_whitelist_store, | 618 SafeBrowsingStore* csd_whitelist_store, |
604 SafeBrowsingStore* download_whitelist_store, | 619 SafeBrowsingStore* download_whitelist_store, |
605 SafeBrowsingStore* inclusion_whitelist_store, | 620 SafeBrowsingStore* inclusion_whitelist_store, |
606 SafeBrowsingStore* extension_blacklist_store, | 621 SafeBrowsingStore* extension_blacklist_store, |
607 SafeBrowsingStore* ip_blacklist_store, | 622 SafeBrowsingStore* ip_blacklist_store, |
608 SafeBrowsingStore* unwanted_software_store) | 623 SafeBrowsingStore* unwanted_software_store, |
| 624 SafeBrowsingStore* resource_blacklist_store) |
609 : db_task_runner_(db_task_runner), | 625 : db_task_runner_(db_task_runner), |
610 state_manager_(db_task_runner_), | 626 state_manager_(db_task_runner_), |
611 db_state_manager_(db_task_runner_), | 627 db_state_manager_(db_task_runner_), |
612 browse_store_(browse_store), | 628 browse_store_(browse_store), |
613 download_store_(download_store), | 629 download_store_(download_store), |
614 csd_whitelist_store_(csd_whitelist_store), | 630 csd_whitelist_store_(csd_whitelist_store), |
615 download_whitelist_store_(download_whitelist_store), | 631 download_whitelist_store_(download_whitelist_store), |
616 inclusion_whitelist_store_(inclusion_whitelist_store), | 632 inclusion_whitelist_store_(inclusion_whitelist_store), |
617 extension_blacklist_store_(extension_blacklist_store), | 633 extension_blacklist_store_(extension_blacklist_store), |
618 ip_blacklist_store_(ip_blacklist_store), | 634 ip_blacklist_store_(ip_blacklist_store), |
619 unwanted_software_store_(unwanted_software_store), | 635 unwanted_software_store_(unwanted_software_store), |
| 636 resource_blacklist_store_(resource_blacklist_store), |
620 reset_factory_(this) { | 637 reset_factory_(this) { |
621 DCHECK(browse_store_.get()); | 638 DCHECK(browse_store_.get()); |
622 } | 639 } |
623 | 640 |
624 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { | 641 SafeBrowsingDatabaseNew::~SafeBrowsingDatabaseNew() { |
625 // The DCHECK is disabled due to crbug.com/338486 . | 642 // The DCHECK is disabled due to crbug.com/338486 . |
626 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 643 // DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
627 } | 644 } |
628 | 645 |
629 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { | 646 void SafeBrowsingDatabaseNew::Init(const base::FilePath& filename_base) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, | 773 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
757 base::Unretained(this))); | 774 base::Unretained(this))); |
758 | 775 |
759 std::vector<SBAddFullHash> full_hashes; | 776 std::vector<SBAddFullHash> full_hashes; |
760 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) { | 777 if (ip_blacklist_store_->GetAddFullHashes(&full_hashes)) { |
761 LoadIpBlacklist(full_hashes); | 778 LoadIpBlacklist(full_hashes); |
762 } else { | 779 } else { |
763 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. | 780 LoadIpBlacklist(std::vector<SBAddFullHash>()); // Clear the list. |
764 } | 781 } |
765 } | 782 } |
| 783 |
| 784 if (resource_blacklist_store_.get()) { |
| 785 resource_blacklist_store_->Init( |
| 786 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), |
| 787 base::Bind(&SafeBrowsingDatabaseNew::HandleCorruptDatabase, |
| 788 base::Unretained(this))); |
| 789 } |
766 } | 790 } |
767 | 791 |
768 bool SafeBrowsingDatabaseNew::ResetDatabase() { | 792 bool SafeBrowsingDatabaseNew::ResetDatabase() { |
769 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 793 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
770 | 794 |
771 // Delete files on disk. | 795 // Delete files on disk. |
772 // TODO(shess): Hard to see where one might want to delete without a | 796 // TODO(shess): Hard to see where one might want to delete without a |
773 // reset. Perhaps inline |Delete()|? | 797 // reset. Perhaps inline |Delete()|? |
774 if (!Delete()) | 798 if (!Delete()) |
775 return false; | 799 return false; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 << " mask:" << base::HexEncode(mask.data(), mask.size()) | 962 << " mask:" << base::HexEncode(mask.data(), mask.size()) |
939 << " subnet:" << base::HexEncode(subnet.data(), subnet.size()) | 963 << " subnet:" << base::HexEncode(subnet.data(), subnet.size()) |
940 << " hash:" << base::HexEncode(hash.data(), hash.size()); | 964 << " hash:" << base::HexEncode(hash.data(), hash.size()); |
941 if (it->second.count(hash) > 0) { | 965 if (it->second.count(hash) > 0) { |
942 return true; | 966 return true; |
943 } | 967 } |
944 } | 968 } |
945 return false; | 969 return false; |
946 } | 970 } |
947 | 971 |
| 972 bool SafeBrowsingDatabaseNew::ContainsResourceUrlPrefixes( |
| 973 const std::vector<SBPrefix>& prefixes, |
| 974 std::vector<SBPrefix>* prefix_hits) { |
| 975 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| 976 |
| 977 if (!resource_blacklist_store_) |
| 978 return false; |
| 979 |
| 980 return MatchAddPrefixes(resource_blacklist_store_.get(), |
| 981 RESOURCEBLACKLIST % 2, prefixes, prefix_hits); |
| 982 } |
| 983 |
948 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( | 984 bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( |
949 const std::string& str) { | 985 const std::string& str) { |
950 std::vector<SBFullHash> hashes; | 986 std::vector<SBFullHash> hashes; |
951 hashes.push_back(SBFullHashForString(str)); | 987 hashes.push_back(SBFullHashForString(str)); |
952 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes); | 988 return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes); |
953 } | 989 } |
954 | 990 |
955 bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes( | 991 bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes( |
956 SBWhitelistId whitelist_id, | 992 SBWhitelistId whitelist_id, |
957 const std::vector<SBFullHash>& hashes) { | 993 const std::vector<SBFullHash>& hashes) { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 HandleCorruptDatabase(); | 1204 HandleCorruptDatabase(); |
1169 return false; | 1205 return false; |
1170 } | 1206 } |
1171 | 1207 |
1172 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) { | 1208 if (unwanted_software_store_ && !unwanted_software_store_->BeginUpdate()) { |
1173 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN); | 1209 RecordFailure(FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_BEGIN); |
1174 HandleCorruptDatabase(); | 1210 HandleCorruptDatabase(); |
1175 return false; | 1211 return false; |
1176 } | 1212 } |
1177 | 1213 |
| 1214 if (resource_blacklist_store_ && !resource_blacklist_store_->BeginUpdate()) { |
| 1215 RecordFailure(FAILURE_RESOURCE_BLACKLIST_UPDATE_BEGIN); |
| 1216 HandleCorruptDatabase(); |
| 1217 return false; |
| 1218 } |
| 1219 |
1178 // Cached fullhash results must be cleared on every database update (whether | 1220 // Cached fullhash results must be cleared on every database update (whether |
1179 // successful or not). | 1221 // successful or not). |
1180 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); | 1222 state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); |
1181 | 1223 |
1182 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, | 1224 UpdateChunkRangesForLists(browse_store_.get(), kMalwareList, kPhishingList, |
1183 lists); | 1225 lists); |
1184 | 1226 |
1185 // NOTE(shess): |download_store_| used to contain kBinHashList, which has been | 1227 // 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 | 1228 // 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 | 1229 // of Feb 2014, so it has been removed. Everything _should_ be resilient to |
1188 // extra data of that sort. | 1230 // extra data of that sort. |
1189 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); | 1231 UpdateChunkRangesForList(download_store_.get(), kBinUrlList, lists); |
1190 | 1232 |
1191 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); | 1233 UpdateChunkRangesForList(csd_whitelist_store_.get(), kCsdWhiteList, lists); |
1192 | 1234 |
1193 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, | 1235 UpdateChunkRangesForList(download_whitelist_store_.get(), kDownloadWhiteList, |
1194 lists); | 1236 lists); |
1195 | 1237 |
1196 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), | 1238 UpdateChunkRangesForList(inclusion_whitelist_store_.get(), |
1197 kInclusionWhitelist, lists); | 1239 kInclusionWhitelist, lists); |
1198 | 1240 |
1199 UpdateChunkRangesForList(extension_blacklist_store_.get(), | 1241 UpdateChunkRangesForList(extension_blacklist_store_.get(), |
1200 kExtensionBlacklist, lists); | 1242 kExtensionBlacklist, lists); |
1201 | 1243 |
1202 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); | 1244 UpdateChunkRangesForList(ip_blacklist_store_.get(), kIPBlacklist, lists); |
1203 | 1245 |
1204 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, | 1246 UpdateChunkRangesForList(unwanted_software_store_.get(), kUnwantedUrlList, |
1205 lists); | 1247 lists); |
1206 | 1248 |
| 1249 UpdateChunkRangesForList(resource_blacklist_store_.get(), kResourceBlacklist, |
| 1250 lists); |
| 1251 |
1207 db_state_manager_.reset_corruption_detected(); | 1252 db_state_manager_.reset_corruption_detected(); |
1208 db_state_manager_.reset_change_detected(); | 1253 db_state_manager_.reset_change_detected(); |
1209 return true; | 1254 return true; |
1210 } | 1255 } |
1211 | 1256 |
1212 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { | 1257 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
1213 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1258 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
1214 | 1259 |
1215 // The update may have failed due to corrupt storage (for instance, | 1260 // The update may have failed due to corrupt storage (for instance, |
1216 // an excessive number of invalid add_chunks and sub_chunks). | 1261 // an excessive number of invalid add_chunks and sub_chunks). |
(...skipping 27 matching lines...) Expand all Loading... |
1244 } | 1289 } |
1245 | 1290 |
1246 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { | 1291 if (ip_blacklist_store_ && !ip_blacklist_store_->CheckValidity()) { |
1247 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; | 1292 DLOG(ERROR) << "Safe-browsing IP blacklist database corrupt."; |
1248 } | 1293 } |
1249 | 1294 |
1250 if (unwanted_software_store_ && | 1295 if (unwanted_software_store_ && |
1251 !unwanted_software_store_->CheckValidity()) { | 1296 !unwanted_software_store_->CheckValidity()) { |
1252 DLOG(ERROR) << "Unwanted software url list database corrupt."; | 1297 DLOG(ERROR) << "Unwanted software url list database corrupt."; |
1253 } | 1298 } |
| 1299 |
| 1300 if (resource_blacklist_store_ && |
| 1301 !resource_blacklist_store_->CheckValidity()) { |
| 1302 DLOG(ERROR) << "Resources blacklist url list database corrupt."; |
| 1303 } |
1254 } | 1304 } |
1255 | 1305 |
1256 if (db_state_manager_.corruption_detected()) | 1306 if (db_state_manager_.corruption_detected()) |
1257 return; | 1307 return; |
1258 | 1308 |
1259 // Unroll the transaction if there was a protocol error or if the | 1309 // Unroll the transaction if there was a protocol error or if the |
1260 // transaction was empty. This will leave the prefix set, the | 1310 // transaction was empty. This will leave the prefix set, the |
1261 // pending hashes, and the prefix miss cache in place. | 1311 // pending hashes, and the prefix miss cache in place. |
1262 if (!update_succeeded || !db_state_manager_.change_detected()) { | 1312 if (!update_succeeded || !db_state_manager_.change_detected()) { |
1263 // Track empty updates to answer questions at http://crbug.com/72216 . | 1313 // Track empty updates to answer questions at http://crbug.com/72216 . |
1264 if (update_succeeded && !db_state_manager_.change_detected()) | 1314 if (update_succeeded && !db_state_manager_.change_detected()) |
1265 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 1315 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
1266 browse_store_->CancelUpdate(); | 1316 browse_store_->CancelUpdate(); |
1267 if (download_store_.get()) | 1317 if (download_store_.get()) |
1268 download_store_->CancelUpdate(); | 1318 download_store_->CancelUpdate(); |
1269 if (csd_whitelist_store_.get()) | 1319 if (csd_whitelist_store_.get()) |
1270 csd_whitelist_store_->CancelUpdate(); | 1320 csd_whitelist_store_->CancelUpdate(); |
1271 if (download_whitelist_store_.get()) | 1321 if (download_whitelist_store_.get()) |
1272 download_whitelist_store_->CancelUpdate(); | 1322 download_whitelist_store_->CancelUpdate(); |
1273 if (inclusion_whitelist_store_.get()) | 1323 if (inclusion_whitelist_store_.get()) |
1274 inclusion_whitelist_store_->CancelUpdate(); | 1324 inclusion_whitelist_store_->CancelUpdate(); |
1275 if (extension_blacklist_store_) | 1325 if (extension_blacklist_store_) |
1276 extension_blacklist_store_->CancelUpdate(); | 1326 extension_blacklist_store_->CancelUpdate(); |
1277 if (ip_blacklist_store_) | 1327 if (ip_blacklist_store_) |
1278 ip_blacklist_store_->CancelUpdate(); | 1328 ip_blacklist_store_->CancelUpdate(); |
1279 if (unwanted_software_store_) | 1329 if (unwanted_software_store_) |
1280 unwanted_software_store_->CancelUpdate(); | 1330 unwanted_software_store_->CancelUpdate(); |
| 1331 if (resource_blacklist_store_) |
| 1332 resource_blacklist_store_->CancelUpdate(); |
1281 return; | 1333 return; |
1282 } | 1334 } |
1283 | 1335 |
1284 if (download_store_) { | 1336 if (download_store_) { |
1285 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), | 1337 UpdateHashPrefixStore(DownloadDBFilename(db_state_manager_.filename_base()), |
1286 download_store_.get(), | 1338 download_store_.get(), |
1287 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); | 1339 FAILURE_DOWNLOAD_DATABASE_UPDATE_FINISH); |
1288 } | 1340 } |
1289 | 1341 |
1290 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), | 1342 UpdatePrefixSetUrlStore(BrowseDBFilename(db_state_manager_.filename_base()), |
(...skipping 21 matching lines...) Expand all Loading... |
1312 if (ip_blacklist_store_) | 1364 if (ip_blacklist_store_) |
1313 UpdateIpBlacklistStore(); | 1365 UpdateIpBlacklistStore(); |
1314 | 1366 |
1315 if (unwanted_software_store_) { | 1367 if (unwanted_software_store_) { |
1316 UpdatePrefixSetUrlStore( | 1368 UpdatePrefixSetUrlStore( |
1317 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), | 1369 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), |
1318 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, | 1370 unwanted_software_store_.get(), PrefixSetId::UNWANTED_SOFTWARE, |
1319 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, | 1371 FAILURE_UNWANTED_SOFTWARE_DATABASE_UPDATE_FINISH, |
1320 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); | 1372 FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_WRITE, true); |
1321 } | 1373 } |
| 1374 |
| 1375 if (resource_blacklist_store_) { |
| 1376 UpdateHashPrefixStore( |
| 1377 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), |
| 1378 resource_blacklist_store_.get(), |
| 1379 FAILURE_RESOURCE_BLACKLIST_UPDATE_FINISH); |
| 1380 } |
1322 } | 1381 } |
1323 | 1382 |
1324 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( | 1383 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( |
1325 const base::FilePath& store_filename, | 1384 const base::FilePath& store_filename, |
1326 SafeBrowsingStore* store, | 1385 SafeBrowsingStore* store, |
1327 SBWhitelistId whitelist_id) { | 1386 SBWhitelistId whitelist_id) { |
1328 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1387 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
1329 | 1388 |
1330 if (!store) | 1389 if (!store) |
1331 return; | 1390 return; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 const bool r9 = base::DeleteFile( | 1654 const bool r9 = base::DeleteFile( |
1596 IpBlacklistDBFilename(db_state_manager_.filename_base()), false); | 1655 IpBlacklistDBFilename(db_state_manager_.filename_base()), false); |
1597 if (!r9) | 1656 if (!r9) |
1598 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); | 1657 RecordFailure(FAILURE_IP_BLACKLIST_DELETE); |
1599 | 1658 |
1600 const bool r10 = base::DeleteFile( | 1659 const bool r10 = base::DeleteFile( |
1601 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false); | 1660 UnwantedSoftwareDBFilename(db_state_manager_.filename_base()), false); |
1602 if (!r10) | 1661 if (!r10) |
1603 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); | 1662 RecordFailure(FAILURE_UNWANTED_SOFTWARE_PREFIX_SET_DELETE); |
1604 | 1663 |
1605 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10; | 1664 const bool r11 = base::DeleteFile( |
| 1665 ResourceBlacklistDBFilename(db_state_manager_.filename_base()), false); |
| 1666 if (!r11) |
| 1667 RecordFailure(FAILURE_RESOURCE_BLACKLIST_DELETE); |
| 1668 |
| 1669 return r1 && r2 && r3 && r4 && r5 && r6 && r7 && r8 && r9 && r10 && r11; |
1606 } | 1670 } |
1607 | 1671 |
1608 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, | 1672 void SafeBrowsingDatabaseNew::WritePrefixSet(const base::FilePath& db_filename, |
1609 PrefixSetId prefix_set_id, | 1673 PrefixSetId prefix_set_id, |
1610 FailureType write_failure_type) { | 1674 FailureType write_failure_type) { |
1611 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); | 1675 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
1612 | 1676 |
1613 // Do not grab the lock to avoid contention while writing to disk. This is | 1677 // 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 | 1678 // safe as only this task runner can ever modify |state_manager_|'s prefix |
1615 // sets anyways. | 1679 // sets anyways. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 histogram_name.append(".InclusionWhitelist"); | 1825 histogram_name.append(".InclusionWhitelist"); |
1762 else if (base::EndsWith(filename, kExtensionBlacklistDBFile, | 1826 else if (base::EndsWith(filename, kExtensionBlacklistDBFile, |
1763 base::CompareCase::SENSITIVE)) | 1827 base::CompareCase::SENSITIVE)) |
1764 histogram_name.append(".ExtensionBlacklist"); | 1828 histogram_name.append(".ExtensionBlacklist"); |
1765 else if (base::EndsWith(filename, kIPBlacklistDBFile, | 1829 else if (base::EndsWith(filename, kIPBlacklistDBFile, |
1766 base::CompareCase::SENSITIVE)) | 1830 base::CompareCase::SENSITIVE)) |
1767 histogram_name.append(".IPBlacklist"); | 1831 histogram_name.append(".IPBlacklist"); |
1768 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, | 1832 else if (base::EndsWith(filename, kUnwantedSoftwareDBFile, |
1769 base::CompareCase::SENSITIVE)) | 1833 base::CompareCase::SENSITIVE)) |
1770 histogram_name.append(".UnwantedSoftware"); | 1834 histogram_name.append(".UnwantedSoftware"); |
| 1835 else if (base::EndsWith(filename, kResourceBlacklistDBFile, |
| 1836 base::CompareCase::SENSITIVE)) |
| 1837 histogram_name.append(".ResourceBlacklist"); |
1771 else | 1838 else |
1772 NOTREACHED(); // Add support for new lists above. | 1839 NOTREACHED(); // Add support for new lists above. |
1773 | 1840 |
1774 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. | 1841 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. |
1775 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( | 1842 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( |
1776 histogram_name, 1, 1000000, 50, | 1843 histogram_name, 1, 1000000, 50, |
1777 base::HistogramBase::kUmaTargetedHistogramFlag); | 1844 base::HistogramBase::kUmaTargetedHistogramFlag); |
1778 | 1845 |
1779 histogram_pointer->Add(file_size_kilobytes); | 1846 histogram_pointer->Add(file_size_kilobytes); |
1780 } | 1847 } |
1781 | 1848 |
1782 } // namespace safe_browsing | 1849 } // namespace safe_browsing |
OLD | NEW |