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/supervised_user/supervised_user_site_list.h" | 5 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 } // namespace | 42 } // namespace |
43 | 43 |
44 SupervisedUserSiteList::HostnameHash::HostnameHash( | 44 SupervisedUserSiteList::HostnameHash::HostnameHash( |
45 const std::string& hostname) { | 45 const std::string& hostname) { |
46 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(hostname.c_str()), | 46 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(hostname.c_str()), |
47 hostname.size(), bytes_.data()); | 47 hostname.size(), bytes_.data()); |
48 } | 48 } |
49 | 49 |
50 SupervisedUserSiteList::HostnameHash::HostnameHash( | 50 SupervisedUserSiteList::HostnameHash::HostnameHash( |
51 const std::vector<uint8>& bytes) { | 51 const std::vector<uint8_t>& bytes) { |
52 CHECK_GE(bytes.size(), base::kSHA1Length); | 52 CHECK_GE(bytes.size(), base::kSHA1Length); |
53 std::copy(bytes.begin(), bytes.end(), bytes_.begin()); | 53 std::copy(bytes.begin(), bytes.end(), bytes_.begin()); |
54 } | 54 } |
55 | 55 |
56 bool SupervisedUserSiteList::HostnameHash::operator==( | 56 bool SupervisedUserSiteList::HostnameHash::operator==( |
57 const HostnameHash& rhs) const { | 57 const HostnameHash& rhs) const { |
58 return bytes_ == rhs.bytes_; | 58 return bytes_ == rhs.bytes_; |
59 } | 59 } |
60 | 60 |
61 size_t SupervisedUserSiteList::HostnameHash::hash() const { | 61 size_t SupervisedUserSiteList::HostnameHash::hash() const { |
(...skipping 29 matching lines...) Expand all Loading... |
91 } | 91 } |
92 | 92 |
93 patterns_.push_back(pattern); | 93 patterns_.push_back(pattern); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 if (hostname_hashes) { | 97 if (hostname_hashes) { |
98 for (const base::Value* entry : *hostname_hashes) { | 98 for (const base::Value* entry : *hostname_hashes) { |
99 // |hash_str| should be a hex-encoded SHA1 hash string. | 99 // |hash_str| should be a hex-encoded SHA1 hash string. |
100 std::string hash_str; | 100 std::string hash_str; |
101 std::vector<uint8> hash_bytes; | 101 std::vector<uint8_t> hash_bytes; |
102 if (!entry->GetAsString(&hash_str) || | 102 if (!entry->GetAsString(&hash_str) || |
103 hash_str.size() != 2 * base::kSHA1Length || | 103 hash_str.size() != 2 * base::kSHA1Length || |
104 !base::HexStringToBytes(hash_str, &hash_bytes)) { | 104 !base::HexStringToBytes(hash_str, &hash_bytes)) { |
105 LOG(ERROR) << "Invalid hostname_hashes entry"; | 105 LOG(ERROR) << "Invalid hostname_hashes entry"; |
106 continue; | 106 continue; |
107 } | 107 } |
108 DCHECK_EQ(base::kSHA1Length, hash_bytes.size()); | 108 DCHECK_EQ(base::kSHA1Length, hash_bytes.size()); |
109 hostname_hashes_.push_back(HostnameHash(hash_bytes)); | 109 hostname_hashes_.push_back(HostnameHash(hash_bytes)); |
110 } | 110 } |
111 } | 111 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 base::ListValue* patterns = nullptr; | 155 base::ListValue* patterns = nullptr; |
156 dict->GetList(kWhitelistKey, &patterns); | 156 dict->GetList(kWhitelistKey, &patterns); |
157 | 157 |
158 base::ListValue* hostname_hashes = nullptr; | 158 base::ListValue* hostname_hashes = nullptr; |
159 dict->GetList(kHostnameHashesKey, &hostname_hashes); | 159 dict->GetList(kHostnameHashesKey, &hostname_hashes); |
160 | 160 |
161 callback.Run(make_scoped_refptr(new SupervisedUserSiteList( | 161 callback.Run(make_scoped_refptr(new SupervisedUserSiteList( |
162 title, GURL(entry_point_url), patterns, hostname_hashes))); | 162 title, GURL(entry_point_url), patterns, hostname_hashes))); |
163 } | 163 } |
OLD | NEW |