Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 1 | // Copyright 2016 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. |
Greg Kerr | 2f76fde | 2016-08-29 16:39:45 -0700 | [diff] [blame] | 4 | #ifndef IMAGELOADER_IMAGELOADER_IMPL_H_ |
| 5 | #define IMAGELOADER_IMAGELOADER_IMPL_H_ |
Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 6 | |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include <base/files/file_path.h> |
| 11 | #include <base/gtest_prod_util.h> |
| 12 | #include <base/macros.h> |
| 13 | |
Greg Kerr | 9944e24 | 2017-01-26 15:09:31 -0800 | [diff] [blame] | 14 | #include "helper_process.h" |
Greg Kerr | 89be05f | 2016-07-27 10:40:32 -0700 | [diff] [blame] | 15 | |
Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 16 | namespace imageloader { |
| 17 | |
| 18 | struct ImageLoaderConfig { |
Greg Kerr | 89be05f | 2016-07-27 10:40:32 -0700 | [diff] [blame] | 19 | ImageLoaderConfig(const std::vector<uint8_t> key, const char* storage_path, |
Greg Kerr | 9944e24 | 2017-01-26 15:09:31 -0800 | [diff] [blame] | 20 | const char* mount_path) |
Greg Kerr | 89be05f | 2016-07-27 10:40:32 -0700 | [diff] [blame] | 21 | : key(key), |
| 22 | storage_dir(storage_path), |
Greg Kerr | 9944e24 | 2017-01-26 15:09:31 -0800 | [diff] [blame] | 23 | mount_path(mount_path) {} |
Greg Kerr | 89be05f | 2016-07-27 10:40:32 -0700 | [diff] [blame] | 24 | |
Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 25 | std::vector<uint8_t> key; |
| 26 | base::FilePath storage_dir; |
Greg Kerr | 89be05f | 2016-07-27 10:40:32 -0700 | [diff] [blame] | 27 | base::FilePath mount_path; |
Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | class ImageLoaderImpl { |
| 31 | public: |
| 32 | // Instantiate an object with a configuration object. |
Greg Kerr | 89be05f | 2016-07-27 10:40:32 -0700 | [diff] [blame] | 33 | explicit ImageLoaderImpl(ImageLoaderConfig config) |
| 34 | : config_(std::move(config)) {} |
Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 35 | |
| 36 | // Register a component. |
| 37 | bool RegisterComponent(const std::string& name, const std::string& version, |
| 38 | const std::string& component_folder_abs_path); |
| 39 | |
| 40 | // Get component version given component name. |
| 41 | std::string GetComponentVersion(const std::string& name); |
| 42 | |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 43 | // Load the specified component. This returns the mount point or an empty |
| 44 | // string on failure. |
Greg Kerr | 9944e24 | 2017-01-26 15:09:31 -0800 | [diff] [blame] | 45 | std::string LoadComponent(const std::string& name, HelperProcess* process); |
Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 46 | |
Greg Kerr | c5b9169 | 2016-09-14 12:09:22 -0700 | [diff] [blame] | 47 | // Load the specified component at a set mount point. |
Greg Kerr | 9944e24 | 2017-01-26 15:09:31 -0800 | [diff] [blame] | 48 | bool LoadComponent(const std::string& name, const std::string& mount_point, |
| 49 | HelperProcess* process); |
Greg Kerr | c5b9169 | 2016-09-14 12:09:22 -0700 | [diff] [blame] | 50 | |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 51 | // The directory hierarchy for a component consists of the storage_root (i.e. |
| 52 | // `/var/lib/imageloader`), the component_root |
| 53 | // (`/var/lib/imageloader/ComponentName`), and the version folder (i.e. |
| 54 | // `/var/lib/imageloader/ComponentName/23.0.0.205`). That is: |
| 55 | // [storage_root]/ |
| 56 | // [storage_root]/[component_root] |
| 57 | // [storage_root]/[component_root]/[version] |
| 58 | // |
| 59 | // Inside the `component_root` there is a current version hint file: |
| 60 | // [storage_root]/[component_root]/latest-version |
| 61 | |
| 62 | // Return the path to latest-version file for |component_name|. |
| 63 | base::FilePath GetLatestVersionFilePath(const std::string& component_name); |
| 64 | |
| 65 | // Return the path to the [component_root] folder for |component_name|. |
| 66 | base::FilePath GetComponentRoot(const std::string& component_name); |
| 67 | |
| 68 | // Return the path to a given version of |component_name|. |
| 69 | base::FilePath GetVersionPath(const std::string& component_name, |
| 70 | const std::string& version); |
| 71 | |
| 72 | // Return the path to the current version of |component_name|. |
| 73 | bool GetPathToCurrentComponentVersion(const std::string& component_name, |
| 74 | base::FilePath* result); |
| 75 | |
Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 76 | private: |
Greg Kerr | a6c0c52 | 2016-07-25 11:15:31 -0700 | [diff] [blame] | 77 | // The configuration traits. |
| 78 | ImageLoaderConfig config_; |
| 79 | |
| 80 | DISALLOW_COPY_AND_ASSIGN(ImageLoaderImpl); |
| 81 | }; |
| 82 | |
| 83 | } // namespace imageloader |
| 84 | |
Greg Kerr | 2f76fde | 2016-08-29 16:39:45 -0700 | [diff] [blame] | 85 | #endif // IMAGELOADER_IMAGELOADER_IMPL_H_ |