1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// Copyright 2020 The Chromium Authors
// 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 <optional>
#include <string>
#include <vector>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/time/time.h"
#include "chrome/updater/constants.h"
namespace updater {
// 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.
class UpdatesSuppressedTimes {
public:
friend constexpr bool operator==(const UpdatesSuppressedTimes&,
const UpdatesSuppressedTimes&) = default;
bool valid() const;
// Returns true if and only if the `hour`:`minute` wall clock time falls
// within this suppression period.
bool contains(int hour, int minute) const;
int start_hour_ = kPolicyNotSet;
int start_minute_ = kPolicyNotSet;
int duration_minute_ = kPolicyNotSet;
};
// The Policy Manager Interface is implemented by policy managers such as Group
// Policy and Device Management.
class PolicyManagerInterface
: public base::RefCountedThreadSafe<PolicyManagerInterface> {
public:
// This is human-readable string that indicates the policy manager being
// queried.
virtual std::string source() const = 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 HasActiveDevicePolicies() const = 0;
// Whether the cloud policy overrides the platform policy.
// This policy affects Windows only.
// The policy value from device management provider takes precedence if this
// policy has conflict values.
virtual std::optional<bool> CloudPolicyOverridesPlatformPolicy() const = 0;
// Returns the policy for how often the Updater should check for updates.
// Returns the time interval between update checks.
// 0 indicates updates are disabled.
virtual std::optional<base::TimeDelta> GetLastCheckPeriod() const = 0;
// For domain-joined machines, checks the current time against the times that
// updates are suppressed.
virtual std::optional<UpdatesSuppressedTimes> GetUpdatesSuppressedTimes()
const = 0;
// Returns the policy for the download preference.
virtual std::optional<std::string> GetDownloadPreference() const = 0;
// Returns the policy for the package cache size limit in megabytes.
virtual std::optional<int> GetPackageCacheSizeLimitMBytes() const = 0;
// Returns the policy for the package cache expiration in days.
virtual std::optional<int> GetPackageCacheExpirationTimeDays() const = 0;
// Returns kPolicyEnabled if installation of the specified app is allowed.
// Otherwise, returns kPolicyDisabled.
virtual std::optional<int> GetEffectivePolicyForAppInstalls(
const std::string& app_id) const = 0;
// Returns kPolicyEnabled if updates of the specified app is allowed.
// Otherwise, returns one of kPolicyDisabled, kPolicyManualUpdatesOnly, or
// kPolicyAutomaticUpdatesOnly.
virtual std::optional<int> GetEffectivePolicyForAppUpdates(
const std::string& app_id) const = 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 std::optional<std::string> GetTargetVersionPrefix(
const std::string& app_id) const = 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 std::optional<bool> IsRollbackToTargetVersionAllowed(
const std::string& app_id) const = 0;
// Returns one of kPolicyRolloutDefault, kPolicyRolloutFast, or
// kPolicyRolloutSlow, indicating the preference for participating in app
// gradual rollouts, skipping gradual rollouts, or holding back from gradual
// rollouts, respectively. Applies to major revisions of apps only.
virtual std::optional<int> GetMajorVersionRolloutPolicy(
const std::string& app_id) const = 0;
// Returns one of kPolicyRolloutDefault, kPolicyRolloutFast, or
// kPolicyRolloutSlow, indicating the preference for participating in app
// gradual rollouts, skipping gradual rollouts, or holding back from gradual
// rollouts, respectively. Applies to minor revisions of apps only.
virtual std::optional<int> GetMinorVersionRolloutPolicy(
const std::string& app_id) const = 0;
// Returns a proxy mode such as |auto_detect|.
virtual std::optional<std::string> GetProxyMode() const = 0;
// Returns a proxy PAC URL.
virtual std::optional<std::string> GetProxyPacUrl() const = 0;
// Returns a proxy server.
virtual std::optional<std::string> GetProxyServer() const = 0;
// Returns a channel, for example {stable|beta|dev}.
virtual std::optional<std::string> GetTargetChannel(
const std::string& app_id) const = 0;
// Returns a list of apps that need to be downloaded and installed by the
// updater.
virtual std::optional<std::vector<std::string>> GetForceInstallApps()
const = 0;
// Returns all apps that have some policy set.
virtual std::optional<std::vector<std::string>> GetAppsWithPolicy() const = 0;
protected:
friend class base::RefCountedThreadSafe<PolicyManagerInterface>;
virtual ~PolicyManagerInterface() = default;
};
scoped_refptr<PolicyManagerInterface> GetDefaultValuesPolicyManager();
} // namespace updater
#endif // CHROME_UPDATER_POLICY_MANAGER_H_
|