-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaemon.h
82 lines (63 loc) · 2.71 KB
/
daemon.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SPACED_DAEMON_H_
#define SPACED_DAEMON_H_
#include <algorithm>
#include <memory>
#include <string>
#include <base/files/scoped_file.h>
#include <base/task/task_runner.h>
#include <brillo/daemons/dbus_daemon.h>
#include <brillo/blkdev_utils/lvm.h>
#include <spaced/proto_bindings/spaced.pb.h>
#include "spaced/calculator/stateful_free_space_calculator.h"
#include "spaced/dbus_adaptors/org.chromium.Spaced.h"
#include "spaced/disk_usage.h"
namespace spaced {
class DBusAdaptor : public org::chromium::SpacedInterface,
public org::chromium::SpacedAdaptor {
public:
explicit DBusAdaptor(scoped_refptr<dbus::Bus> bus);
DBusAdaptor(const DBusAdaptor&) = delete;
DBusAdaptor& operator=(const DBusAdaptor&) = delete;
~DBusAdaptor() override = default;
void RegisterAsync(
brillo::dbus_utils::AsyncEventSequencer::CompletionAction cb);
int64_t GetFreeDiskSpace(const std::string& path) override;
int64_t GetTotalDiskSpace(const std::string& path) override;
int64_t GetRootDeviceSize() override;
bool IsQuotaSupported(const std::string& path) override;
int64_t GetQuotaCurrentSpaceForUid(const std::string& path,
uint32_t uid) override;
int64_t GetQuotaCurrentSpaceForGid(const std::string& path,
uint32_t gid) override;
int64_t GetQuotaCurrentSpaceForProjectId(const std::string& path,
uint32_t project_id) override;
SetProjectIdReply SetProjectId(const base::ScopedFD& fd,
uint32_t project_id) override;
SetProjectInheritanceFlagReply SetProjectInheritanceFlag(
const base::ScopedFD& fd, bool enable) override;
void StatefulDiskSpaceUpdateCallback(const StatefulDiskSpaceUpdate& state);
private:
brillo::dbus_utils::DBusObject dbus_object_;
std::unique_ptr<DiskUsageUtil> disk_usage_util_;
// Async. task runner. The calculations are offloaded from the D-Bus thread so
// that slow disk usage calculations do not DoS D-Bus requests into spaced.
scoped_refptr<base::SequencedTaskRunner> task_runner_;
std::unique_ptr<StatefulFreeSpaceCalculator> stateful_free_space_calculator_;
};
class Daemon : public brillo::DBusServiceDaemon {
public:
Daemon();
Daemon(const Daemon&) = delete;
Daemon& operator=(const Daemon&) = delete;
~Daemon() override = default;
protected:
void RegisterDBusObjectsAsync(
brillo::dbus_utils::AsyncEventSequencer* sequencer) override;
private:
std::unique_ptr<DBusAdaptor> adaptor_;
};
} // namespace spaced
#endif // SPACED_DAEMON_H_