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[]; ...@@ -194,6 +194,7 @@ extern const char kProxyModeSystem[];
extern const char kDownloadPreferenceCacheable[]; extern const char kDownloadPreferenceCacheable[];
constexpr int kPolicyNotSet = -1;
constexpr int kPolicyDisabled = 0; constexpr int kPolicyDisabled = 0;
constexpr int kPolicyEnabled = 1; constexpr int kPolicyEnabled = 1;
constexpr int kPolicyEnabledMachineOnly = 4; constexpr int kPolicyEnabledMachineOnly = 4;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/updater/constants.h" #include "chrome/updater/constants.h"
#include "chrome/updater/policy_manager.h"
namespace updater { namespace updater {
...@@ -69,9 +70,8 @@ bool DMPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const { ...@@ -69,9 +70,8 @@ bool DMPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const {
return true; return true;
} }
bool DMPolicyManager::GetUpdatesSuppressedTimes(int* start_hour, bool DMPolicyManager::GetUpdatesSuppressedTimes(
int* start_min, UpdatesSuppressedTimes* suppressed_times) const {
int* duration_min) const {
if (!omaha_settings_.has_updates_suppressed()) if (!omaha_settings_.has_updates_suppressed())
return false; return false;
...@@ -81,9 +81,9 @@ bool DMPolicyManager::GetUpdatesSuppressedTimes(int* start_hour, ...@@ -81,9 +81,9 @@ bool DMPolicyManager::GetUpdatesSuppressedTimes(int* start_hour,
!updates_suppressed.has_duration_min()) !updates_suppressed.has_duration_min())
return false; return false;
*start_hour = updates_suppressed.start_hour(); suppressed_times->start_hour = updates_suppressed.start_hour();
*start_min = updates_suppressed.start_minute(); suppressed_times->start_minute = updates_suppressed.start_minute();
*duration_min = updates_suppressed.duration_min(); suppressed_times->duration_minute = updates_suppressed.duration_min();
return true; return true;
} }
......
...@@ -29,9 +29,8 @@ class DMPolicyManager : public PolicyManagerInterface { ...@@ -29,9 +29,8 @@ class DMPolicyManager : public PolicyManagerInterface {
bool IsManaged() const override; bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override; bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour, bool GetUpdatesSuppressedTimes(
int* start_min, UpdatesSuppressedTimes* suppressed_times) const override;
int* duration_min) const override;
bool GetDownloadPreferenceGroupPolicy( bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override; std::string* download_preference) const override;
bool GetProxyMode(std::string* proxy_mode) const override; bool GetProxyMode(std::string* proxy_mode) const override;
......
...@@ -114,11 +114,8 @@ TEST(DMPolicyManager, PolicyManagerFromEmptyProto) { ...@@ -114,11 +114,8 @@ TEST(DMPolicyManager, PolicyManagerFromEmptyProto) {
EXPECT_FALSE( EXPECT_FALSE(
policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes)); policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes));
int start_hour = 0; UpdatesSuppressedTimes suppressed_times;
int start_minute = 0; EXPECT_FALSE(policy_manager->GetUpdatesSuppressedTimes(&suppressed_times));
int duration_minute = 0;
EXPECT_FALSE(policy_manager->GetUpdatesSuppressedTimes(
&start_hour, &start_minute, &duration_minute));
std::string download_preference; std::string download_preference;
EXPECT_FALSE( EXPECT_FALSE(
...@@ -192,14 +189,11 @@ TEST(DMPolicyManager, PolicyManagerFromProto) { ...@@ -192,14 +189,11 @@ TEST(DMPolicyManager, PolicyManagerFromProto) {
policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes)); policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes));
EXPECT_EQ(last_check_period_minutes, 111); EXPECT_EQ(last_check_period_minutes, 111);
int start_hour = 0; UpdatesSuppressedTimes suppressed_times;
int start_minute = 0; EXPECT_TRUE(policy_manager->GetUpdatesSuppressedTimes(&suppressed_times));
int duration_minute = 0; EXPECT_EQ(suppressed_times.start_hour, 9);
EXPECT_TRUE(policy_manager->GetUpdatesSuppressedTimes( EXPECT_EQ(suppressed_times.start_minute, 30);
&start_hour, &start_minute, &duration_minute)); EXPECT_EQ(suppressed_times.duration_minute, 120);
EXPECT_EQ(start_hour, 9);
EXPECT_EQ(start_minute, 30);
EXPECT_EQ(duration_minute, 120);
std::string download_preference; std::string download_preference;
EXPECT_TRUE( EXPECT_TRUE(
...@@ -284,11 +278,8 @@ TEST(DMPolicyManager, PolicyManagerFromDMResponse) { ...@@ -284,11 +278,8 @@ TEST(DMPolicyManager, PolicyManagerFromDMResponse) {
EXPECT_FALSE( EXPECT_FALSE(
policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes)); policy_manager->GetLastCheckPeriodMinutes(&last_check_period_minutes));
int start_hour = 0; UpdatesSuppressedTimes suppressed_times;
int start_minute = 0; EXPECT_FALSE(policy_manager->GetUpdatesSuppressedTimes(&suppressed_times));
int duration_minute = 0;
EXPECT_FALSE(policy_manager->GetUpdatesSuppressedTimes(
&start_hour, &start_minute, &duration_minute));
std::string download_preference; std::string download_preference;
EXPECT_FALSE( EXPECT_FALSE(
......
...@@ -191,15 +191,11 @@ TEST(DMStorage, ReadCachedOmahaPolicy) { ...@@ -191,15 +191,11 @@ TEST(DMStorage, ReadCachedOmahaPolicy) {
EXPECT_TRUE(policy_manager->GetLastCheckPeriodMinutes(&check_interval)); EXPECT_TRUE(policy_manager->GetLastCheckPeriodMinutes(&check_interval));
EXPECT_EQ(check_interval, 111); EXPECT_EQ(check_interval, 111);
int suppressed_start_hour = 0; UpdatesSuppressedTimes suppressed_times;
int suppressed_start_minute = 0; EXPECT_TRUE(policy_manager->GetUpdatesSuppressedTimes(&suppressed_times));
int suppressed_duration_minute = 0; EXPECT_EQ(suppressed_times.start_hour, 8);
EXPECT_TRUE(policy_manager->GetUpdatesSuppressedTimes( EXPECT_EQ(suppressed_times.start_minute, 8);
&suppressed_start_hour, &suppressed_start_minute, EXPECT_EQ(suppressed_times.duration_minute, 47);
&suppressed_duration_minute));
EXPECT_EQ(suppressed_start_hour, 8);
EXPECT_EQ(suppressed_start_minute, 8);
EXPECT_EQ(suppressed_duration_minute, 47);
// Proxy policies. // Proxy policies.
std::string proxy_mode; std::string proxy_mode;
......
...@@ -85,8 +85,10 @@ update_client::CrxComponent Installer::MakeCrxComponent() { ...@@ -85,8 +85,10 @@ update_client::CrxComponent Installer::MakeCrxComponent() {
// |component.channel| is an empty string. Possible failure cases are if the // |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 // machine is not managed, the policy was not set or any other unexpected
// error. // error.
if (!GetUpdaterPolicyService()->GetTargetChannel(app_id_, &component.channel)) if (!GetUpdaterPolicyService()->GetTargetChannel(app_id_, nullptr,
&component.channel)) {
component.channel.clear(); component.channel.clear();
}
return component; return component;
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "chrome/updater/mac/managed_preference_policy_manager_impl.h" #include "chrome/updater/mac/managed_preference_policy_manager_impl.h"
#include "chrome/updater/policy_manager.h"
namespace updater { namespace updater {
...@@ -32,9 +33,8 @@ class ManagedPreferencePolicyManager : public PolicyManagerInterface { ...@@ -32,9 +33,8 @@ class ManagedPreferencePolicyManager : public PolicyManagerInterface {
bool IsManaged() const override; bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override; bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour, bool GetUpdatesSuppressedTimes(
int* start_min, UpdatesSuppressedTimes* suppressed_times) const override;
int* duration_min) const override;
bool GetDownloadPreferenceGroupPolicy( bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override; std::string* download_preference) const override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override; bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override;
...@@ -81,15 +81,9 @@ bool ManagedPreferencePolicyManager::GetLastCheckPeriodMinutes( ...@@ -81,15 +81,9 @@ bool ManagedPreferencePolicyManager::GetLastCheckPeriodMinutes(
} }
bool ManagedPreferencePolicyManager::GetUpdatesSuppressedTimes( bool ManagedPreferencePolicyManager::GetUpdatesSuppressedTimes(
int* start_hour, UpdatesSuppressedTimes* suppressed_times) const {
int* start_min, *suppressed_times = [impl_ updatesSuppressed];
int* duration_min) const { return suppressed_times->valid();
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;
} }
bool ManagedPreferencePolicyManager::GetDownloadPreferenceGroupPolicy( bool ManagedPreferencePolicyManager::GetDownloadPreferenceGroupPolicy(
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#include "chrome/updater/policy_manager.h"
// TODO: crbug/1073980 // TODO: crbug/1073980
// Add a doc link for the managed preferences dictionary format. // Add a doc link for the managed preferences dictionary format.
// //
...@@ -38,19 +40,10 @@ ...@@ -38,19 +40,10 @@
// </dict> // </dict>
// </dict> // </dict>
constexpr int kPolicyNotSet = -1;
using CRUAppPolicyDictionary = NSDictionary<NSString*, id>; using CRUAppPolicyDictionary = NSDictionary<NSString*, id>;
using CRUUpdatePolicyDictionary = using CRUUpdatePolicyDictionary =
NSDictionary<NSString*, CRUAppPolicyDictionary*>; 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 @interface CRUManagedPreferencePolicyManager : NSObject
@property(nonatomic, readonly, nullable) NSString* source; @property(nonatomic, readonly, nullable) NSString* source;
...@@ -60,7 +53,8 @@ struct CRUUpdatesSuppressed { ...@@ -60,7 +53,8 @@ struct CRUUpdatesSuppressed {
@property(nonatomic, readonly) int lastCheckPeriodMinutes; @property(nonatomic, readonly) int lastCheckPeriodMinutes;
@property(nonatomic, readonly) int defaultUpdatePolicy; @property(nonatomic, readonly) int defaultUpdatePolicy;
@property(nonatomic, readonly, nullable) NSString* downloadPreference; @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* proxyMode;
@property(nonatomic, readonly, nullable) NSString* proxyServer; @property(nonatomic, readonly, nullable) NSString* proxyServer;
@property(nonatomic, readonly, nullable) NSString* proxyPacURL; @property(nonatomic, readonly, nullable) NSString* proxyPacURL;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "chrome/updater/constants.h" #include "chrome/updater/constants.h"
#include "chrome/updater/policy_manager.h"
// Constants for managed preference policy keys. // Constants for managed preference policy keys.
static NSString* kGlobalPolicyKey = @"global"; static NSString* kGlobalPolicyKey = @"global";
...@@ -66,7 +67,8 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) { ...@@ -66,7 +67,8 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
@property(nonatomic, readonly, nullable) NSString* proxyMode; @property(nonatomic, readonly, nullable) NSString* proxyMode;
@property(nonatomic, readonly, nullable) NSString* proxyServer; @property(nonatomic, readonly, nullable) NSString* proxyServer;
@property(nonatomic, readonly, nullable) NSString* proxyPacURL; @property(nonatomic, readonly, nullable) NSString* proxyPacURL;
@property(nonatomic, readonly) CRUUpdatesSuppressed updatesSuppressed; @property(nonatomic, readonly)
updater::UpdatesSuppressedTimes updatesSuppressed;
@end @end
...@@ -93,7 +95,7 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) { ...@@ -93,7 +95,7 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
- (int)lastCheckPeriodMinutes { - (int)lastCheckPeriodMinutes {
// LastCheckPeriodMinutes is not supported in Managed Preference policy. // LastCheckPeriodMinutes is not supported in Managed Preference policy.
return kPolicyNotSet; return updater::kPolicyNotSet;
} }
- (NSString*)downloadPreference { - (NSString*)downloadPreference {
...@@ -235,14 +237,14 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) { ...@@ -235,14 +237,14 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
return [_globalPolicy defaultUpdatePolicy]; return [_globalPolicy defaultUpdatePolicy];
} }
- (CRUUpdatesSuppressed)updatesSuppressed { - (updater::UpdatesSuppressedTimes)updatesSuppressed {
return [_globalPolicy updatesSuppressed]; return [_globalPolicy updatesSuppressed];
} }
- (int)appUpdatePolicy:(NSString*)appid { - (int)appUpdatePolicy:(NSString*)appid {
appid = appid.lowercaseString; appid = appid.lowercaseString;
if (![_appPolicies objectForKey:appid]) if (![_appPolicies objectForKey:appid])
return kPolicyNotSet; return updater::kPolicyNotSet;
return [_appPolicies objectForKey:appid].updatePolicy; return [_appPolicies objectForKey:appid].updatePolicy;
} }
...@@ -259,7 +261,7 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) { ...@@ -259,7 +261,7 @@ base::scoped_nsobject<NSString> ReadPolicyString(id value) {
- (int)rollbackToTargetVersion:(NSString*)appid { - (int)rollbackToTargetVersion:(NSString*)appid {
appid = appid.lowercaseString; appid = appid.lowercaseString;
if (![_appPolicies objectForKey:appid]) if (![_appPolicies objectForKey:appid])
return kPolicyNotSet; return updater::kPolicyNotSet;
return [_appPolicies objectForKey:appid].rollbackToTargetVersion; return [_appPolicies objectForKey:appid].rollbackToTargetVersion;
} }
......
...@@ -24,9 +24,8 @@ class DefaultPolicyManager : public PolicyManagerInterface { ...@@ -24,9 +24,8 @@ class DefaultPolicyManager : public PolicyManagerInterface {
bool IsManaged() const override; bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override; bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour, bool GetUpdatesSuppressedTimes(
int* start_min, UpdatesSuppressedTimes* suppressed_times) const override;
int* duration_min) const override;
bool GetDownloadPreferenceGroupPolicy( bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override; std::string* download_preference) const override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override; bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override;
...@@ -53,7 +52,7 @@ DefaultPolicyManager::DefaultPolicyManager() = default; ...@@ -53,7 +52,7 @@ DefaultPolicyManager::DefaultPolicyManager() = default;
DefaultPolicyManager::~DefaultPolicyManager() = default; DefaultPolicyManager::~DefaultPolicyManager() = default;
bool DefaultPolicyManager::IsManaged() const { bool DefaultPolicyManager::IsManaged() const {
return false; return true;
} }
std::string DefaultPolicyManager::source() const { std::string DefaultPolicyManager::source() const {
...@@ -64,9 +63,8 @@ bool DefaultPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const { ...@@ -64,9 +63,8 @@ bool DefaultPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const {
return false; return false;
} }
bool DefaultPolicyManager::GetUpdatesSuppressedTimes(int* start_hour, bool DefaultPolicyManager::GetUpdatesSuppressedTimes(
int* start_min, UpdatesSuppressedTimes* suppressed_times) const {
int* duration_min) const {
return false; return false;
} }
......
...@@ -8,8 +8,36 @@ ...@@ -8,8 +8,36 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "chrome/updater/constants.h"
namespace updater { 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 // The Policy Manager Interface is implemented by policy managers such as Group
// Policy and Device Management. // Policy and Device Management.
class PolicyManagerInterface { class PolicyManagerInterface {
...@@ -32,15 +60,10 @@ class PolicyManagerInterface { ...@@ -32,15 +60,10 @@ class PolicyManagerInterface {
virtual bool GetLastCheckPeriodMinutes(int* minutes) const = 0; virtual bool GetLastCheckPeriodMinutes(int* minutes) const = 0;
// For domain-joined machines, checks the current time against the times that // For domain-joined machines, checks the current time against the times that
// updates are suppressed. Updates are suppressed if the current time falls // updates are suppressed.
// between the start time and the duration. virtual bool GetUpdatesSuppressedTimes(
// The duration does not account for daylight savings time. For instance, if UpdatesSuppressedTimes* suppressed_times) const = 0;
// 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;
// Returns the policy for the download preference. // Returns the policy for the download preference.
virtual bool GetDownloadPreferenceGroupPolicy( virtual bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const = 0; std::string* download_preference) const = 0;
......
...@@ -9,7 +9,7 @@ namespace updater { ...@@ -9,7 +9,7 @@ namespace updater {
TEST(PolicyManager, GetPolicyManager) { TEST(PolicyManager, GetPolicyManager) {
std::unique_ptr<PolicyManagerInterface> policy_manager(GetPolicyManager()); std::unique_ptr<PolicyManagerInterface> policy_manager(GetPolicyManager());
ASSERT_FALSE(policy_manager->IsManaged()); ASSERT_TRUE(policy_manager->IsManaged());
} }
} // namespace updater } // namespace updater
This diff is collapsed.
...@@ -9,61 +9,129 @@ ...@@ -9,61 +9,129 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/callback_forward.h"
#include "base/optional.h"
#include "chrome/updater/policy_manager.h" #include "chrome/updater/policy_manager.h"
namespace updater { 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 // The PolicyService returns policies for enterprise managed machines from the
// source with the highest priority where the policy available. // source with the highest priority where the policy available.
class PolicyService : public PolicyManagerInterface { class PolicyService {
public: public:
PolicyService(); PolicyService();
PolicyService(const PolicyService&) = delete; PolicyService(const PolicyService&) = delete;
PolicyService& operator=(const PolicyService&) = delete; PolicyService& operator=(const PolicyService&) = delete;
~PolicyService() override; ~PolicyService();
// Overrides for PolicyManagerInterface.
std::string source() const override;
bool IsManaged() const override; std::string source() const;
bool GetLastCheckPeriodMinutes(int* minutes) const override; bool GetLastCheckPeriodMinutes(PolicyStatus<int>* policy_status,
bool GetUpdatesSuppressedTimes(int* start_hour, int* minutes) const;
int* start_min, bool GetUpdatesSuppressedTimes(
int* duration_min) const override; PolicyStatus<UpdatesSuppressedTimes>* policy_status,
UpdatesSuppressedTimes* suppressed_times) const;
bool GetDownloadPreferenceGroupPolicy( bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override; PolicyStatus<std::string>* policy_status,
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) const override; std::string* download_preference) const;
bool GetPackageCacheExpirationTimeDays(int* cache_life_limit) const override; 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, 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, 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, bool GetTargetChannel(const std::string& app_id,
std::string* channel) const override; PolicyStatus<std::string>* policy_status,
bool GetTargetVersionPrefix( std::string* channel) const;
const std::string& app_id, bool GetTargetVersionPrefix(const std::string& app_id,
std::string* target_version_prefix) const override; PolicyStatus<std::string>* policy_status,
std::string* target_version_prefix) const;
bool IsRollbackToTargetVersionAllowed(const std::string& app_id, bool IsRollbackToTargetVersionAllowed(const std::string& app_id,
bool* rollback_allowed) const override; PolicyStatus<bool>* policy_status,
bool GetProxyMode(std::string* proxy_mode) const override; bool* rollback_allowed) const;
bool GetProxyPacUrl(std::string* proxy_pac_url) const override; bool GetProxyMode(PolicyStatus<std::string>* policy_status,
bool GetProxyServer(std::string* proxy_server) const override; std::string* proxy_mode) const;
bool GetProxyPacUrl(PolicyStatus<std::string>* policy_status,
const std::vector<std::unique_ptr<PolicyManagerInterface>>& std::string* proxy_pac_url) const;
policy_managers() { bool GetProxyServer(PolicyStatus<std::string>* policy_status,
return policy_managers_; std::string* proxy_server) const;
}
void SetPolicyManagersForTesting( void SetPolicyManagersForTesting(
std::vector<std::unique_ptr<PolicyManagerInterface>> managers); std::vector<std::unique_ptr<PolicyManagerInterface>> managers);
const PolicyManagerInterface& GetActivePolicyManager();
private: private:
// List of policy managers in descending order of priority. The first policy // List of policy providers in descending order of priority. All managed
// manager's policies takes precedence over the following. // providers should be ahead of non-managed providers.
std::vector<std::unique_ptr<PolicyManagerInterface>> policy_managers_; 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(); std::unique_ptr<PolicyService> GetUpdaterPolicyService();
......
This diff is collapsed.
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/win/win_util.h" #include "base/win/win_util.h"
#include "chrome/updater/policy_manager.h"
#include "chrome/updater/win/constants.h" #include "chrome/updater/win/constants.h"
namespace updater { namespace updater {
...@@ -70,12 +71,14 @@ bool GroupPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const { ...@@ -70,12 +71,14 @@ bool GroupPolicyManager::GetLastCheckPeriodMinutes(int* minutes) const {
return ReadValueDW(kRegValueAutoUpdateCheckPeriodOverrideMinutes, minutes); return ReadValueDW(kRegValueAutoUpdateCheckPeriodOverrideMinutes, minutes);
} }
bool GroupPolicyManager::GetUpdatesSuppressedTimes(int* start_hour, bool GroupPolicyManager::GetUpdatesSuppressedTimes(
int* start_min, UpdatesSuppressedTimes* suppressed_times) const {
int* duration_min) const { return ReadValueDW(kRegValueUpdatesSuppressedStartHour,
return ReadValueDW(kRegValueUpdatesSuppressedStartHour, start_hour) && &suppressed_times->start_hour) &&
ReadValueDW(kRegValueUpdatesSuppressedStartMin, start_min) && ReadValueDW(kRegValueUpdatesSuppressedStartMin,
ReadValueDW(kRegValueUpdatesSuppressedDurationMin, duration_min); &suppressed_times->start_minute) &&
ReadValueDW(kRegValueUpdatesSuppressedDurationMin,
&suppressed_times->duration_minute);
} }
bool GroupPolicyManager::GetDownloadPreferenceGroupPolicy( bool GroupPolicyManager::GetDownloadPreferenceGroupPolicy(
......
...@@ -28,9 +28,8 @@ class GroupPolicyManager : public PolicyManagerInterface { ...@@ -28,9 +28,8 @@ class GroupPolicyManager : public PolicyManagerInterface {
bool IsManaged() const override; bool IsManaged() const override;
bool GetLastCheckPeriodMinutes(int* minutes) const override; bool GetLastCheckPeriodMinutes(int* minutes) const override;
bool GetUpdatesSuppressedTimes(int* start_hour, bool GetUpdatesSuppressedTimes(
int* start_min, UpdatesSuppressedTimes* suppressed_times) const override;
int* duration_min) const override;
bool GetDownloadPreferenceGroupPolicy( bool GetDownloadPreferenceGroupPolicy(
std::string* download_preference) const override; std::string* download_preference) const override;
bool GetPackageCacheSizeLimitMBytes(int* cache_size_limit) 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