summaryrefslogtreecommitdiffstats
path: root/chrome/browser/supervised_user/experimental/supervised_user_blacklist.h
blob: 44ccb36302d8b878e47a7c40e5c339f1dcadcfd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_BLACKLIST_H_
#define CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_BLACKLIST_H_

#include <stddef.h>

#include <string>
#include <vector>

#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sha1.h"

namespace base {
class FilePath;
}

class GURL;

// Compact list of (SHA1 hashes of) blocked hosts.
// Checking for URLs is thread-safe, loading is not.
class SupervisedUserBlacklist {
 public:
  struct Hash {
    Hash() {}
    explicit Hash(const std::string& host);
    bool operator<(const Hash& rhs) const;

    unsigned char data[base::kSHA1Length];
  };

  SupervisedUserBlacklist();
  ~SupervisedUserBlacklist();

  // Asynchronously read a blacklist from the given file, replacing any previous
  // entries. |done_callback| will be run after reading finishes (successfully
  // or not), but not if the SupervisedUserBlacklist is destroyed before that.
  void ReadFromFile(const base::FilePath& path,
                    const base::Closure& done_callback);

  bool HasURL(const GURL& url) const;

  size_t GetEntryCount() const;

 private:
  void OnReadFromFileCompleted(const base::Closure& done_callback,
                               scoped_ptr<std::vector<Hash> > host_hashes);

  std::vector<Hash> host_hashes_;

  base::WeakPtrFactory<SupervisedUserBlacklist> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(SupervisedUserBlacklist);
};

#endif  // CHROME_BROWSER_SUPERVISED_USER_EXPERIMENTAL_SUPERVISED_USER_BLACKLIST_H_