Commit e1da12a7 authored by Xiaoling Bao's avatar Xiaoling Bao Committed by Commit Bot

Enable policy status query for chrome://policy page.

Changes:
1) Add policy providers even when they are not active (to show potential policy conflict)
2) Returns caller the optional policy status (source of a policy, conflict etc),

Bug: 1141124
Change-Id: I90356ac7c0ec376fed8cd57a1c7dbcc76a0c7814
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490275Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Commit-Queue: Xiaoling Bao <xiaolingbao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824150}
parent 7a322ca1
......@@ -194,6 +194,7 @@ extern const char kProxyModeSystem[];
extern const char kDownloadPreferenceCacheable[];
constexpr int kPolicyNotSet = -1;
constexpr int kPolicyDisabled = 0;
constexpr int kPolicyEnabled = 1;
constexpr int kPolicyEnabledMachineOnly = 4;
......
......@@ -8,6 +8,7 @@
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "chrome/updater/constants.h"
#include "chrome/updater/policy_manager.h"
namespace updater {
......@@ -69,9 +70,8 @@ bool DMPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const {
return true;
}
bool DMPolicyManager::GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const {
bool DMPolicyManager::GetUpdatesSuppressedTimes(
UpdatesSuppressedTimes* suppressed_times) const {
if (!omaha_settings_.has_updates_suppressed())
return false;
......@@ -81,9 +81,9 @@ bool DMPolicyManager::GetUpdatesSuppressedTimes(int* start_hour,
!updates_suppressed.has_duration_min())
return false;
*start_hour = updates_suppressed.start_hour();
*start_min = updates_suppressed.start_minute();
*duration_min = updates_suppressed.duration_min();
suppressed_times->start_hour = updates_suppressed.start_hour();
suppressed_times->start_minute = updates_suppressed.start_minute();
suppressed_times->duration_minute = updates_suppressed.duration_min();
return true;
}
......
......@@ -29,9 +29,8 @@ class DMPolicyManager : public PolicyManagerInterface {
bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const override;
bool GetUpdatesSuppressedTimes(
UpdatesSuppressedTimes* suppressed_times) const override;
bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override;
bool GetProxyMode(std::string* proxy_mode) const override;
......
......@@ -114,11 +114,8 @@ TEST(DMPolicyManager, PolicyManagerFromEmptyProto) {
EXPECT_FALSE(
policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes));
int start_hour = 0;
int start_minute = 0;
int duration_minute = 0;
EXPECT_FALSE(policy_manager->GetUpdatesSuppressedTimes(
&start_hour, &start_minute, &duration_minute));
UpdatesSuppressedTimes suppressed_times;
EXPECT_FALSE(policy_manager->GetUpdatesSuppressedTimes(&suppressed_times));
std::string download_preference;
EXPECT_FALSE(
......@@ -192,14 +189,11 @@ TEST(DMPolicyManager, PolicyManagerFromProto) {
policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes));
EXPECT_EQ(last_check_period_minutes, 111);
int start_hour = 0;
int start_minute = 0;
int duration_minute = 0;
EXPECT_TRUE(policy_manager->GetUpdatesSuppressedTimes(
&start_hour, &start_minute, &duration_minute));
EXPECT_EQ(start_hour, 9);
EXPECT_EQ(start_minute, 30);
EXPECT_EQ(duration_minute, 120);
UpdatesSuppressedTimes suppressed_times;
EXPECT_TRUE(policy_manager->GetUpdatesSuppressedTimes(&suppressed_times));
EXPECT_EQ(suppressed_times.start_hour, 9);
EXPECT_EQ(suppressed_times.start_minute, 30);
EXPECT_EQ(suppressed_times.duration_minute, 120);
std::string download_preference;
EXPECT_TRUE(
......@@ -284,11 +278,8 @@ TEST(DMPolicyManager, PolicyManagerFromDMResponse) {
EXPECT_FALSE(
policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes));
int start_hour = 0;
int start_minute = 0;
int duration_minute = 0;
EXPECT_FALSE(policy_manager->GetUpdatesSuppressedTimes(
&start_hour, &start_minute, &duration_minute));
UpdatesSuppressedTimes suppressed_times;
EXPECT_FALSE(policy_manager->GetUpdatesSuppressedTimes(&suppressed_times));
std::string download_preference;
EXPECT_FALSE(
......
......@@ -191,15 +191,11 @@ TEST(DMStorage, ReadCachedOmahaPolicy) {
EXPECT_TRUE(policy_manager->GetLastCheckPeriodMinutes(&check_interval));
EXPECT_EQ(check_interval, 111);
int suppressed_start_hour = 0;
int suppressed_start_minute = 0;
int suppressed_duration_minute = 0;
EXPECT_TRUE(policy_manager->GetUpdatesSuppressedTimes(
&suppressed_start_hour, &suppressed_start_minute,
&suppressed_duration_minute));
EXPECT_EQ(suppressed_start_hour, 8);
EXPECT_EQ(suppressed_start_minute, 8);
EXPECT_EQ(suppressed_duration_minute, 47);
UpdatesSuppressedTimes suppressed_times;
EXPECT_TRUE(policy_manager->GetUpdatesSuppressedTimes(&suppressed_times));
EXPECT_EQ(suppressed_times.start_hour, 8);
EXPECT_EQ(suppressed_times.start_minute, 8);
EXPECT_EQ(suppressed_times.duration_minute, 47);
// Proxy policies.
std::string proxy_mode;
......
......@@ -85,8 +85,10 @@ update_client::CrxComponent Installer::MakeCrxComponent() {
// |component.channel| is an empty string. Possible failure cases are if the
// machine is not managed, the policy was not set or any other unexpected
// error.
if (!GetUpdaterPolicyService()->GetTargetChannel(app_id_, &component.channel))
if (!GetUpdaterPolicyService()->GetTargetChannel(app_id_, nullptr,
&component.channel)) {
component.channel.clear();
}
return component;
}
......
......@@ -11,6 +11,7 @@
#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/updater/mac/managed_preference_policy_manager_impl.h"
#include "chrome/updater/policy_manager.h"
namespace updater {
......@@ -32,9 +33,8 @@ class ManagedPreferencePolicyManager : public PolicyManagerInterface {
bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const override;
bool GetUpdatesSuppressedTimes(
UpdatesSuppressedTimes* suppressed_times) const override;
bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override;
......@@ -81,15 +81,9 @@ bool ManagedPreferencePolicyManager::GetLastCheckPeriodMinutes(
}
bool ManagedPreferencePolicyManager::GetUpdatesSuppressedTimes(
int* start_hour,
int* start_min,
int* duration_min) const {
CRUUpdatesSuppressed updatesSuppressed = [impl_ updatesSuppressed];
*start_hour = updatesSuppressed.start_hour;
*start_min = updatesSuppressed.start_minute;
*duration_min = updatesSuppressed.duration_minute;
return *start_hour != kPolicyNotSet || *start_min != kPolicyNotSet ||
*duration_min != kPolicyNotSet;
UpdatesSuppressedTimes* suppressed_times) const {
*suppressed_times = [impl_ updatesSuppressed];
return suppressed_times->valid();
}
bool ManagedPreferencePolicyManager::GetDownloadPreferenceGroupPolicy(
......
......@@ -7,6 +7,8 @@
#import <Foundation/Foundation.h>
#include "chrome/updater/policy_manager.h"
// TODO: crbug/1073980
// Add a doc link for the managed preferences dictionary format.
//
......@@ -38,19 +40,10 @@
// </dict>
// </dict>
constexpr int kPolicyNotSet = -1;
using CRUAppPolicyDictionary = NSDictionary<NSString*, id>;
using CRUUpdatePolicyDictionary =
NSDictionary<NSString*, CRUAppPolicyDictionary*>;
// Structure describes time window when update check is suppressed.
struct CRUUpdatesSuppressed {
int start_hour = kPolicyNotSet;
int start_minute = kPolicyNotSet;
int duration_minute = kPolicyNotSet;
};
@interface CRUManagedPreferencePolicyManager : NSObject
@property(nonatomic, readonly, nullable) NSString* source;
......@@ -60,7 +53,8 @@ struct CRUUpdatesSuppressed {
@property(nonatomic, readonly) int lastCheckPeriodMinutes;
@property(nonatomic, readonly) int defaultUpdatePolicy;
@property(nonatomic, readonly, nullable) NSString* downloadPreference;
@property(nonatomic, readonly) CRUUpdatesSuppressed updatesSuppressed;
@property(nonatomic, readonly)
updater::UpdatesSuppressedTimes updatesSuppressed;
@property(nonatomic, readonly, nullable) NSString* proxyMode;
@property(nonatomic, readonly, nullable) NSString* proxyServer;
@property(nonatomic, readonly, nullable) NSString* proxyPacURL;
......
......@@ -6,6 +6,7 @@
#include "base/mac/scoped_nsobject.h"
#include "chrome/updater/constants.h"
#include "chrome/updater/policy_manager.h"
// Constants for managed preference policy keys.
static NSString* kGlobalPolicyKey = @"global";
......@@ -66,7 +67,8 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
@property(nonatomic, readonly, nullable) NSString* proxyMode;
@property(nonatomic, readonly, nullable) NSString* proxyServer;
@property(nonatomic, readonly, nullable) NSString* proxyPacURL;
@property(nonatomic, readonly) CRUUpdatesSuppressed updatesSuppressed;
@property(nonatomic, readonly)
updater::UpdatesSuppressedTimes updatesSuppressed;
@end
......@@ -93,7 +95,7 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
- (int)lastCheckPeriodMinutes {
// LastCheckPeriodMinutes is not supported in Managed Preference policy.
return kPolicyNotSet;
return updater::kPolicyNotSet;
}
- (NSString*)downloadPreference {
......@@ -235,14 +237,14 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
return [_globalPolicy defaultUpdatePolicy];
}
- (CRUUpdatesSuppressed)updatesSuppressed {
- (updater::UpdatesSuppressedTimes)updatesSuppressed {
return [_globalPolicy updatesSuppressed];
}
- (int)appUpdatePolicy:(NSString*)appid {
appid = appid.lowercaseString;
if (![_appPolicies objectForKey:appid])
return kPolicyNotSet;
return updater::kPolicyNotSet;
return [_appPolicies objectForKey:appid].updatePolicy;
}
......@@ -259,7 +261,7 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
- (int)rollbackToTargetVersion:(NSString*)appid {
appid = appid.lowercaseString;
if (![_appPolicies objectForKey:appid])
return kPolicyNotSet;
return updater::kPolicyNotSet;
return [_appPolicies objectForKey:appid].rollbackToTargetVersion;
}
......
......@@ -24,9 +24,8 @@ class DefaultPolicyManager : public PolicyManagerInterface {
bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const override;
bool GetUpdatesSuppressedTimes(
UpdatesSuppressedTimes* suppressed_times) const override;
bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override;
......@@ -53,7 +52,7 @@ DefaultPolicyManager::DefaultPolicyManager() = default;
DefaultPolicyManager::~DefaultPolicyManager() = default;
bool DefaultPolicyManager::IsManaged() const {
return false;
return true;
}
std::string DefaultPolicyManager::source() const {
......@@ -64,9 +63,8 @@ bool DefaultPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const {
return false;
}
bool DefaultPolicyManager::GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const {
bool DefaultPolicyManager::GetUpdatesSuppressedTimes(
UpdatesSuppressedTimes* suppressed_times) const {
return false;
}
......
......@@ -8,8 +8,36 @@
#include <memory>
#include <string>
#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.
struct UpdatesSuppressedTimes {
int start_hour = kPolicyNotSet;
int start_minute = kPolicyNotSet;
int duration_minute = kPolicyNotSet;
bool operator==(const UpdatesSuppressedTimes& other) const {
return start_hour == other.start_hour &&
start_minute == other.start_minute &&
duration_minute == other.duration_minute;
}
bool operator!=(const UpdatesSuppressedTimes& other) const {
return !(*this == other);
}
bool valid() const {
return start_hour != kPolicyNotSet && start_minute != kPolicyNotSet &&
duration_minute != kPolicyNotSet;
}
};
// The Policy Manager Interface is implemented by policy managers such as Group
// Policy and Device Management.
class PolicyManagerInterface {
......@@ -32,15 +60,10 @@ class PolicyManagerInterface {
virtual bool GetLastCheckPeriodMinutes(int* minutes) const = 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) const = 0;
// updates are suppressed.
virtual bool GetUpdatesSuppressedTimes(
UpdatesSuppressedTimes* suppressed_times) const = 0;
// Returns the policy for the download preference.
virtual bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const = 0;
......
......@@ -9,7 +9,7 @@ namespace updater {
TEST(PolicyManager, GetPolicyManager) {
std::unique_ptr<PolicyManagerInterface> policy_manager(GetPolicyManager());
ASSERT_FALSE(policy_manager->IsManaged());
ASSERT_TRUE(policy_manager->IsManaged());
}
} // namespace updater
This diff is collapsed.
......@@ -9,61 +9,129 @@
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/optional.h"
#include "chrome/updater/policy_manager.h"
namespace updater {
// This class contains the aggregate status of a policy value. It determines
// whether a conflict exists when multiple policy providers set the same policy.
template <typename T>
class PolicyStatus {
public:
struct Entry {
Entry(const std::string& s, T p) : source(s), policy(p) {}
std::string source;
T policy{};
};
PolicyStatus() = default;
PolicyStatus(const PolicyStatus&) = default;
void AddPolicyIfNeeded(bool is_managed,
const std::string& source,
const T& policy) {
if (conflict_policy_)
return; // We already have enough policies.
if (!effective_policy_ && is_managed) {
effective_policy_ = base::make_optional<Entry>(source, policy);
} else if (effective_policy_ &&
policy != effective_policy_.value().policy) {
conflict_policy_ = base::make_optional<Entry>(source, policy);
}
}
const base::Optional<Entry>& effective_policy() const {
return effective_policy_;
}
const base::Optional<Entry>& conflict_policy() const {
return conflict_policy_;
}
private:
base::Optional<Entry> effective_policy_;
base::Optional<Entry> conflict_policy_;
};
// The PolicyService returns policies for enterprise managed machines from the
// source with the highest priority where the policy available.
class PolicyService : public PolicyManagerInterface {
class PolicyService {
public:
PolicyService();
PolicyService(const PolicyService&) = delete;
PolicyService& operator=(const PolicyService&) = delete;
~PolicyService() override;
// Overrides for PolicyManagerInterface.
std::string source() const override;
~PolicyService();
bool IsManaged() const override;
std::string source() const;
bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const override;
bool GetLastCheckPeriodMinutes(PolicyStatus<int>* policy_status,
int* minutes) const;
bool GetUpdatesSuppressedTimes(
PolicyStatus<UpdatesSuppressedTimes>* policy_status,
UpdatesSuppressedTimes* suppressed_times) const;
bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override;
bool GetPackageCacheExpirationTimeDays(int* cache_life_limit) const override;
PolicyStatus<std::string>* policy_status,
std::string* download_preference) const;
bool GetPackageCacheSizeLimitMBytes(PolicyStatus<int>* policy_status,
int* cache_size_limit) const;
bool GetPackageCacheExpirationTimeDays(PolicyStatus<int>* policy_status,
int* cache_life_limit) const;
bool GetEffectivePolicyForAppInstalls(const std::string& app_id,
int* install_policy) const override;
PolicyStatus<int>* policy_status,
int* install_policy) const;
bool GetEffectivePolicyForAppUpdates(const std::string& app_id,
int* update_policy) const override;
PolicyStatus<int>* policy_status,
int* update_policy) const;
bool GetTargetChannel(const std::string& app_id,
std::string* channel) const override;
bool GetTargetVersionPrefix(
const std::string& app_id,
std::string* target_version_prefix) const override;
PolicyStatus<std::string>* policy_status,
std::string* channel) const;
bool GetTargetVersionPrefix(const std::string& app_id,
PolicyStatus<std::string>* policy_status,
std::string* target_version_prefix) const;
bool IsRollbackToTargetVersionAllowed(const std::string& app_id,
bool* rollback_allowed) const override;
bool GetProxyMode(std::string* proxy_mode) const override;
bool GetProxyPacUrl(std::string* proxy_pac_url) const override;
bool GetProxyServer(std::string* proxy_server) const override;
const std::vector<std::unique_ptr<PolicyManagerInterface>>&
policy_managers() {
return policy_managers_;
}
PolicyStatus<bool>* policy_status,
bool* rollback_allowed) const;
bool GetProxyMode(PolicyStatus<std::string>* policy_status,
std::string* proxy_mode) const;
bool GetProxyPacUrl(PolicyStatus<std::string>* policy_status,
std::string* proxy_pac_url) const;
bool GetProxyServer(PolicyStatus<std::string>* policy_status,
std::string* proxy_server) const;
void SetPolicyManagersForTesting(
std::vector<std::unique_ptr<PolicyManagerInterface>> managers);
const PolicyManagerInterface& GetActivePolicyManager();
private:
// List of policy managers in descending order of priority. The first policy
// manager's policies takes precedence over the following.
// List of policy providers in descending order of priority. All managed
// providers should be ahead of non-managed providers.
std::vector<std::unique_ptr<PolicyManagerInterface>> policy_managers_;
// Helper function to insert the policy manager and make sure that
// managed providers are ahead of non-managed providers.
void InsertPolicyManager(std::unique_ptr<PolicyManagerInterface> manager);
// Helper function to query the policy from the managed policy providers and
// determines the policy status.
template <typename T>
bool QueryPolicy(
const base::RepeatingCallback<bool(const PolicyManagerInterface*, T*)>&
policy_query_callback,
PolicyStatus<T>* policy_status,
T* value) const;
// Helper function to query app policy from the managed policy providers and
// determines the policy status.
template <typename T>
bool QueryAppPolicy(
const base::RepeatingCallback<bool(const PolicyManagerInterface*,
const std::string& app_id,
T*)>& policy_query_callback,
const std::string& app_id,
PolicyStatus<T>* policy_status,
T* value) const;
};
std::unique_ptr<PolicyService> GetUpdaterPolicyService();
......
This diff is collapsed.
......@@ -7,6 +7,7 @@
#include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h"
#include "base/win/win_util.h"
#include "chrome/updater/policy_manager.h"
#include "chrome/updater/win/constants.h"
namespace updater {
......@@ -70,12 +71,14 @@ bool GroupPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const {
return ReadValueDW(kRegValueAutoUpdateCheckPeriodOverrideMinutes, minutes);
}
bool GroupPolicyManager::GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const {
return ReadValueDW(kRegValueUpdatesSuppressedStartHour, start_hour) &&
ReadValueDW(kRegValueUpdatesSuppressedStartMin, start_min) &&
ReadValueDW(kRegValueUpdatesSuppressedDurationMin, duration_min);
bool GroupPolicyManager::GetUpdatesSuppressedTimes(
UpdatesSuppressedTimes* suppressed_times) const {
return ReadValueDW(kRegValueUpdatesSuppressedStartHour,
&suppressed_times->start_hour) &&
ReadValueDW(kRegValueUpdatesSuppressedStartMin,
&suppressed_times->start_minute) &&
ReadValueDW(kRegValueUpdatesSuppressedDurationMin,
&suppressed_times->duration_minute);
}
bool GroupPolicyManager::GetDownloadPreferenceGroupPolicy(
......
......@@ -28,9 +28,8 @@ class GroupPolicyManager : public PolicyManagerInterface {
bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour,
int* start_min,
int* duration_min) const override;
bool GetUpdatesSuppressedTimes(
UpdatesSuppressedTimes* suppressed_times) const override;
bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override;
......
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