Commit a61c38f1 authored by S. Ganesh's avatar S. Ganesh Committed by Commit Bot

Add base classes for Policy Management in Omaha 4.

This CL adds a PolicyManagerInterface that all future Policy Managers
will support, as well as a DefaultPolicyManager.

Bug: 1068797
Change-Id: Idf70e93a6b084e6a519cb65738f45ed51ecaae29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2140994Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Commit-Queue: S. Ganesh <ganesh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759682}
parent f08b6400
...@@ -43,6 +43,8 @@ if (is_win || is_mac) { ...@@ -43,6 +43,8 @@ if (is_win || is_mac) {
"patcher.h", "patcher.h",
"persisted_data.cc", "persisted_data.cc",
"persisted_data.h", "persisted_data.h",
"policy_manager.cc",
"policy_manager.h",
"prefs.cc", "prefs.cc",
"prefs.h", "prefs.h",
"registration_data.cc", "registration_data.cc",
...@@ -186,6 +188,7 @@ if (is_win || is_mac) { ...@@ -186,6 +188,7 @@ if (is_win || is_mac) {
sources = [ sources = [
"lib_util_unittest.cc", "lib_util_unittest.cc",
"persisted_data_unittest.cc", "persisted_data_unittest.cc",
"policy_manager_unittest.cc",
"prefs_unittest.cc", "prefs_unittest.cc",
"run_all_unittests.cc", "run_all_unittests.cc",
"tag_unittest.cc", "tag_unittest.cc",
......
...@@ -43,4 +43,11 @@ const char kCrashStagingUploadURL[] = ...@@ -43,4 +43,11 @@ const char kCrashStagingUploadURL[] =
const char kAppsDir[] = "apps"; const char kAppsDir[] = "apps";
const char kUninstallScript[] = "uninstall.cmd"; const char kUninstallScript[] = "uninstall.cmd";
// Policy Management constants.
const char kProxyModeDirect[] = "direct";
const char kProxyModeAutoDetect[] = "auto_detect";
const char kProxyModePacScript[] = "pac_script";
const char kProxyModeFixedServers[] = "fixed_servers";
const char kProxyModeSystem[] = "system";
} // namespace updater } // namespace updater
...@@ -146,6 +146,22 @@ constexpr int kErrorMissingRunableFile = kCustomInstallErrorBase + 2; ...@@ -146,6 +146,22 @@ constexpr int kErrorMissingRunableFile = kCustomInstallErrorBase + 2;
// Running the application installer failed. // Running the application installer failed.
constexpr int kErrorApplicationInstallerFailed = kCustomInstallErrorBase + 3; constexpr int kErrorApplicationInstallerFailed = kCustomInstallErrorBase + 3;
// Policy Management constants.
extern const char kProxyModeDirect[];
extern const char kProxyModeAutoDetect[];
extern const char kProxyModePacScript[];
extern const char kProxyModeFixedServers[];
extern const char kProxyModeSystem[];
constexpr int kPolicyDisabled = 0;
constexpr int kPolicyEnabled = 1;
constexpr int kPolicyEnabledMachineOnly = 4;
constexpr int kPolicyManualUpdatesOnly = 2;
constexpr int kPolicyAutomaticUpdatesOnly = 3;
constexpr bool kInstallPolicyDefault = kPolicyEnabled;
constexpr bool kUpdatePolicyDefault = kPolicyEnabled;
} // namespace updater } // namespace updater
#endif // CHROME_UPDATER_CONSTANTS_H_ #endif // CHROME_UPDATER_CONSTANTS_H_
// Copyright 2020 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/policy_manager.h"
namespace updater {
// TODO: crbug 1070833.
// The DefaultPolicyManager is just a stub manager at the moment that returns
// |false| or failure for all methods. This policy manager would be in effect
// when policies are not effective for any other policy manager in the system.
// It is expected that this policy manager will return default values instead of
// failure in the future.
class DefaultPolicyManager : public PolicyManagerInterface {
public:
DefaultPolicyManager();
DefaultPolicyManager(const DefaultPolicyManager&) = delete;
DefaultPolicyManager& operator=(const DefaultPolicyManager&) = delete;
~DefaultPolicyManager() override;
std::string source() override;
bool IsManaged() override;
bool GetLastCheckPeriodMinutes(int* minutes) override;
bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) override;
bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) override;
bool GetPackageCacheExpirationTimeDays(int* cache_life_limit) override;
bool GetEffectivePolicyForAppInstalls(const std::string& app_id,
int* install_policy) override;
bool GetEffectivePolicyForAppUpdates(const std::string& app_id,
int* update_policy) override;
bool GetTargetVersionPrefix(const std::string& app_id,
std::string* target_version_prefix) override;
bool IsRollbackToTargetVersionAllowed(const std::string& app_id,
bool* rollback_allowed) override;
bool GetProxyMode(std::string* proxy_mode) override;
bool GetProxyPacUrl(std::string* proxy_pac_url) override;
bool GetProxyServer(std::string* proxy_server) override;
};
DefaultPolicyManager::DefaultPolicyManager() = default;
DefaultPolicyManager::~DefaultPolicyManager() = default;
bool DefaultPolicyManager::IsManaged() {
return false;
}
std::string DefaultPolicyManager::source() {
return std::string("default");
}
bool DefaultPolicyManager::GetLastCheckPeriodMinutes(int* minutes) {
return false;
}
bool DefaultPolicyManager::GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) {
return false;
}
bool DefaultPolicyManager::GetDownloadPreferenceGroupPolicy(
std::string* download_preference) {
return false;
}
bool DefaultPolicyManager::GetPackageCacheSizeLimitMBytes(
int* cache_size_limit) {
return false;
}
bool DefaultPolicyManager::GetPackageCacheExpirationTimeDays(
int* cache_life_limit) {
return false;
}
bool DefaultPolicyManager::GetEffectivePolicyForAppInstalls(
const std::string& app_id,
int* install_policy) {
return false;
}
bool DefaultPolicyManager::GetEffectivePolicyForAppUpdates(
const std::string& app_id,
int* update_policy) {
return false;
}
bool DefaultPolicyManager::GetTargetVersionPrefix(
const std::string& app_id,
std::string* target_version_prefix) {
return false;
}
bool DefaultPolicyManager::IsRollbackToTargetVersionAllowed(
const std::string& app_id,
bool* rollback_allowed) {
return false;
}
bool DefaultPolicyManager::GetProxyMode(std::string* proxy_mode) {
return false;
}
bool DefaultPolicyManager::GetProxyPacUrl(std::string* proxy_pac_url) {
return false;
}
bool DefaultPolicyManager::GetProxyServer(std::string* proxy_server) {
return false;
}
std::unique_ptr<PolicyManagerInterface> GetPolicyManager() {
return std::make_unique<DefaultPolicyManager>();
}
} // namespace updater
// Copyright 2020 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.
#ifndef CHROME_UPDATER_POLICY_MANAGER_H_
#define CHROME_UPDATER_POLICY_MANAGER_H_
#include <memory>
#include <string>
namespace updater {
// The Policy Manager Interface is implemented by policy managers such as Group
// Policy and Device Management.
class PolicyManagerInterface {
public:
virtual ~PolicyManagerInterface() = default;
// This is human-readable string that indicates the policy manager being
// queried.
virtual std::string source() = 0;
// This method returns |true| if the current policy manager determines that
// its policies are operational. For instance, the Device Management Policy
// Manager will return |true| for this method if the machine is joined to
// a DM server.
virtual bool IsManaged() = 0;
// Returns the policy for how often the Updater should check for updates.
// Returns the time interval between update checks in minutes.
// 0 indicates updates are disabled.
virtual bool GetLastCheckPeriodMinutes(int* minutes) = 0;
// For domain-joined machines, checks the current time against the times that
// updates are suppressed. Updates are suppressed if the current time falls
// between the start time and the duration.
// The duration does not account for daylight savings time. For instance, if
// the start time is 22:00 hours, and with a duration of 8 hours, the updates
// will be suppressed for 8 hours regardless of whether daylight savings time
// changes happen in between.
virtual bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) = 0;
// Returns the policy for the download preference.
virtual bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) = 0;
// Returns the policy for the package cache size limit in megabytes.
virtual bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) = 0;
// Returns the policy for the package cache expiration in days.
virtual bool GetPackageCacheExpirationTimeDays(int* cache_life_limit) = 0;
// Returns kPolicyEnabled if installation of the specified app is allowed.
// Otherwise, returns kPolicyDisabled.
virtual bool GetEffectivePolicyForAppInstalls(const std::string& app_id,
int* install_policy) = 0;
// Returns kPolicyEnabled if updates of the specified app is allowed.
// Otherwise, returns one of kPolicyDisabled, kPolicyManualUpdatesOnly, or
// kPolicyAutomaticUpdatesOnly.
virtual bool GetEffectivePolicyForAppUpdates(const std::string& app_id,
int* update_policy) = 0;
// Returns the target version prefix for the app.
// Examples:
// * "" (or not configured): update to latest version available.
// * "55.": update to any minor version of 55 (e.g. 55.24.34 or 55.60.2).
// * "55.2.": update to any minor version of 55.2 (e.g. 55.2.34 or 55.2.2).
// * "55.24.34": update to this specific version only.
virtual bool GetTargetVersionPrefix(const std::string& app_id,
std::string* target_version_prefix) = 0;
// Returns whether the RollbackToTargetVersion policy has been set for the
// app. If RollbackToTargetVersion is set, the TargetVersionPrefix policy
// governs the version to rollback clients with higher versions to.
virtual bool IsRollbackToTargetVersionAllowed(const std::string& app_id,
bool* rollback_allowed) = 0;
// Returns a proxy mode such as |auto_detect|.
virtual bool GetProxyMode(std::string* proxy_mode) = 0;
// Returns a proxy PAC URL.
virtual bool GetProxyPacUrl(std::string* proxy_pac_url) = 0;
// Returns a proxy server.
virtual bool GetProxyServer(std::string* proxy_server) = 0;
};
std::unique_ptr<PolicyManagerInterface> GetPolicyManager();
} // namespace updater
#endif // CHROME_UPDATER_POLICY_MANAGER_H_
// Copyright 2020 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/policy_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace updater {
TEST(PolicyManager, GetPolicyManager) {
std::unique_ptr<PolicyManagerInterface> policy_manager(GetPolicyManager());
ASSERT_FALSE(policy_manager->IsManaged());
}
} // namespace updater
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment