Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / supervised_user / experimental / supervised_user_blacklist.h
blob2e93d7d49dfb3e7d1424713c46b4fd7d89399f97
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.
5 #ifndef CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_BLACKLIST_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_BLACKLIST_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/sha1.h"
17 namespace base {
18 class FilePath;
21 class GURL;
23 // Compact list of (SHA1 hashes of) blocked hosts.
24 // Checking for URLs is thread-safe, loading is not.
25 class SupervisedUserBlacklist {
26 public:
27 struct Hash {
28 Hash() {}
29 explicit Hash(const std::string& host);
30 bool operator<(const Hash& rhs) const;
32 unsigned char data[base::kSHA1Length];
35 SupervisedUserBlacklist();
36 ~SupervisedUserBlacklist();
38 // Asynchronously read a blacklist from the given file, replacing any previous
39 // entries. |done_callback| will be run after reading finishes (successfully
40 // or not), but not if the SupervisedUserBlacklist is destroyed before that.
41 void ReadFromFile(const base::FilePath& path,
42 const base::Closure& done_callback);
44 bool HasURL(const GURL& url) const;
46 size_t GetEntryCount() const;
48 private:
49 void OnReadFromFileCompleted(const base::Closure& done_callback,
50 scoped_ptr<std::vector<Hash> > host_hashes);
52 std::vector<Hash> host_hashes_;
54 base::WeakPtrFactory<SupervisedUserBlacklist> weak_ptr_factory_;
56 DISALLOW_COPY_AND_ASSIGN(SupervisedUserBlacklist);
59 #endif // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_BLACKLIST_H_