OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/activity_log/hashed_ad_network_database.h" | 5 #include "chrome/browser/extensions/activity_log/hashed_ad_network_database.h" |
6 | 6 |
7 #include <algorithm> // std::binary_search | 7 #include <algorithm> // std::binary_search |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 HashedAdNetworkDatabase::HashedAdNetworkDatabase() | 31 HashedAdNetworkDatabase::HashedAdNetworkDatabase() |
32 : entries_(kHashedAdNetworks), | 32 : entries_(kHashedAdNetworks), |
33 num_entries_(kNumHashedAdNetworks) { | 33 num_entries_(kNumHashedAdNetworks) { |
34 } | 34 } |
35 | 35 |
36 HashedAdNetworkDatabase::~HashedAdNetworkDatabase() { | 36 HashedAdNetworkDatabase::~HashedAdNetworkDatabase() { |
37 } | 37 } |
38 | 38 |
39 bool HashedAdNetworkDatabase::IsAdNetwork(const GURL& url) const { | 39 bool HashedAdNetworkDatabase::IsAdNetwork(const GURL& url) const { |
40 // The list should be sorted. Check once in debug builds. | 40 // The list should be sorted. Check once in debug builds. |
41 #if DCHECK_IS_ON | 41 #if DCHECK_IS_ON() |
42 static bool is_sorted = false; | 42 static bool is_sorted = false; |
43 if (!is_sorted) { | 43 if (!is_sorted) { |
44 std::vector<std::string> list; | 44 std::vector<std::string> list; |
45 for (int i = 0; i < num_entries_; ++i) | 45 for (int i = 0; i < num_entries_; ++i) |
46 list.push_back(std::string(entries_[i])); | 46 list.push_back(std::string(entries_[i])); |
47 is_sorted = base::STLIsSorted(list); | 47 is_sorted = base::STLIsSorted(list); |
48 } | 48 } |
49 DCHECK(is_sorted); | 49 DCHECK(is_sorted); |
50 #endif | 50 #endif |
51 | 51 |
52 shorthash hash; | 52 shorthash hash; |
53 crypto::SHA256HashString(url.host(), hash, sizeof(shorthash)); | 53 crypto::SHA256HashString(url.host(), hash, sizeof(shorthash)); |
54 std::string hex_encoded = base::HexEncode(hash, sizeof(shorthash)); | 54 std::string hex_encoded = base::HexEncode(hash, sizeof(shorthash)); |
55 return std::binary_search(entries_, | 55 return std::binary_search(entries_, |
56 entries_ + num_entries_, | 56 entries_ + num_entries_, |
57 hex_encoded.c_str(), | 57 hex_encoded.c_str(), |
58 CompareEntries); | 58 CompareEntries); |
59 } | 59 } |
60 | 60 |
61 } // namespace extensions | 61 } // namespace extensions |
OLD | NEW |