Chromium Code Reviews| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 void GetDownloadUrlPrefixes(const std::vector<GURL>& urls, | 127 void GetDownloadUrlPrefixes(const std::vector<GURL>& urls, |
| 128 std::vector<SBPrefix>* prefixes) { | 128 std::vector<SBPrefix>* prefixes) { |
| 129 std::vector<SBFullHash> full_hashes; | 129 std::vector<SBFullHash> full_hashes; |
| 130 for (size_t i = 0; i < urls.size(); ++i) | 130 for (size_t i = 0; i < urls.size(); ++i) |
| 131 BrowseFullHashesToCheck(urls[i], false, &full_hashes); | 131 BrowseFullHashesToCheck(urls[i], false, &full_hashes); |
| 132 | 132 |
| 133 for (size_t i = 0; i < full_hashes.size(); ++i) | 133 for (size_t i = 0; i < full_hashes.size(); ++i) |
| 134 prefixes->push_back(full_hashes[i].prefix); | 134 prefixes->push_back(full_hashes[i].prefix); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Helper function to compare addprefixes in |store| with |prefixes|. | |
| 138 // The |list_bit| indicates which list (url or hash) to compare. | |
| 139 // | |
| 140 // Returns true if there is a match, |*prefix_hits| (if non-NULL) will contain | |
| 141 // the actual matching prefixes. | |
| 142 bool MatchAddPrefixes(SafeBrowsingStore* store, | |
| 143 int list_bit, | |
| 144 const std::vector<SBPrefix>& prefixes, | |
| 145 std::vector<SBPrefix>* prefix_hits) { | |
| 146 if (prefix_hits) | |
| 147 prefix_hits->clear(); | |
|
Scott Hess - ex-Googler
2013/01/11 23:44:05
I don't think having to test prefix_hits and havin
not at google - send to devlin
2013/01/14 23:00:55
Done.
| |
| 148 bool found_match = false; | |
| 149 | |
| 150 SBAddPrefixes add_prefixes; | |
| 151 store->GetAddPrefixes(&add_prefixes); | |
| 152 for (SBAddPrefixes::const_iterator iter = add_prefixes.begin(); | |
| 153 iter != add_prefixes.end(); ++iter) { | |
| 154 for (size_t j = 0; j < prefixes.size(); ++j) { | |
| 155 const SBPrefix& prefix = prefixes[j]; | |
| 156 if (prefix == iter->prefix && | |
| 157 GetListIdBit(iter->chunk_id) == list_bit) { | |
| 158 if (prefix_hits) | |
| 159 prefix_hits->push_back(prefix); | |
| 160 found_match = true; | |
| 161 } | |
| 162 } | |
| 163 } | |
| 164 return found_match; | |
| 165 } | |
| 166 | |
| 137 // Find the entries in |full_hashes| with prefix in |prefix_hits|, and | 167 // Find the entries in |full_hashes| with prefix in |prefix_hits|, and |
| 138 // add them to |full_hits| if not expired. "Not expired" is when | 168 // add them to |full_hits| if not expired. "Not expired" is when |
| 139 // either |last_update| was recent enough, or the item has been | 169 // either |last_update| was recent enough, or the item has been |
| 140 // received recently enough. Expired items are not deleted because a | 170 // received recently enough. Expired items are not deleted because a |
| 141 // future update may make them acceptable again. | 171 // future update may make them acceptable again. |
| 142 // | 172 // |
| 143 // For efficiency reasons the code walks |prefix_hits| and | 173 // For efficiency reasons the code walks |prefix_hits| and |
| 144 // |full_hashes| in parallel, so they must be sorted by prefix. | 174 // |full_hashes| in parallel, so they must be sorted by prefix. |
| 145 void GetCachedFullHashesForBrowse(const std::vector<SBPrefix>& prefix_hits, | 175 void GetCachedFullHashesForBrowse(const std::vector<SBPrefix>& prefix_hits, |
| 146 const std::vector<SBAddFullHash>& full_hashes, | 176 const std::vector<SBAddFullHash>& full_hashes, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 157 ++piter; | 187 ++piter; |
| 158 } else if (hiter->full_hash.prefix < *piter) { | 188 } else if (hiter->full_hash.prefix < *piter) { |
| 159 ++hiter; | 189 ++hiter; |
| 160 } else { | 190 } else { |
| 161 if (expire_time < last_update || | 191 if (expire_time < last_update || |
| 162 expire_time.ToTimeT() < hiter->received) { | 192 expire_time.ToTimeT() < hiter->received) { |
| 163 SBFullHashResult result; | 193 SBFullHashResult result; |
| 164 const int list_bit = GetListIdBit(hiter->chunk_id); | 194 const int list_bit = GetListIdBit(hiter->chunk_id); |
| 165 DCHECK(list_bit == safe_browsing_util::MALWARE || | 195 DCHECK(list_bit == safe_browsing_util::MALWARE || |
| 166 list_bit == safe_browsing_util::PHISH); | 196 list_bit == safe_browsing_util::PHISH); |
| 167 if (!safe_browsing_util::GetListName(list_bit, &result.list_name)) | 197 const safe_browsing_util::ListType list_id = |
| 198 static_cast<safe_browsing_util::ListType>(list_bit); | |
| 199 if (!safe_browsing_util::GetListName(list_id, &result.list_name)) | |
| 168 continue; | 200 continue; |
| 169 result.add_chunk_id = DecodeChunkId(hiter->chunk_id); | 201 result.add_chunk_id = DecodeChunkId(hiter->chunk_id); |
| 170 result.hash = hiter->full_hash; | 202 result.hash = hiter->full_hash; |
| 171 full_hits->push_back(result); | 203 full_hits->push_back(result); |
| 172 } | 204 } |
| 173 | 205 |
| 174 // Only increment |hiter|, |piter| might have multiple hits. | 206 // Only increment |hiter|, |piter| might have multiple hits. |
| 175 ++hiter; | 207 ++hiter; |
| 176 } | 208 } |
| 177 } | 209 } |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 // updates. | 580 // updates. |
| 549 std::sort(prefix_hits->begin(), prefix_hits->end()); | 581 std::sort(prefix_hits->begin(), prefix_hits->end()); |
| 550 | 582 |
| 551 GetCachedFullHashesForBrowse(*prefix_hits, full_browse_hashes_, | 583 GetCachedFullHashesForBrowse(*prefix_hits, full_browse_hashes_, |
| 552 full_hits, last_update); | 584 full_hits, last_update); |
| 553 GetCachedFullHashesForBrowse(*prefix_hits, pending_browse_hashes_, | 585 GetCachedFullHashesForBrowse(*prefix_hits, pending_browse_hashes_, |
| 554 full_hits, last_update); | 586 full_hits, last_update); |
| 555 return true; | 587 return true; |
| 556 } | 588 } |
| 557 | 589 |
| 558 bool SafeBrowsingDatabaseNew::MatchDownloadAddPrefixes( | |
| 559 int list_bit, | |
| 560 const std::vector<SBPrefix>& prefixes, | |
| 561 std::vector<SBPrefix>* prefix_hits) { | |
| 562 prefix_hits->clear(); | |
| 563 | |
| 564 SBAddPrefixes add_prefixes; | |
| 565 download_store_->GetAddPrefixes(&add_prefixes); | |
| 566 for (SBAddPrefixes::const_iterator iter = add_prefixes.begin(); | |
| 567 iter != add_prefixes.end(); ++iter) { | |
| 568 for (size_t j = 0; j < prefixes.size(); ++j) { | |
| 569 const SBPrefix& prefix = prefixes[j]; | |
| 570 if (prefix == iter->prefix && | |
| 571 GetListIdBit(iter->chunk_id) == list_bit) { | |
| 572 prefix_hits->push_back(prefix); | |
| 573 } | |
| 574 } | |
| 575 } | |
| 576 return !prefix_hits->empty(); | |
| 577 } | |
| 578 | |
| 579 bool SafeBrowsingDatabaseNew::ContainsDownloadUrl( | 590 bool SafeBrowsingDatabaseNew::ContainsDownloadUrl( |
| 580 const std::vector<GURL>& urls, | 591 const std::vector<GURL>& urls, |
| 581 std::vector<SBPrefix>* prefix_hits) { | 592 std::vector<SBPrefix>* prefix_hits) { |
| 582 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 593 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 583 | 594 |
| 584 // Ignore this check when download checking is not enabled. | 595 // Ignore this check when download checking is not enabled. |
| 585 if (!download_store_.get()) | 596 if (!download_store_.get()) |
| 586 return false; | 597 return false; |
| 587 | 598 |
| 588 std::vector<SBPrefix> prefixes; | 599 std::vector<SBPrefix> prefixes; |
| 589 GetDownloadUrlPrefixes(urls, &prefixes); | 600 GetDownloadUrlPrefixes(urls, &prefixes); |
| 590 return MatchDownloadAddPrefixes(safe_browsing_util::BINURL % 2, | 601 return MatchAddPrefixes(download_store_.get(), |
| 591 prefixes, | 602 safe_browsing_util::BINURL % 2, |
| 592 prefix_hits); | 603 prefixes, |
| 604 prefix_hits); | |
| 593 } | 605 } |
| 594 | 606 |
| 595 bool SafeBrowsingDatabaseNew::ContainsDownloadHashPrefix( | 607 bool SafeBrowsingDatabaseNew::ContainsDownloadHashPrefix( |
| 596 const SBPrefix& prefix) { | 608 const SBPrefix& prefix) { |
| 597 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 609 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 598 | 610 |
| 599 // Ignore this check when download store is not available. | 611 // Ignore this check when download store is not available. |
| 600 if (!download_store_.get()) | 612 if (!download_store_.get()) |
| 601 return false; | 613 return false; |
| 602 | 614 |
| 603 std::vector<SBPrefix> prefixes(1, prefix); | 615 return MatchAddPrefixes(download_store_.get(), |
| 604 std::vector<SBPrefix> prefix_hits; | 616 safe_browsing_util::BINHASH % 2, |
| 605 return MatchDownloadAddPrefixes(safe_browsing_util::BINHASH % 2, | 617 std::vector<SBPrefix>(1, prefix), |
| 606 prefixes, | 618 NULL); |
| 607 &prefix_hits); | |
| 608 } | 619 } |
| 609 | 620 |
| 610 bool SafeBrowsingDatabaseNew::ContainsCsdWhitelistedUrl(const GURL& url) { | 621 bool SafeBrowsingDatabaseNew::ContainsCsdWhitelistedUrl(const GURL& url) { |
| 611 // This method is theoretically thread-safe but we expect all calls to | 622 // This method is theoretically thread-safe but we expect all calls to |
| 612 // originate from the IO thread. | 623 // originate from the IO thread. |
| 613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 614 std::vector<SBFullHash> full_hashes; | 625 std::vector<SBFullHash> full_hashes; |
| 615 BrowseFullHashesToCheck(url, true, &full_hashes); | 626 BrowseFullHashesToCheck(url, true, &full_hashes); |
| 616 return ContainsWhitelistedHashes(csd_whitelist_, full_hashes); | 627 return ContainsWhitelistedHashes(csd_whitelist_, full_hashes); |
| 617 } | 628 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 store->WriteAddPrefix(encoded_chunk_id, prefix); | 692 store->WriteAddPrefix(encoded_chunk_id, prefix); |
| 682 | 693 |
| 683 STATS_COUNTER("SB.PrefixAddFull", 1); | 694 STATS_COUNTER("SB.PrefixAddFull", 1); |
| 684 store->WriteAddHash(encoded_chunk_id, receive_time, full_hash); | 695 store->WriteAddHash(encoded_chunk_id, receive_time, full_hash); |
| 685 } | 696 } |
| 686 } | 697 } |
| 687 } | 698 } |
| 688 | 699 |
| 689 // Helper to iterate over all the entries in the hosts in |chunks| and | 700 // Helper to iterate over all the entries in the hosts in |chunks| and |
| 690 // add them to the store. | 701 // add them to the store. |
| 691 void SafeBrowsingDatabaseNew::InsertAddChunks(const int list_id, | 702 void SafeBrowsingDatabaseNew::InsertAddChunks( |
| 692 const SBChunkList& chunks) { | 703 const safe_browsing_util::ListType list_id, |
| 704 const SBChunkList& chunks) { | |
| 693 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 705 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 694 | 706 |
| 695 SafeBrowsingStore* store = GetStore(list_id); | 707 SafeBrowsingStore* store = GetStore(list_id); |
| 696 if (!store) return; | 708 if (!store) return; |
| 697 | 709 |
| 698 for (SBChunkList::const_iterator citer = chunks.begin(); | 710 for (SBChunkList::const_iterator citer = chunks.begin(); |
| 699 citer != chunks.end(); ++citer) { | 711 citer != chunks.end(); ++citer) { |
| 700 const int chunk_id = citer->chunk_number; | 712 const int chunk_id = citer->chunk_number; |
| 701 | 713 |
| 702 // The server can give us a chunk that we already have because | 714 // The server can give us a chunk that we already have because |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 store->WriteSubPrefix(encoded_chunk_id, add_chunk_id, full_hash.prefix); | 767 store->WriteSubPrefix(encoded_chunk_id, add_chunk_id, full_hash.prefix); |
| 756 | 768 |
| 757 STATS_COUNTER("SB.PrefixSubFull", 1); | 769 STATS_COUNTER("SB.PrefixSubFull", 1); |
| 758 store->WriteSubHash(encoded_chunk_id, add_chunk_id, full_hash); | 770 store->WriteSubHash(encoded_chunk_id, add_chunk_id, full_hash); |
| 759 } | 771 } |
| 760 } | 772 } |
| 761 } | 773 } |
| 762 | 774 |
| 763 // Helper to iterate over all the entries in the hosts in |chunks| and | 775 // Helper to iterate over all the entries in the hosts in |chunks| and |
| 764 // add them to the store. | 776 // add them to the store. |
| 765 void SafeBrowsingDatabaseNew::InsertSubChunks(int list_id, | 777 void SafeBrowsingDatabaseNew::InsertSubChunks( |
| 766 const SBChunkList& chunks) { | 778 safe_browsing_util::ListType list_id, |
| 779 const SBChunkList& chunks) { | |
| 767 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 780 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 768 | 781 |
| 769 SafeBrowsingStore* store = GetStore(list_id); | 782 SafeBrowsingStore* store = GetStore(list_id); |
| 770 if (!store) return; | 783 if (!store) return; |
| 771 | 784 |
| 772 for (SBChunkList::const_iterator citer = chunks.begin(); | 785 for (SBChunkList::const_iterator citer = chunks.begin(); |
| 773 citer != chunks.end(); ++citer) { | 786 citer != chunks.end(); ++citer) { |
| 774 const int chunk_id = citer->chunk_number; | 787 const int chunk_id = citer->chunk_number; |
| 775 | 788 |
| 776 // The server can give us a chunk that we already have because | 789 // The server can give us a chunk that we already have because |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 789 | 802 |
| 790 void SafeBrowsingDatabaseNew::InsertChunks(const std::string& list_name, | 803 void SafeBrowsingDatabaseNew::InsertChunks(const std::string& list_name, |
| 791 const SBChunkList& chunks) { | 804 const SBChunkList& chunks) { |
| 792 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 805 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 793 | 806 |
| 794 if (corruption_detected_ || chunks.empty()) | 807 if (corruption_detected_ || chunks.empty()) |
| 795 return; | 808 return; |
| 796 | 809 |
| 797 const base::TimeTicks before = base::TimeTicks::Now(); | 810 const base::TimeTicks before = base::TimeTicks::Now(); |
| 798 | 811 |
| 799 const int list_id = safe_browsing_util::GetListId(list_name); | 812 const safe_browsing_util::ListType list_id = |
| 813 safe_browsing_util::GetListId(list_name); | |
| 800 DVLOG(2) << list_name << ": " << list_id; | 814 DVLOG(2) << list_name << ": " << list_id; |
| 801 | 815 |
| 802 SafeBrowsingStore* store = GetStore(list_id); | 816 SafeBrowsingStore* store = GetStore(list_id); |
| 803 if (!store) return; | 817 if (!store) return; |
| 804 | 818 |
| 805 change_detected_ = true; | 819 changes_detected_.insert(list_id); |
| 806 | 820 |
| 807 store->BeginChunk(); | 821 store->BeginChunk(); |
| 808 if (chunks.front().is_add) { | 822 if (chunks.front().is_add) { |
| 809 InsertAddChunks(list_id, chunks); | 823 InsertAddChunks(list_id, chunks); |
| 810 } else { | 824 } else { |
| 811 InsertSubChunks(list_id, chunks); | 825 InsertSubChunks(list_id, chunks); |
| 812 } | 826 } |
| 813 store->FinishChunk(); | 827 store->FinishChunk(); |
| 814 | 828 |
| 815 UMA_HISTOGRAM_TIMES("SB2.ChunkInsert", base::TimeTicks::Now() - before); | 829 UMA_HISTOGRAM_TIMES("SB2.ChunkInsert", base::TimeTicks::Now() - before); |
| 816 } | 830 } |
| 817 | 831 |
| 818 void SafeBrowsingDatabaseNew::DeleteChunks( | 832 void SafeBrowsingDatabaseNew::DeleteChunks( |
| 819 const std::vector<SBChunkDelete>& chunk_deletes) { | 833 const std::vector<SBChunkDelete>& chunk_deletes) { |
| 820 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 834 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 821 | 835 |
| 822 if (corruption_detected_ || chunk_deletes.empty()) | 836 if (corruption_detected_ || chunk_deletes.empty()) |
| 823 return; | 837 return; |
| 824 | 838 |
| 825 const std::string& list_name = chunk_deletes.front().list_name; | 839 const std::string& list_name = chunk_deletes.front().list_name; |
| 826 const int list_id = safe_browsing_util::GetListId(list_name); | 840 const safe_browsing_util::ListType list_id = |
| 841 safe_browsing_util::GetListId(list_name); | |
| 827 | 842 |
| 828 SafeBrowsingStore* store = GetStore(list_id); | 843 SafeBrowsingStore* store = GetStore(list_id); |
| 829 if (!store) return; | 844 if (!store) return; |
| 830 | 845 |
| 831 change_detected_ = true; | 846 changes_detected_.insert(list_id); |
| 832 | 847 |
| 833 for (size_t i = 0; i < chunk_deletes.size(); ++i) { | 848 for (size_t i = 0; i < chunk_deletes.size(); ++i) { |
| 834 std::vector<int> chunk_numbers; | 849 std::vector<int> chunk_numbers; |
| 835 RangesToChunks(chunk_deletes[i].chunk_del, &chunk_numbers); | 850 RangesToChunks(chunk_deletes[i].chunk_del, &chunk_numbers); |
| 836 for (size_t j = 0; j < chunk_numbers.size(); ++j) { | 851 for (size_t j = 0; j < chunk_numbers.size(); ++j) { |
| 837 const int encoded_chunk_id = EncodeChunkId(chunk_numbers[j], list_id); | 852 const int encoded_chunk_id = EncodeChunkId(chunk_numbers[j], list_id); |
| 838 if (chunk_deletes[i].is_sub_del) | 853 if (chunk_deletes[i].is_sub_del) |
| 839 store->DeleteSubChunk(encoded_chunk_id); | 854 store->DeleteSubChunk(encoded_chunk_id); |
| 840 else | 855 else |
| 841 store->DeleteAddChunk(encoded_chunk_id); | 856 store->DeleteAddChunk(encoded_chunk_id); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 | 966 |
| 952 if (download_whitelist_store_.get()) { | 967 if (download_whitelist_store_.get()) { |
| 953 std::vector<std::string> download_whitelist_listnames; | 968 std::vector<std::string> download_whitelist_listnames; |
| 954 download_whitelist_listnames.push_back( | 969 download_whitelist_listnames.push_back( |
| 955 safe_browsing_util::kDownloadWhiteList); | 970 safe_browsing_util::kDownloadWhiteList); |
| 956 UpdateChunkRanges(download_whitelist_store_.get(), | 971 UpdateChunkRanges(download_whitelist_store_.get(), |
| 957 download_whitelist_listnames, lists); | 972 download_whitelist_listnames, lists); |
| 958 } | 973 } |
| 959 | 974 |
| 960 corruption_detected_ = false; | 975 corruption_detected_ = false; |
| 961 change_detected_ = false; | 976 changes_detected_.clear(); |
| 962 return true; | 977 return true; |
| 963 } | 978 } |
| 964 | 979 |
| 965 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { | 980 void SafeBrowsingDatabaseNew::UpdateFinished(bool update_succeeded) { |
| 966 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 981 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 967 | 982 |
| 968 // The update may have failed due to corrupt storage (for instance, | 983 // The update may have failed due to corrupt storage (for instance, |
| 969 // an excessive number of invalid add_chunks and sub_chunks). | 984 // an excessive number of invalid add_chunks and sub_chunks). |
| 970 // Double-check that the databases are valid. | 985 // Double-check that the databases are valid. |
| 971 // TODO(shess): Providing a checksum for the add_chunk and sub_chunk | 986 // TODO(shess): Providing a checksum for the add_chunk and sub_chunk |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 986 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; | 1001 DLOG(ERROR) << "Safe-browsing download whitelist database corrupt."; |
| 987 } | 1002 } |
| 988 } | 1003 } |
| 989 | 1004 |
| 990 if (corruption_detected_) | 1005 if (corruption_detected_) |
| 991 return; | 1006 return; |
| 992 | 1007 |
| 993 // Unroll the transaction if there was a protocol error or if the | 1008 // Unroll the transaction if there was a protocol error or if the |
| 994 // transaction was empty. This will leave the prefix set, the | 1009 // transaction was empty. This will leave the prefix set, the |
| 995 // pending hashes, and the prefix miss cache in place. | 1010 // pending hashes, and the prefix miss cache in place. |
| 996 if (!update_succeeded || !change_detected_) { | 1011 if (!update_succeeded || changes_detected_.empty()) { |
| 997 // Track empty updates to answer questions at http://crbug.com/72216 . | 1012 // Track empty updates to answer questions at http://crbug.com/72216 . |
| 998 if (update_succeeded && !change_detected_) | 1013 if (update_succeeded && changes_detected_.empty()) |
| 999 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); | 1014 UMA_HISTOGRAM_COUNTS("SB2.DatabaseUpdateKilobytes", 0); |
| 1000 browse_store_->CancelUpdate(); | 1015 browse_store_->CancelUpdate(); |
| 1001 if (download_store_.get()) | 1016 if (download_store_.get()) |
| 1002 download_store_->CancelUpdate(); | 1017 download_store_->CancelUpdate(); |
| 1003 if (csd_whitelist_store_.get()) | 1018 if (csd_whitelist_store_.get()) |
| 1004 csd_whitelist_store_->CancelUpdate(); | 1019 csd_whitelist_store_->CancelUpdate(); |
| 1005 if (download_whitelist_store_.get()) | 1020 if (download_whitelist_store_.get()) |
| 1006 download_whitelist_store_->CancelUpdate(); | 1021 download_whitelist_store_->CancelUpdate(); |
| 1007 return; | 1022 return; |
| 1008 } | 1023 } |
| 1009 | 1024 |
| 1010 // for download | |
| 1011 UpdateDownloadStore(); | 1025 UpdateDownloadStore(); |
| 1012 // for browsing | |
| 1013 UpdateBrowseStore(); | 1026 UpdateBrowseStore(); |
| 1014 // for csd and download whitelists. | |
| 1015 UpdateWhitelistStore(csd_whitelist_filename_, | 1027 UpdateWhitelistStore(csd_whitelist_filename_, |
| 1016 csd_whitelist_store_.get(), | 1028 csd_whitelist_store_.get(), |
| 1017 &csd_whitelist_); | 1029 &csd_whitelist_); |
| 1018 UpdateWhitelistStore(download_whitelist_filename_, | 1030 UpdateWhitelistStore(download_whitelist_filename_, |
| 1019 download_whitelist_store_.get(), | 1031 download_whitelist_store_.get(), |
| 1020 &download_whitelist_); | 1032 &download_whitelist_); |
| 1021 } | 1033 } |
| 1022 | 1034 |
| 1023 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( | 1035 void SafeBrowsingDatabaseNew::UpdateWhitelistStore( |
| 1024 const FilePath& store_filename, | 1036 const FilePath& store_filename, |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1257 RecordFailure(FAILURE_DATABASE_STORE_DELETE); | 1269 RecordFailure(FAILURE_DATABASE_STORE_DELETE); |
| 1258 | 1270 |
| 1259 FilePath bloom_filter_filename = BloomFilterForFilename(browse_filename_); | 1271 FilePath bloom_filter_filename = BloomFilterForFilename(browse_filename_); |
| 1260 const bool r5 = file_util::Delete(bloom_filter_filename, false); | 1272 const bool r5 = file_util::Delete(bloom_filter_filename, false); |
| 1261 if (!r5) | 1273 if (!r5) |
| 1262 RecordFailure(FAILURE_DATABASE_FILTER_DELETE); | 1274 RecordFailure(FAILURE_DATABASE_FILTER_DELETE); |
| 1263 | 1275 |
| 1264 const bool r6 = file_util::Delete(prefix_set_filename_, false); | 1276 const bool r6 = file_util::Delete(prefix_set_filename_, false); |
| 1265 if (!r6) | 1277 if (!r6) |
| 1266 RecordFailure(FAILURE_DATABASE_PREFIX_SET_DELETE); | 1278 RecordFailure(FAILURE_DATABASE_PREFIX_SET_DELETE); |
| 1279 | |
| 1267 return r1 && r2 && r3 && r4 && r5 && r6; | 1280 return r1 && r2 && r3 && r4 && r5 && r6; |
| 1268 } | 1281 } |
| 1269 | 1282 |
| 1270 void SafeBrowsingDatabaseNew::WritePrefixSet() { | 1283 void SafeBrowsingDatabaseNew::WritePrefixSet() { |
| 1271 DCHECK_EQ(creation_loop_, MessageLoop::current()); | 1284 DCHECK_EQ(creation_loop_, MessageLoop::current()); |
| 1272 | 1285 |
| 1273 if (!prefix_set_.get()) | 1286 if (!prefix_set_.get()) |
| 1274 return; | 1287 return; |
| 1275 | 1288 |
| 1276 const base::TimeTicks before = base::TimeTicks::Now(); | 1289 const base::TimeTicks before = base::TimeTicks::Now(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), | 1329 if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), |
| 1317 kill_switch)) { | 1330 kill_switch)) { |
| 1318 // The kill switch is whitelisted hence we whitelist all URLs. | 1331 // The kill switch is whitelisted hence we whitelist all URLs. |
| 1319 WhitelistEverything(whitelist); | 1332 WhitelistEverything(whitelist); |
| 1320 } else { | 1333 } else { |
| 1321 base::AutoLock locked(lookup_lock_); | 1334 base::AutoLock locked(lookup_lock_); |
| 1322 whitelist->second = false; | 1335 whitelist->second = false; |
| 1323 whitelist->first.swap(new_whitelist); | 1336 whitelist->first.swap(new_whitelist); |
| 1324 } | 1337 } |
| 1325 } | 1338 } |
| OLD | NEW |