blob: 1c175db67cd58de30da60b65840c1e026c6d48c2 (
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
|
// Copyright 2016 The Weave 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 LIBWEAVE_SRC_ACCESS_BLACK_LIST_IMPL_H_
#define LIBWEAVE_SRC_ACCESS_BLACK_LIST_IMPL_H_
#include <map>
#include <utility>
#include <base/time/default_clock.h>
#include <base/time/time.h>
#include <weave/error.h>
#include <weave/provider/config_store.h>
#include "src/access_black_list_manager.h"
namespace weave {
class AccessBlackListManagerImpl : public AccessBlackListManager {
public:
explicit AccessBlackListManagerImpl(provider::ConfigStore* store,
size_t capacity = 1024,
base::Clock* clock = nullptr);
// AccessBlackListManager implementation.
void Block(const std::vector<uint8_t>& user_id,
const std::vector<uint8_t>& app_id,
const base::Time& expiration,
const DoneCallback& callback) override;
void Unblock(const std::vector<uint8_t>& user_id,
const std::vector<uint8_t>& app_id,
const DoneCallback& callback) override;
bool IsBlocked(const std::vector<uint8_t>& user_id,
const std::vector<uint8_t>& app_id) const override;
std::vector<Entry> GetEntries() const override;
size_t GetSize() const override;
size_t GetCapacity() const override;
private:
void Load();
void Save(const DoneCallback& callback);
void RemoveExpired();
const size_t capacity_{0};
base::DefaultClock default_clock_;
base::Clock* clock_{&default_clock_};
provider::ConfigStore* store_{nullptr};
std::map<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>, base::Time>
entries_;
DISALLOW_COPY_AND_ASSIGN(AccessBlackListManagerImpl);
};
} // namespace weave
#endif // LIBWEAVE_SRC_ACCESS_BLACK_LIST_IMPL_H_
|