Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 1 | // 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 | |
| 13 | namespace mems_setup { |
| 14 | |
| 15 | // This is an implementation detail of the DelegateImpl, but it is made |
| 16 | // visible for testing purposes |
| 17 | bool LoadVpdFromString(const std::string& vpd_data, |
| 18 | std::map<std::string, std::string>* cache); |
| 19 | |
| 20 | class 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 Yang | 06ce00f | 2020-12-01 18:05:23 +0800 | [diff] [blame] | 27 | bool CreateDirectory(const base::FilePath&) override; |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 28 | bool Exists(const base::FilePath&) override; |
| 29 | |
Enrico Granata | 10e19de | 2019-05-21 14:17:36 -0700 | [diff] [blame] | 30 | 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 Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 39 | 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_ |