blob: 0711734f4deeec642babb29856d39a46424f4596 [file] [log] [blame]
Greg Kerra6c0c522016-07-25 11:15:31 -07001// 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 Kerr2f76fde2016-08-29 16:39:45 -07004#ifndef IMAGELOADER_IMAGELOADER_IMPL_H_
5#define IMAGELOADER_IMAGELOADER_IMPL_H_
Greg Kerra6c0c522016-07-25 11:15:31 -07006
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 Kerr9944e242017-01-26 15:09:31 -080014#include "helper_process.h"
Greg Kerr89be05f2016-07-27 10:40:32 -070015
Greg Kerra6c0c522016-07-25 11:15:31 -070016namespace imageloader {
17
Eric Caruso0b79bc82017-03-21 13:44:34 -070018using Keys = std::vector<std::vector<uint8_t>>;
19
Greg Kerra6c0c522016-07-25 11:15:31 -070020struct ImageLoaderConfig {
Eric Caruso0b79bc82017-03-21 13:44:34 -070021 ImageLoaderConfig(const Keys& keys, const char* storage_path,
Greg Kerr9944e242017-01-26 15:09:31 -080022 const char* mount_path)
Eric Caruso0b79bc82017-03-21 13:44:34 -070023 : keys(keys),
Greg Kerr89be05f2016-07-27 10:40:32 -070024 storage_dir(storage_path),
Greg Kerr9944e242017-01-26 15:09:31 -080025 mount_path(mount_path) {}
Greg Kerr89be05f2016-07-27 10:40:32 -070026
Eric Caruso0b79bc82017-03-21 13:44:34 -070027 Keys keys;
Greg Kerra6c0c522016-07-25 11:15:31 -070028 base::FilePath storage_dir;
Greg Kerr89be05f2016-07-27 10:40:32 -070029 base::FilePath mount_path;
Greg Kerra6c0c522016-07-25 11:15:31 -070030};
31
32class ImageLoaderImpl {
33 public:
34 // Instantiate an object with a configuration object.
Greg Kerr89be05f2016-07-27 10:40:32 -070035 explicit ImageLoaderImpl(ImageLoaderConfig config)
36 : config_(std::move(config)) {}
Greg Kerra6c0c522016-07-25 11:15:31 -070037
38 // Register a component.
39 bool RegisterComponent(const std::string& name, const std::string& version,
40 const std::string& component_folder_abs_path);
41
42 // Get component version given component name.
43 std::string GetComponentVersion(const std::string& name);
44
Greg Kerr019d59c2016-11-17 14:28:49 -080045 // Load the specified component. This returns the mount point or an empty
46 // string on failure.
Greg Kerr9944e242017-01-26 15:09:31 -080047 std::string LoadComponent(const std::string& name, HelperProcess* process);
Greg Kerra6c0c522016-07-25 11:15:31 -070048
Greg Kerrc5b91692016-09-14 12:09:22 -070049 // Load the specified component at a set mount point.
Greg Kerr9944e242017-01-26 15:09:31 -080050 bool LoadComponent(const std::string& name, const std::string& mount_point,
51 HelperProcess* process);
Greg Kerrc5b91692016-09-14 12:09:22 -070052
Greg Kerr019d59c2016-11-17 14:28:49 -080053 // The directory hierarchy for a component consists of the storage_root (i.e.
54 // `/var/lib/imageloader`), the component_root
55 // (`/var/lib/imageloader/ComponentName`), and the version folder (i.e.
56 // `/var/lib/imageloader/ComponentName/23.0.0.205`). That is:
57 // [storage_root]/
58 // [storage_root]/[component_root]
59 // [storage_root]/[component_root]/[version]
60 //
61 // Inside the `component_root` there is a current version hint file:
62 // [storage_root]/[component_root]/latest-version
63
64 // Return the path to latest-version file for |component_name|.
65 base::FilePath GetLatestVersionFilePath(const std::string& component_name);
66
67 // Return the path to the [component_root] folder for |component_name|.
68 base::FilePath GetComponentRoot(const std::string& component_name);
69
70 // Return the path to a given version of |component_name|.
71 base::FilePath GetVersionPath(const std::string& component_name,
72 const std::string& version);
73
74 // Return the path to the current version of |component_name|.
75 bool GetPathToCurrentComponentVersion(const std::string& component_name,
76 base::FilePath* result);
77
Greg Kerra6c0c522016-07-25 11:15:31 -070078 private:
Greg Kerra6c0c522016-07-25 11:15:31 -070079 // The configuration traits.
80 ImageLoaderConfig config_;
81
82 DISALLOW_COPY_AND_ASSIGN(ImageLoaderImpl);
83};
84
85} // namespace imageloader
86
Greg Kerr2f76fde2016-08-29 16:39:45 -070087#endif // IMAGELOADER_IMAGELOADER_IMPL_H_