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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_DENYLIST_H_ 6 #define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_DENYLIST_H_ 7 8 #include <stddef.h> 9 10 #include <memory> 11 #include <string> 12 #include <vector> 13 14 #include "base/callback_forward.h" 15 #include "base/hash/sha1.h" 16 #include "base/macros.h" 17 #include "base/memory/weak_ptr.h" 18 19 namespace base { 20 class FilePath; 21 } 22 23 class GURL; 24 25 // Compact list of (SHA1 hashes of) blocked hosts. 26 // Checking for URLs is thread-safe, loading is not. 27 class SupervisedUserDenylist { 28 public: 29 struct Hash { HashHash30 Hash() {} 31 explicit Hash(const std::string& host); 32 bool operator<(const Hash& rhs) const; 33 34 unsigned char data[base::kSHA1Length]; 35 }; 36 37 SupervisedUserDenylist(); 38 ~SupervisedUserDenylist(); 39 40 // Asynchronously read a denylist from the given file, replacing any previous 41 // entries. |done_callback| will be run after reading finishes (successfully 42 // or not), but not if the SupervisedUserDenylist is destroyed before that. 43 void ReadFromFile(const base::FilePath& path, 44 const base::Closure& done_callback); 45 46 bool HasURL(const GURL& url) const; 47 48 size_t GetEntryCount() const; 49 50 private: 51 void OnReadFromFileCompleted(const base::Closure& done_callback, 52 std::unique_ptr<std::vector<Hash>> host_hashes); 53 54 std::vector<Hash> host_hashes_; 55 56 base::WeakPtrFactory<SupervisedUserDenylist> weak_ptr_factory_{this}; 57 58 DISALLOW_COPY_AND_ASSIGN(SupervisedUserDenylist); 59 }; 60 61 #endif // CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_DENYLIST_H_ 62