Chromium Code Reviews| Index: chrome/browser/safe_browsing/safe_browsing_database.cc |
| diff --git a/chrome/browser/safe_browsing/safe_browsing_database.cc b/chrome/browser/safe_browsing/safe_browsing_database.cc |
| index 80c16f7bbd5e236f6cc5ebb5bbe0045c3c5a68a8..5d41f88cf004a23d466a4ba016a08114c4813d3c 100644 |
| --- a/chrome/browser/safe_browsing/safe_browsing_database.cc |
| +++ b/chrome/browser/safe_browsing/safe_browsing_database.cc |
| @@ -31,10 +31,11 @@ |
| #endif |
| using content::BrowserThread; |
| -using safe_browsing::PrefixSet; |
| -using safe_browsing::PrefixSetBuilder; |
| -namespace { |
| +namespace safe_browsing { |
| + |
| +class PrefixSet; |
| +class PrefixSetBuilder; |
| // Filename suffix for the bloom filter. |
|
Nathan Parker
2015/11/05 22:00:53
Keep these in anon-namespace.
vakh (old account. dont use)
2015/11/07 01:22:56
Done.
|
| const base::FilePath::CharType kBloomFilterFileSuffix[] = |
| @@ -107,7 +108,7 @@ int DecodeChunkId(int encoded_chunk_id) { |
| return encoded_chunk_id >> 1; |
| } |
| int EncodeChunkId(const int chunk, const int list_id) { |
| - DCHECK_NE(list_id, safe_browsing::INVALID); |
| + DCHECK_NE(list_id, INVALID); |
|
Nathan Parker
2015/11/05 22:00:53
(This is a terribly generically named enum val. W
|
| return chunk << 1 | list_id % 2; |
| } |
| @@ -128,16 +129,16 @@ void UrlToFullHashes(const GURL& url, |
| if (url.HostIsIPAddress()) { |
| hosts.push_back(url.host()); |
| } else { |
| - safe_browsing::GenerateHostsToCheck(url, &hosts); |
| + GenerateHostsToCheck(url, &hosts); |
| } |
| std::vector<std::string> paths; |
| - safe_browsing::GeneratePathsToCheck(url, &paths); |
| + GeneratePathsToCheck(url, &paths); |
| for (size_t i = 0; i < hosts.size(); ++i) { |
| for (size_t j = 0; j < paths.size(); ++j) { |
| const std::string& path = paths[j]; |
| - full_hashes->push_back(safe_browsing::SBFullHashForString( |
| + full_hashes->push_back(SBFullHashForString( |
| hosts[i] + path)); |
| // We may have /foo as path-prefix in the whitelist which should |
| @@ -147,7 +148,7 @@ void UrlToFullHashes(const GURL& url, |
| path.size() > 1 && |
| path[path.size() - 1] == '/') { |
| full_hashes->push_back( |
| - safe_browsing::SBFullHashForString( |
| + SBFullHashForString( |
| hosts[i] + path.substr(0, path.size() - 1))); |
| } |
| } |
| @@ -232,10 +233,10 @@ void UpdateChunkRanges(SafeBrowsingStore* store, |
| for (size_t i = 0; i < listnames.size(); ++i) { |
| const std::string& listname = listnames[i]; |
| - DCHECK_EQ(safe_browsing::GetListId(listname) % 2, |
| + DCHECK_EQ(GetListId(listname) % 2, |
| static_cast<int>(i % 2)); |
| - DCHECK_NE(safe_browsing::GetListId(listname), |
| - safe_browsing::INVALID); |
| + DCHECK_NE(GetListId(listname), |
| + INVALID); |
| lists->push_back(SBListChunkRanges(listname)); |
| lists->back().adds.swap(adds[i]); |
| lists->back().subs.swap(subs[i]); |
| @@ -291,7 +292,7 @@ bool GetCachedFullHash(std::map<SBPrefix, SBCachedFullHashResult>* cache, |
| // Find full-hash matches. |
| std::vector<SBFullHashResult>& cached_hashes = cached_result.full_hashes; |
| for (size_t i = 0; i < cached_hashes.size(); ++i) { |
| - if (safe_browsing::SBFullHashEqual(full_hash, cached_hashes[i].hash)) |
| + if (SBFullHashEqual(full_hash, cached_hashes[i].hash)) |
| results->push_back(cached_hashes[i]); |
| } |
| @@ -306,8 +307,6 @@ SafeBrowsingStoreFile* CreateStore( |
| return new SafeBrowsingStoreFile(task_runner); |
| } |
| -} // namespace |
| - |
| // The default SafeBrowsingDatabaseFactory. |
| class SafeBrowsingDatabaseFactoryImpl : public SafeBrowsingDatabaseFactory { |
| public: |
| @@ -447,22 +446,22 @@ SafeBrowsingStore* SafeBrowsingDatabaseNew::GetStore(const int list_id) { |
| // Stores are not thread safe. |
| DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| - if (list_id == safe_browsing::PHISH || |
| - list_id == safe_browsing::MALWARE) { |
| + if (list_id == PHISH || |
| + list_id == MALWARE) { |
| return browse_store_.get(); |
| - } else if (list_id == safe_browsing::BINURL) { |
| + } else if (list_id == BINURL) { |
| return download_store_.get(); |
| - } else if (list_id == safe_browsing::CSDWHITELIST) { |
| + } else if (list_id == CSDWHITELIST) { |
| return csd_whitelist_store_.get(); |
| - } else if (list_id == safe_browsing::DOWNLOADWHITELIST) { |
| + } else if (list_id == DOWNLOADWHITELIST) { |
| return download_whitelist_store_.get(); |
| - } else if (list_id == safe_browsing::INCLUSIONWHITELIST) { |
| + } else if (list_id == INCLUSIONWHITELIST) { |
| return inclusion_whitelist_store_.get(); |
| - } else if (list_id == safe_browsing::EXTENSIONBLACKLIST) { |
| + } else if (list_id == EXTENSIONBLACKLIST) { |
| return extension_blacklist_store_.get(); |
| - } else if (list_id == safe_browsing::IPBLACKLIST) { |
| + } else if (list_id == IPBLACKLIST) { |
| return ip_blacklist_store_.get(); |
| - } else if (list_id == safe_browsing::UNWANTEDURL) { |
| + } else if (list_id == UNWANTEDURL) { |
| return unwanted_software_store_.get(); |
| } |
| return NULL; |
| @@ -917,7 +916,7 @@ bool SafeBrowsingDatabaseNew::ContainsDownloadUrlPrefixes( |
| return false; |
| return MatchAddPrefixes(download_store_.get(), |
| - safe_browsing::BINURL % 2, |
| + BINURL % 2, |
| prefixes, |
| prefix_hits); |
| } |
| @@ -949,7 +948,7 @@ bool SafeBrowsingDatabaseNew::ContainsExtensionPrefixes( |
| return false; |
| return MatchAddPrefixes(extension_blacklist_store_.get(), |
| - safe_browsing::EXTENSIONBLACKLIST % 2, |
| + EXTENSIONBLACKLIST % 2, |
| prefixes, |
| prefix_hits); |
| } |
| @@ -989,7 +988,7 @@ bool SafeBrowsingDatabaseNew::ContainsMalwareIP(const std::string& ip_address) { |
| bool SafeBrowsingDatabaseNew::ContainsDownloadWhitelistedString( |
| const std::string& str) { |
| std::vector<SBFullHash> hashes; |
| - hashes.push_back(safe_browsing::SBFullHashForString(str)); |
| + hashes.push_back(SBFullHashForString(str)); |
| return ContainsWhitelistedHashes(SBWhitelistId::DOWNLOAD, hashes); |
| } |
| @@ -1003,7 +1002,7 @@ bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes( |
| for (std::vector<SBFullHash>::const_iterator it = hashes.begin(); |
| it != hashes.end(); ++it) { |
| if (std::binary_search(whitelist->first.begin(), whitelist->first.end(), |
| - *it, safe_browsing::SBFullHashLess)) { |
| + *it, SBFullHashLess)) { |
| return true; |
| } |
| } |
| @@ -1013,7 +1012,7 @@ bool SafeBrowsingDatabaseNew::ContainsWhitelistedHashes( |
| // Helper to insert add-chunk entries. |
| void SafeBrowsingDatabaseNew::InsertAddChunk( |
| SafeBrowsingStore* store, |
| - const safe_browsing::ListType list_id, |
| + const ListType list_id, |
| const SBChunkData& chunk_data) { |
| DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| DCHECK(store); |
| @@ -1042,7 +1041,7 @@ void SafeBrowsingDatabaseNew::InsertAddChunk( |
| // Helper to insert sub-chunk entries. |
| void SafeBrowsingDatabaseNew::InsertSubChunk( |
| SafeBrowsingStore* store, |
| - const safe_browsing::ListType list_id, |
| + const ListType list_id, |
| const SBChunkData& chunk_data) { |
| DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); |
| DCHECK(store); |
| @@ -1085,8 +1084,8 @@ void SafeBrowsingDatabaseNew::InsertChunks( |
| const base::TimeTicks before = base::TimeTicks::Now(); |
| // TODO(shess): The caller should just pass list_id. |
| - const safe_browsing::ListType list_id = |
| - safe_browsing::GetListId(list_name); |
| + const ListType list_id = |
| + GetListId(list_name); |
| SafeBrowsingStore* store = GetStore(list_id); |
| if (!store) return; |
| @@ -1118,8 +1117,8 @@ void SafeBrowsingDatabaseNew::DeleteChunks( |
| return; |
| const std::string& list_name = chunk_deletes.front().list_name; |
| - const safe_browsing::ListType list_id = |
| - safe_browsing::GetListId(list_name); |
| + const ListType list_id = |
| + GetListId(list_name); |
| SafeBrowsingStore* store = GetStore(list_id); |
| if (!store) return; |
| @@ -1223,8 +1222,8 @@ bool SafeBrowsingDatabaseNew::UpdateStarted( |
| state_manager_.BeginWriteTransaction()->clear_prefix_gethash_cache(); |
| UpdateChunkRangesForLists(browse_store_.get(), |
| - safe_browsing::kMalwareList, |
| - safe_browsing::kPhishingList, |
| + kMalwareList, |
| + kPhishingList, |
| lists); |
| // NOTE(shess): |download_store_| used to contain kBinHashList, which has been |
| @@ -1232,25 +1231,25 @@ bool SafeBrowsingDatabaseNew::UpdateStarted( |
| // of Feb 2014, so it has been removed. Everything _should_ be resilient to |
| // extra data of that sort. |
| UpdateChunkRangesForList(download_store_.get(), |
| - safe_browsing::kBinUrlList, lists); |
| + kBinUrlList, lists); |
| UpdateChunkRangesForList(csd_whitelist_store_.get(), |
| - safe_browsing::kCsdWhiteList, lists); |
| + kCsdWhiteList, lists); |
| UpdateChunkRangesForList(download_whitelist_store_.get(), |
| - safe_browsing::kDownloadWhiteList, lists); |
| + kDownloadWhiteList, lists); |
| UpdateChunkRangesForList(inclusion_whitelist_store_.get(), |
| - safe_browsing::kInclusionWhitelist, lists); |
| + kInclusionWhitelist, lists); |
| UpdateChunkRangesForList(extension_blacklist_store_.get(), |
| - safe_browsing::kExtensionBlacklist, lists); |
| + kExtensionBlacklist, lists); |
| UpdateChunkRangesForList(ip_blacklist_store_.get(), |
| - safe_browsing::kIPBlacklist, lists); |
| + kIPBlacklist, lists); |
| UpdateChunkRangesForList(unwanted_software_store_.get(), |
| - safe_browsing::kUnwantedUrlList, |
| + kUnwantedUrlList, |
| lists); |
| db_state_manager_.reset_corruption_detected(); |
| @@ -1705,12 +1704,12 @@ void SafeBrowsingDatabaseNew::LoadWhitelist( |
| new_whitelist.push_back(it->full_hash); |
| } |
| std::sort(new_whitelist.begin(), new_whitelist.end(), |
| - safe_browsing::SBFullHashLess); |
| + SBFullHashLess); |
| - SBFullHash kill_switch = safe_browsing::SBFullHashForString( |
| + SBFullHash kill_switch = SBFullHashForString( |
| kWhitelistKillSwitchUrl); |
| if (std::binary_search(new_whitelist.begin(), new_whitelist.end(), |
| - kill_switch, safe_browsing::SBFullHashLess)) { |
| + kill_switch, SBFullHashLess)) { |
| // The kill switch is whitelisted hence we whitelist all URLs. |
| state_manager_.BeginWriteTransaction()->WhitelistEverything(whitelist_id); |
| } else { |
| @@ -1760,8 +1759,7 @@ void SafeBrowsingDatabaseNew::LoadIpBlacklist( |
| } |
| bool SafeBrowsingDatabaseNew::IsMalwareIPMatchKillSwitchOn() { |
| - SBFullHash malware_kill_switch = safe_browsing::SBFullHashForString( |
| - kMalwareIPKillSwitchUrl); |
| + SBFullHash malware_kill_switch = SBFullHashForString(kMalwareIPKillSwitchUrl); |
| std::vector<SBFullHash> full_hashes; |
| full_hashes.push_back(malware_kill_switch); |
| return ContainsWhitelistedHashes(SBWhitelistId::CSD, full_hashes); |
| @@ -1834,3 +1832,5 @@ void SafeBrowsingDatabaseNew::RecordFileSizeHistogram( |
| histogram_pointer->Add(file_size_kilobytes); |
| } |
| + |
| +} // namespace safe_browsing |