Home | History | Annotate | Download | only in src
      1 // Copyright 2016 The Weave 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 LIBWEAVE_SRC_ACCESS_BLACK_LIST_IMPL_H_
      6 #define LIBWEAVE_SRC_ACCESS_BLACK_LIST_IMPL_H_
      7 
      8 #include <map>
      9 #include <utility>
     10 
     11 #include <base/time/default_clock.h>
     12 #include <base/time/time.h>
     13 #include <weave/error.h>
     14 #include <weave/provider/config_store.h>
     15 
     16 #include "src/access_black_list_manager.h"
     17 
     18 namespace weave {
     19 
     20 class AccessBlackListManagerImpl : public AccessBlackListManager {
     21  public:
     22   explicit AccessBlackListManagerImpl(provider::ConfigStore* store,
     23                                       size_t capacity = 1024,
     24                                       base::Clock* clock = nullptr);
     25 
     26   // AccessBlackListManager implementation.
     27   void Block(const std::vector<uint8_t>& user_id,
     28              const std::vector<uint8_t>& app_id,
     29              const base::Time& expiration,
     30              const DoneCallback& callback) override;
     31   void Unblock(const std::vector<uint8_t>& user_id,
     32                const std::vector<uint8_t>& app_id,
     33                const DoneCallback& callback) override;
     34   bool IsBlocked(const std::vector<uint8_t>& user_id,
     35                  const std::vector<uint8_t>& app_id) const override;
     36   std::vector<Entry> GetEntries() const override;
     37   size_t GetSize() const override;
     38   size_t GetCapacity() const override;
     39 
     40  private:
     41   void Load();
     42   void Save(const DoneCallback& callback);
     43   void RemoveExpired();
     44 
     45   const size_t capacity_{0};
     46   base::DefaultClock default_clock_;
     47   base::Clock* clock_{&default_clock_};
     48 
     49   provider::ConfigStore* store_{nullptr};
     50   std::map<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>, base::Time>
     51       entries_;
     52 
     53   DISALLOW_COPY_AND_ASSIGN(AccessBlackListManagerImpl);
     54 };
     55 
     56 }  // namespace weave
     57 
     58 #endif  // LIBWEAVE_SRC_ACCESS_BLACK_LIST_IMPL_H_
     59