Leonid Baraz | 3e8af4b | 2020-11-23 19:04:47 | [diff] [blame] | 1 | // Copyright 2020 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 | |
Leonid Baraz | ea0c6dc | 2021-11-02 20:38:05 | [diff] [blame] | 5 | #ifndef COMPONENTS_REPORTING_RESOURCES_MEMORY_RESOURCE_IMPL_H_ |
| 6 | #define COMPONENTS_REPORTING_RESOURCES_MEMORY_RESOURCE_IMPL_H_ |
Leonid Baraz | 3e8af4b | 2020-11-23 19:04:47 | [diff] [blame] | 7 | |
| 8 | #include <atomic> |
| 9 | #include <cstdint> |
| 10 | |
Leonid Baraz | ea0c6dc | 2021-11-02 20:38:05 | [diff] [blame] | 11 | #include "components/reporting/resources/resource_interface.h" |
Leonid Baraz | 3e8af4b | 2020-11-23 19:04:47 | [diff] [blame] | 12 | |
| 13 | namespace reporting { |
| 14 | |
| 15 | // Interface to resources management by Storage module. |
| 16 | // Must be implemented by the caller base on the platform limitations. |
| 17 | // All APIs are non-blocking. |
| 18 | class MemoryResourceImpl : public ResourceInterface { |
| 19 | public: |
Leonid Baraz | 960ea8f | 2022-05-17 01:01:06 | [diff] [blame] | 20 | explicit MemoryResourceImpl(uint64_t total_size); |
Leonid Baraz | 3e8af4b | 2020-11-23 19:04:47 | [diff] [blame] | 21 | |
| 22 | // Implementation of ResourceInterface methods. |
Zach Trudo | f1bf7ce | 2020-12-22 21:46:15 | [diff] [blame] | 23 | bool Reserve(uint64_t size) override; |
| 24 | void Discard(uint64_t size) override; |
| 25 | uint64_t GetTotal() override; |
| 26 | uint64_t GetUsed() override; |
| 27 | void Test_SetTotal(uint64_t test_total) override; |
Leonid Baraz | 3e8af4b | 2020-11-23 19:04:47 | [diff] [blame] | 28 | |
| 29 | private: |
Leonid Baraz | 960ea8f | 2022-05-17 01:01:06 | [diff] [blame] | 30 | ~MemoryResourceImpl() override; |
| 31 | |
Zach Trudo | f1bf7ce | 2020-12-22 21:46:15 | [diff] [blame] | 32 | uint64_t total_; |
Leonid Baraz | 960ea8f | 2022-05-17 01:01:06 | [diff] [blame] | 33 | std::atomic<uint64_t> used_{0}; |
Leonid Baraz | 3e8af4b | 2020-11-23 19:04:47 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | } // namespace reporting |
| 37 | |
Leonid Baraz | ea0c6dc | 2021-11-02 20:38:05 | [diff] [blame] | 38 | #endif // COMPONENTS_REPORTING_RESOURCES_MEMORY_RESOURCE_IMPL_H_ |