Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_database.cc

Issue 1548133002: Switch to standard integer types in chrome/browser/, part 3 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
8 #include <stdint.h>
9
7 #include <algorithm> 10 #include <algorithm>
8 #include <iterator> 11 #include <iterator>
9 12
10 #include "base/bind.h" 13 #include "base/bind.h"
11 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
12 #include "base/macros.h" 15 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
15 #include "base/process/process_handle.h" 18 #include "base/process/process_handle.h"
16 #include "base/process/process_metrics.h" 19 #include "base/process/process_metrics.h"
17 #include "base/sha1.h" 20 #include "base/sha1.h"
18 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
21 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "build/build_config.h"
22 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" 26 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
23 #include "components/safe_browsing_db/prefix_set.h" 27 #include "components/safe_browsing_db/prefix_set.h"
24 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
25 #include "crypto/sha2.h" 29 #include "crypto/sha2.h"
26 #include "net/base/ip_address_number.h" 30 #include "net/base/ip_address_number.h"
27 #include "url/gurl.h" 31 #include "url/gurl.h"
28 32
29 #if defined(OS_MACOSX) 33 #if defined(OS_MACOSX)
30 #include "base/mac/mac_util.h" 34 #include "base/mac/mac_util.h"
31 #endif 35 #endif
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 213
210 void UpdateChunkRangesForList( 214 void UpdateChunkRangesForList(
211 SafeBrowsingStore* store, 215 SafeBrowsingStore* store,
212 const std::string& listname, 216 const std::string& listname,
213 std::vector<SBListChunkRanges>* lists) { 217 std::vector<SBListChunkRanges>* lists) {
214 UpdateChunkRanges(store, std::vector<std::string>(1, listname), lists); 218 UpdateChunkRanges(store, std::vector<std::string>(1, listname), lists);
215 } 219 }
216 220
217 // This code always checks for non-zero file size. This helper makes 221 // This code always checks for non-zero file size. This helper makes
218 // that less verbose. 222 // that less verbose.
219 int64 GetFileSizeOrZero(const base::FilePath& file_path) { 223 int64_t GetFileSizeOrZero(const base::FilePath& file_path) {
220 int64 size_64; 224 int64_t size_64;
221 if (!base::GetFileSize(file_path, &size_64)) 225 if (!base::GetFileSize(file_path, &size_64))
222 return 0; 226 return 0;
223 return size_64; 227 return size_64;
224 } 228 }
225 229
226 // Helper for PrefixSetContainsUrlHashes(). Returns true if an un-expired match 230 // Helper for PrefixSetContainsUrlHashes(). Returns true if an un-expired match
227 // for |full_hash| is found in |cache|, with any matches appended to |results| 231 // for |full_hash| is found in |cache|, with any matches appended to |results|
228 // (true can be returned with zero matches). |expire_base| is used to check the 232 // (true can be returned with zero matches). |expire_base| is used to check the
229 // cache lifetime of matches, expired matches will be discarded from |cache|. 233 // cache lifetime of matches, expired matches will be discarded from |cache|.
230 bool GetCachedFullHash(std::map<SBPrefix, SBCachedFullHashResult>* cache, 234 bool GetCachedFullHash(std::map<SBPrefix, SBCachedFullHashResult>* cache,
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 void SafeBrowsingDatabaseNew::LoadIpBlacklist( 1660 void SafeBrowsingDatabaseNew::LoadIpBlacklist(
1657 const std::vector<SBAddFullHash>& full_hashes) { 1661 const std::vector<SBAddFullHash>& full_hashes) {
1658 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 1662 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
1659 1663
1660 IPBlacklist new_blacklist; 1664 IPBlacklist new_blacklist;
1661 for (std::vector<SBAddFullHash>::const_iterator it = full_hashes.begin(); 1665 for (std::vector<SBAddFullHash>::const_iterator it = full_hashes.begin();
1662 it != full_hashes.end(); ++it) { 1666 it != full_hashes.end(); ++it) {
1663 const char* full_hash = it->full_hash.full_hash; 1667 const char* full_hash = it->full_hash.full_hash;
1664 DCHECK_EQ(crypto::kSHA256Length, arraysize(it->full_hash.full_hash)); 1668 DCHECK_EQ(crypto::kSHA256Length, arraysize(it->full_hash.full_hash));
1665 // The format of the IP blacklist is: 1669 // The format of the IP blacklist is:
1666 // SHA-1(IPv6 prefix) + uint8(prefix size) + 11 unused bytes. 1670 // SHA-1(IPv6 prefix) + uint8_t(prefix size) + 11 unused bytes.
1667 std::string hashed_ip_prefix(full_hash, base::kSHA1Length); 1671 std::string hashed_ip_prefix(full_hash, base::kSHA1Length);
1668 size_t prefix_size = static_cast<uint8>(full_hash[base::kSHA1Length]); 1672 size_t prefix_size = static_cast<uint8_t>(full_hash[base::kSHA1Length]);
1669 if (prefix_size > kMaxIpPrefixSize || prefix_size < kMinIpPrefixSize) { 1673 if (prefix_size > kMaxIpPrefixSize || prefix_size < kMinIpPrefixSize) {
1670 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_INVALID); 1674 RecordFailure(FAILURE_IP_BLACKLIST_UPDATE_INVALID);
1671 new_blacklist.clear(); // Load empty blacklist. 1675 new_blacklist.clear(); // Load empty blacklist.
1672 break; 1676 break;
1673 } 1677 }
1674 1678
1675 // We precompute the mask for the given subnet size to speed up lookups. 1679 // We precompute the mask for the given subnet size to speed up lookups.
1676 // Basically we need to create a 16B long string which has the highest 1680 // Basically we need to create a 16B long string which has the highest
1677 // |size| bits sets to one. 1681 // |size| bits sets to one.
1678 std::string mask(net::kIPv6AddressSize, '\0'); 1682 std::string mask(net::kIPv6AddressSize, '\0');
(...skipping 26 matching lines...) Expand all
1705 ->second; 1709 ->second;
1706 } 1710 }
1707 1711
1708 SafeBrowsingDatabaseNew::PrefixGetHashCache* 1712 SafeBrowsingDatabaseNew::PrefixGetHashCache*
1709 SafeBrowsingDatabaseNew::GetUnsynchronizedPrefixGetHashCacheForTesting() { 1713 SafeBrowsingDatabaseNew::GetUnsynchronizedPrefixGetHashCacheForTesting() {
1710 return state_manager_.BeginReadTransaction()->prefix_gethash_cache(); 1714 return state_manager_.BeginReadTransaction()->prefix_gethash_cache();
1711 } 1715 }
1712 1716
1713 void SafeBrowsingDatabaseNew::RecordFileSizeHistogram( 1717 void SafeBrowsingDatabaseNew::RecordFileSizeHistogram(
1714 const base::FilePath& file_path) { 1718 const base::FilePath& file_path) {
1715 const int64 file_size = GetFileSizeOrZero(file_path); 1719 const int64_t file_size = GetFileSizeOrZero(file_path);
1716 const int file_size_kilobytes = static_cast<int>(file_size / 1024); 1720 const int file_size_kilobytes = static_cast<int>(file_size / 1024);
1717 1721
1718 base::FilePath::StringType filename = file_path.BaseName().value(); 1722 base::FilePath::StringType filename = file_path.BaseName().value();
1719 1723
1720 // Default to logging DB sizes unless |file_path| points at PrefixSet storage. 1724 // Default to logging DB sizes unless |file_path| points at PrefixSet storage.
1721 std::string histogram_name("SB2.DatabaseSizeKilobytes"); 1725 std::string histogram_name("SB2.DatabaseSizeKilobytes");
1722 if (base::EndsWith(filename, kPrefixSetFileSuffix, 1726 if (base::EndsWith(filename, kPrefixSetFileSuffix,
1723 base::CompareCase::SENSITIVE)) { 1727 base::CompareCase::SENSITIVE)) {
1724 histogram_name = "SB2.PrefixSetSizeKilobytes"; 1728 histogram_name = "SB2.PrefixSetSizeKilobytes";
1725 // Clear the PrefixSet suffix to have the histogram suffix selector below 1729 // Clear the PrefixSet suffix to have the histogram suffix selector below
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 1765
1762 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro. 1766 // Histogram properties as in UMA_HISTOGRAM_COUNTS macro.
1763 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet( 1767 base::HistogramBase* histogram_pointer = base::Histogram::FactoryGet(
1764 histogram_name, 1, 1000000, 50, 1768 histogram_name, 1, 1000000, 50,
1765 base::HistogramBase::kUmaTargetedHistogramFlag); 1769 base::HistogramBase::kUmaTargetedHistogramFlag);
1766 1770
1767 histogram_pointer->Add(file_size_kilobytes); 1771 histogram_pointer->Add(file_size_kilobytes);
1768 } 1772 }
1769 1773
1770 } // namespace safe_browsing 1774 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_database.h ('k') | chrome/browser/safe_browsing/safe_browsing_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698