blob: 9819a0eb7943b1b52ba53525d5028a6f796f5469 [file] [log] [blame]
Leonid Baraz3e8af4b2020-11-23 19:04:471// 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 Barazea0c6dc2021-11-02 20:38:055#ifndef COMPONENTS_REPORTING_RESOURCES_MEMORY_RESOURCE_IMPL_H_
6#define COMPONENTS_REPORTING_RESOURCES_MEMORY_RESOURCE_IMPL_H_
Leonid Baraz3e8af4b2020-11-23 19:04:477
8#include <atomic>
9#include <cstdint>
10
Leonid Barazea0c6dc2021-11-02 20:38:0511#include "components/reporting/resources/resource_interface.h"
Leonid Baraz3e8af4b2020-11-23 19:04:4712
13namespace 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.
18class MemoryResourceImpl : public ResourceInterface {
19 public:
Leonid Baraz960ea8f2022-05-17 01:01:0620 explicit MemoryResourceImpl(uint64_t total_size);
Leonid Baraz3e8af4b2020-11-23 19:04:4721
22 // Implementation of ResourceInterface methods.
Zach Trudof1bf7ce2020-12-22 21:46:1523 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 Baraz3e8af4b2020-11-23 19:04:4728
29 private:
Leonid Baraz960ea8f2022-05-17 01:01:0630 ~MemoryResourceImpl() override;
31
Zach Trudof1bf7ce2020-12-22 21:46:1532 uint64_t total_;
Leonid Baraz960ea8f2022-05-17 01:01:0633 std::atomic<uint64_t> used_{0};
Leonid Baraz3e8af4b2020-11-23 19:04:4734};
35
36} // namespace reporting
37
Leonid Barazea0c6dc2021-11-02 20:38:0538#endif // COMPONENTS_REPORTING_RESOURCES_MEMORY_RESOURCE_IMPL_H_