PolicyManager: Include the Polling interval for kVariableModePoll variables. A kVariableModePoll variable requires to be polled to know the if the value changed. This patch adds a new GetPollInterval method that tells how often a kVariableModePoll variable should be polled. This value will be used by the policy manager to trigger re-evaluations of the same policy request. BUG=chromium:341209 TEST=unit tests added and passes. Change-Id: I9c982ec8106ce39a0bc0889df7686add131b3bea Reviewed-on: https://chromium-review.googlesource.com/187703 Reviewed-by: Gilad Arnold <[email protected]> Tested-by: Alex Deymo <[email protected]> Commit-Queue: Alex Deymo <[email protected]>
diff --git a/policy_manager/variable.h b/policy_manager/variable.h index d4fba0c..373af7f 100644 --- a/policy_manager/variable.h +++ b/policy_manager/variable.h
@@ -49,16 +49,42 @@ return mode_; } + // For VariableModePoll variables, it returns the polling interval of this + // variable. In other case, it returns 0. + base::TimeDelta GetPollInterval() const { + return poll_interval_; + } + protected: + // Creates a BaseVariable using the default polling interval (5 minutes). BaseVariable(const std::string& name, VariableMode mode) - : name_(name), mode_(mode) {} + : BaseVariable(name, mode, + base::TimeDelta::FromMinutes(kDefaultPollMinutes)) {} + + // Creates a BaseVariable with mode kVariableModePoll and the provided + // polling interval. + BaseVariable(const std::string& name, base::TimeDelta poll_interval) + : BaseVariable(name, kVariableModePoll, poll_interval) {} private: + BaseVariable(const std::string& name, VariableMode mode, + base::TimeDelta poll_interval) + : name_(name), mode_(mode), + poll_interval_(mode == kVariableModePoll ? + poll_interval : base::TimeDelta()) {} + + // The default PollInterval in minutes. + static constexpr int kDefaultPollMinutes = 5; + // The variable's name as a string. const std::string name_; // The variable's mode. const VariableMode mode_; + + // The variable's polling interval for VariableModePoll variable and 0 for + // other modes. + const base::TimeDelta poll_interval_; }; // Interface to a Policy Manager variable of a given type. Implementation @@ -82,6 +108,9 @@ Variable(const std::string& name, VariableMode mode) : BaseVariable(name, mode) {} + Variable(const std::string& name, const base::TimeDelta& poll_interval) + : BaseVariable(name, poll_interval) {} + // Gets the current value of the variable. The current value is copied to a // new object and returned. The caller of this method owns the object and // should delete it.