blob: 508d8532d2effda8f982135c0f261a535d27ae32 [file] [log] [blame]
Enrico Granata60b1cbc2019-05-20 11:06:46 -07001// Copyright 2019 The Chromium OS 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
5#ifndef MEMS_SETUP_DELEGATE_IMPL_H_
6#define MEMS_SETUP_DELEGATE_IMPL_H_
7
8#include <map>
9#include <string>
10
11#include "mems_setup/delegate.h"
12
13namespace mems_setup {
14
15// This is an implementation detail of the DelegateImpl, but it is made
16// visible for testing purposes
17bool LoadVpdFromString(const std::string& vpd_data,
18 std::map<std::string, std::string>* cache);
19
20class DelegateImpl : public Delegate {
21 public:
22 DelegateImpl() = default;
23
24 base::Optional<std::string> ReadVpdValue(const std::string& key) override;
25 bool ProbeKernelModule(const std::string& module) override;
26
Harvey Yang06ce00f2020-12-01 18:05:23 +080027 bool CreateDirectory(const base::FilePath&) override;
Enrico Granata60b1cbc2019-05-20 11:06:46 -070028 bool Exists(const base::FilePath&) override;
29
Enrico Granata10e19de2019-05-21 14:17:36 -070030 base::Optional<gid_t> FindGroupId(const char* group) override;
31
32 int GetPermissions(const base::FilePath& path) override;
33 bool SetPermissions(const base::FilePath& path, int mode) override;
34
35 bool SetOwnership(const base::FilePath& path,
36 uid_t user,
37 gid_t group) override;
38
Enrico Granata60b1cbc2019-05-20 11:06:46 -070039 private:
40 void LoadVpdIfNeeded();
41
42 std::map<std::string, std::string> vpd_cache_;
43 bool vpd_loaded_ = false;
44};
45
46} // namespace mems_setup
47
48#endif // MEMS_SETUP_DELEGATE_IMPL_H_