Sergei Datsenko | 1d2cbf8 | 2020-12-08 21:54:42 +1100 | [diff] [blame] | 1 | // Copyright 2020 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 CROS_DISKS_ARCHIVE_MOUNTER_H_ |
| 6 | #define CROS_DISKS_ARCHIVE_MOUNTER_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "cros-disks/fuse_mounter.h" |
| 13 | |
| 14 | namespace cros_disks { |
| 15 | |
| 16 | class Metrics; |
| 17 | |
| 18 | // An implementation of FUSEMounter tailored for mounting archives. |
| 19 | class ArchiveMounter : public FUSEMounter { |
| 20 | public: |
| 21 | static constexpr char kChromeNamespace[] = "/run/namespaces/mnt_chrome"; |
| 22 | |
| 23 | ArchiveMounter(const Platform* platform, |
| 24 | brillo::ProcessReaper* process_reaper, |
| 25 | std::string archive_type, |
| 26 | Metrics* metrics, |
| 27 | std::string metrics_name, |
| 28 | std::vector<int> password_needed_exit_codes, |
| 29 | std::unique_ptr<SandboxedProcessFactory> sandbox_factory); |
| 30 | ArchiveMounter(const ArchiveMounter&) = delete; |
| 31 | ArchiveMounter& operator=(const ArchiveMounter&) = delete; |
| 32 | |
| 33 | ~ArchiveMounter() override; |
| 34 | |
| 35 | bool CanMount(const std::string& source, |
| 36 | const std::vector<std::string>& params, |
| 37 | base::FilePath* suggested_dir_name) const override; |
| 38 | |
Sergei Datsenko | 87c49bb | 2021-01-13 15:08:07 +1100 | [diff] [blame] | 39 | OwnerUser GetDaemonUser() const; |
| 40 | |
Sergei Datsenko | 1d2cbf8 | 2020-12-08 21:54:42 +1100 | [diff] [blame] | 41 | protected: |
| 42 | // FUSEMounter overrides: |
| 43 | MountErrorType InterpretReturnCode(int return_code) const override; |
| 44 | |
| 45 | std::unique_ptr<SandboxedProcess> PrepareSandbox( |
| 46 | const std::string& source, |
| 47 | const base::FilePath& target_path, |
| 48 | std::vector<std::string> params, |
| 49 | MountErrorType* error) const final; |
| 50 | |
| 51 | virtual MountErrorType FormatInvocationCommand( |
| 52 | const base::FilePath& archive, |
| 53 | std::vector<std::string> params, |
| 54 | SandboxedProcess* sandbox) const; |
| 55 | |
| 56 | private: |
| 57 | const std::string archive_type_; |
| 58 | const std::string extension_; |
| 59 | Metrics* const metrics_; |
| 60 | const std::string metrics_name_; |
| 61 | const std::vector<int> password_needed_exit_codes_; |
| 62 | const std::unique_ptr<SandboxedProcessFactory> sandbox_factory_; |
| 63 | |
| 64 | friend class ArchiveMounterTest; |
| 65 | }; |
| 66 | |
| 67 | } // namespace cros_disks |
| 68 | |
| 69 | #endif // CROS_DISKS_ARCHIVE_MOUNTER_H_ |