blob: 5da7179d809b51cb0c4f4db185c74281dcaeb212 [file] [log] [blame]
Noah Rose Ledesma151767732022-12-07 23:01:471// 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 Jianu6badd002024-01-11 17:29:025#include "chrome/updater/installer.h"
6
Sorin Jianua4b3d382023-11-10 20:08:467#include <optional>
Allan Kerr901b3fd2024-10-08 18:13:518#include <string>
Sorin Jianua4b3d382023-11-10 20:08:469
Allan Kerr901b3fd2024-10-08 18:13:5110#include "base/files/file_path.h"
Noah Rose Ledesma151767732022-12-07 23:01:4711#include "base/files/file_util.h"
12#include "base/logging.h"
13#include "base/process/launch.h"
Noah Rose Ledesmab872710a2023-03-16 21:16:0114#include "base/strings/string_split.h"
Noah Rose Ledesma151767732022-12-07 23:01:4715#include "base/strings/string_util.h"
Allan Kerr901b3fd2024-10-08 18:13:5116#include "base/version.h"
Noah Rose Ledesma151767732022-12-07 23:01:4717#include "chrome/updater/constants.h"
Allan Kerr901b3fd2024-10-08 18:13:5118#include "chrome/updater/updater_scope.h"
Noah Rose Ledesma151767732022-12-07 23:01:4719
20namespace updater {
21
Sorin Jianu7c2d13c52024-08-28 19:41:4822InstallerResult RunApplicationInstaller(
Noah Rose Ledesma151767732022-12-07 23:01:4723 const AppInfo& app_info,
24 const base::FilePath& installer_path,
25 const std::string& arguments,
Sorin Jianu9085ad7f2024-10-16 21:57:3226 std::optional<base::FilePath> install_data_file,
Joshua Pawlicki79e7b282023-02-02 19:03:0927 bool usage_stats_enabled,
Sorin Jianufc8f69572024-10-03 20:54:1328 base::TimeDelta timeout,
Noah Rose Ledesma151767732022-12-07 23:01:4729 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 Ledesmab872710a2023-03-16 21:16:0143 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 Ledesma151767732022-12-07 23:01:4750 int exit_code = 0;
S. Ganesh51b1ba82024-08-12 18:31:1551 const base::Process process = base::LaunchProcess(command, options);
52 if (!process.IsValid() ||
53 !process.WaitForExitWithTimeout(timeout, &exit_code)) {
Noah Rose Ledesma151767732022-12-07 23:01:4754 LOG(ERROR) << "Could not launch application installer.";
Sorin Jianu7c2d13c52024-08-28 19:41:4855 return InstallerResult(kErrorApplicationInstallerFailed,
56 kErrorProcessLaunchFailed);
Noah Rose Ledesma151767732022-12-07 23:01:4757 }
58 if (exit_code != 0) {
59 LOG(ERROR) << "Installer returned error code " << exit_code;
Sorin Jianu7c2d13c52024-08-28 19:41:4860 return InstallerResult(kErrorApplicationInstallerFailed, exit_code);
Noah Rose Ledesma151767732022-12-07 23:01:4761 }
62
Sorin Jianu7c2d13c52024-08-28 19:41:4863 return InstallerResult();
Noah Rose Ledesma151767732022-12-07 23:01:4764}
65
Joshua Pawlickifc0a0252023-10-16 23:29:4266std::string LookupString(const base::FilePath& path,
67 const std::string& keyname,
68 const std::string& default_value) {
69 return default_value;
70}
71
Allan Kerr901b3fd2024-10-08 18:13:5172base::Version LookupVersion(UpdaterScope scope,
73 const std::string& app_id,
74 const base::FilePath& version_path,
75 const std::string& version_key,
Joshua Pawlickifc0a0252023-10-16 23:29:4276 const base::Version& default_value) {
77 return default_value;
78}
79
Noah Rose Ledesma151767732022-12-07 23:01:4780} // namespace updater