| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 1 | // Copyright 2022 The Chromium Authors |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| Sorin Jianu | 6badd00 | 2024-01-11 17:29:02 | [diff] [blame] | 5 | #include "chrome/updater/installer.h" |
| 6 | |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 7 | #include <optional> |
| Allan Kerr | 901b3fd | 2024-10-08 18:13:51 | [diff] [blame] | 8 | #include <string> |
| Sorin Jianu | a4b3d38 | 2023-11-10 20:08:46 | [diff] [blame] | 9 | |
| Allan Kerr | 901b3fd | 2024-10-08 18:13:51 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 11 | #include "base/files/file_util.h" |
| 12 | #include "base/logging.h" |
| 13 | #include "base/process/launch.h" |
| Noah Rose Ledesma | b872710a | 2023-03-16 21:16:01 | [diff] [blame] | 14 | #include "base/strings/string_split.h" |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
| Allan Kerr | 901b3fd | 2024-10-08 18:13:51 | [diff] [blame] | 16 | #include "base/version.h" |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 17 | #include "chrome/updater/constants.h" |
| Allan Kerr | 901b3fd | 2024-10-08 18:13:51 | [diff] [blame] | 18 | #include "chrome/updater/updater_scope.h" |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 19 | |
| 20 | namespace updater { |
| 21 | |
| Sorin Jianu | 7c2d13c5 | 2024-08-28 19:41:48 | [diff] [blame] | 22 | InstallerResult RunApplicationInstaller( |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 23 | const AppInfo& app_info, |
| 24 | const base::FilePath& installer_path, |
| 25 | const std::string& arguments, |
| Sorin Jianu | 9085ad7f | 2024-10-16 21:57:32 | [diff] [blame] | 26 | std::optional<base::FilePath> install_data_file, |
| Joshua Pawlicki | 79e7b28 | 2023-02-02 19:03:09 | [diff] [blame] | 27 | bool usage_stats_enabled, |
| Sorin Jianu | fc8f6957 | 2024-10-03 20:54:13 | [diff] [blame] | 28 | base::TimeDelta timeout, |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 29 | InstallProgressCallback /*progress_callback*/) { |
| 30 | base::LaunchOptions options; |
| 31 | if (install_data_file) { |
| 32 | options.environment.emplace(base::ToUpperASCII(kInstallerDataSwitch), |
| 33 | install_data_file->value()); |
| 34 | } |
| 35 | |
| 36 | base::SetPosixFilePermissions(installer_path, |
| 37 | base::FILE_PERMISSION_USER_MASK | |
| 38 | base::FILE_PERMISSION_GROUP_MASK | |
| 39 | base::FILE_PERMISSION_READ_BY_OTHERS | |
| 40 | base::FILE_PERMISSION_EXECUTE_BY_OTHERS); |
| 41 | |
| 42 | base::CommandLine command(installer_path); |
| Noah Rose Ledesma | b872710a | 2023-03-16 21:16:01 | [diff] [blame] | 43 | std::vector<std::string> arg_vec = |
| 44 | base::SplitString(arguments, base::kWhitespaceASCII, |
| 45 | base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 46 | for (const std::string& arg : arg_vec) { |
| 47 | command.AppendArg(arg); |
| 48 | } |
| 49 | |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 50 | int exit_code = 0; |
| S. Ganesh | 51b1ba8 | 2024-08-12 18:31:15 | [diff] [blame] | 51 | const base::Process process = base::LaunchProcess(command, options); |
| 52 | if (!process.IsValid() || |
| 53 | !process.WaitForExitWithTimeout(timeout, &exit_code)) { |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 54 | LOG(ERROR) << "Could not launch application installer."; |
| Sorin Jianu | 7c2d13c5 | 2024-08-28 19:41:48 | [diff] [blame] | 55 | return InstallerResult(kErrorApplicationInstallerFailed, |
| 56 | kErrorProcessLaunchFailed); |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 57 | } |
| 58 | if (exit_code != 0) { |
| 59 | LOG(ERROR) << "Installer returned error code " << exit_code; |
| Sorin Jianu | 7c2d13c5 | 2024-08-28 19:41:48 | [diff] [blame] | 60 | return InstallerResult(kErrorApplicationInstallerFailed, exit_code); |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 61 | } |
| 62 | |
| Sorin Jianu | 7c2d13c5 | 2024-08-28 19:41:48 | [diff] [blame] | 63 | return InstallerResult(); |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 64 | } |
| 65 | |
| Joshua Pawlicki | fc0a025 | 2023-10-16 23:29:42 | [diff] [blame] | 66 | std::string LookupString(const base::FilePath& path, |
| 67 | const std::string& keyname, |
| 68 | const std::string& default_value) { |
| 69 | return default_value; |
| 70 | } |
| 71 | |
| Allan Kerr | 901b3fd | 2024-10-08 18:13:51 | [diff] [blame] | 72 | base::Version LookupVersion(UpdaterScope scope, |
| 73 | const std::string& app_id, |
| 74 | const base::FilePath& version_path, |
| 75 | const std::string& version_key, |
| Joshua Pawlicki | fc0a025 | 2023-10-16 23:29:42 | [diff] [blame] | 76 | const base::Version& default_value) { |
| 77 | return default_value; |
| 78 | } |
| 79 | |
| Noah Rose Ledesma | 15176773 | 2022-12-07 23:01:47 | [diff] [blame] | 80 | } // namespace updater |