summaryrefslogtreecommitdiff
path: root/chromium/components/exo/permission.h
blob: fdf0ab67b64decbd7df9b3e9efa32142c6810786 (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
// Copyright 2019 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 COMPONENTS_EXO_PERMISSION_H_
#define COMPONENTS_EXO_PERMISSION_H_

#include "base/time/time.h"

namespace exo {

class Permission {
 public:
  enum class Capability {
    kActivate,
  };

  // Create a permission with the given |capability| until |timeout| elapses.
  Permission(Capability capability, base::TimeDelta timeout);

  // Delete copy and move.
  Permission(const Permission& other) = delete;
  Permission(Permission&& other) = delete;
  Permission& operator=(const Permission& other) = delete;
  Permission& operator=(Permission&& other) = delete;

  virtual ~Permission() = default;

  // Prevent this permission from returning true on subsequent Check()s.
  void Revoke();

  // Returns true iff this permission was created with the given |capability|
  // and is not expired.
  bool Check(Capability capability) const;

 private:
  Capability capability_;

  base::Time expiry_;
};

}  // namespace exo

#endif  // COMPONENTS_EXO_PERMISSION_H_