permission.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 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.
  4. #ifndef COMPONENTS_EXO_PERMISSION_H_
  5. #define COMPONENTS_EXO_PERMISSION_H_
  6. #include "base/time/time.h"
  7. #include "ui/base/class_property.h"
  8. namespace exo {
  9. // An aura::Window property that adds a capability to a window.
  10. class Permission {
  11. public:
  12. enum class Capability {
  13. kActivate,
  14. };
  15. // Creates a permission with a |capability| that never expires.
  16. explicit Permission(Capability capability);
  17. // Create a permission with the given |capability| until |timeout| elapses.
  18. Permission(Capability capability, base::TimeDelta timeout);
  19. // Delete copy and move.
  20. Permission(const Permission& other) = delete;
  21. Permission(Permission&& other) = delete;
  22. Permission& operator=(const Permission& other) = delete;
  23. Permission& operator=(Permission&& other) = delete;
  24. virtual ~Permission();
  25. // Prevent this permission from returning true on subsequent Check()s.
  26. void Revoke();
  27. // Returns true iff this permission was created with the given |capability|
  28. // and is not expired.
  29. bool Check(Capability capability) const;
  30. private:
  31. Capability capability_;
  32. base::Time expiry_;
  33. };
  34. extern const ui::ClassProperty<Permission*>* const kPermissionKey;
  35. } // namespace exo
  36. #endif // COMPONENTS_EXO_PERMISSION_H_