blob: 6ccd2589e9c33169a3bc7fc6857e252f79f07739 [file] [log] [blame]
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/updater/updater_scope.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "build/build_config.h"
#include "chrome/updater/constants.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#if BUILDFLAG(IS_WIN)
#include "chrome/updater/tag.h"
#include "chrome/updater/util.h"
#include "chrome/updater/win/win_util.h"
#endif
namespace updater {
namespace {
bool IsSystemProcessForCommandLine(const base::CommandLine& command_line) {
return command_line.HasSwitch(kSystemSwitch);
}
} // namespace
UpdaterScope GetUpdaterScopeForCommandLine(
const base::CommandLine& command_line) {
#if BUILDFLAG(IS_WIN)
if (IsSystemProcessForCommandLine(command_line)) {
return UpdaterScope::kSystem;
}
// TODO(crbug.com/1128631): support bundles. For now, assume one app.
const absl::optional<tagging::TagArgs> tag_args =
GetTagArgsForCommandLine(command_line).tag_args;
if (tag_args && !tag_args->apps.empty() &&
tag_args->apps.front().needs_admin) {
DCHECK_EQ(tag_args->apps.size(), size_t{1});
switch (*tag_args->apps.front().needs_admin) {
case tagging::AppArgs::NeedsAdmin::kYes:
return UpdaterScope::kSystem;
case tagging::AppArgs::NeedsAdmin::kNo:
return UpdaterScope::kUser;
case tagging::AppArgs::NeedsAdmin::kPrefers:
return command_line.HasSwitch(kCmdLinePrefersUser)
? UpdaterScope::kUser
: UpdaterScope::kSystem;
}
}
// crbug.com(1214058): consider handling the elevation case by
// calling IsUserAdmin().
return UpdaterScope::kUser;
#else
return IsSystemProcessForCommandLine(command_line) ? UpdaterScope::kSystem
: UpdaterScope::kUser;
#endif
}
UpdaterScope GetUpdaterScope() {
return GetUpdaterScopeForCommandLine(*base::CommandLine::ForCurrentProcess());
}
} // namespace updater