PolicyManager: Add a Variable "Mode" property.

There are three kinds of Variables: Const, Poll and Async; that
reflect how the value on the variable changes. Const variables don't
change its value, Poll variables can change the value without notice
and Async variables can change the value but notify the observers
with those changes.

This patch adds the Mode property to the BaseVariable class. This
property can be used by the EvaluationContext to determine how to
treat a given variable.

BUG=chromium:341209
TEST=unit test added and passing.

Change-Id: Ifd4ebcfb84cdb9c6cca1ccbb34004cbac0ea2d2f
Reviewed-on: https://chromium-review.googlesource.com/187240
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/policy_manager/variable.h b/policy_manager/variable.h
index ce239ce..d4fba0c 100644
--- a/policy_manager/variable.h
+++ b/policy_manager/variable.h
@@ -12,21 +12,53 @@
 
 namespace chromeos_policy_manager {
 
+// The VariableMode specifies important behavior of the variable in terms of
+// whether, how and when the value of the variable changes.
+enum VariableMode {
+  // Const variables never changes during the life of a policy request, so the
+  // EvaluationContext caches the value even between different evaluations of
+  // the same policy request.
+  kVariableModeConst,
+
+  // Poll variables, or synchronous variables, represent a variable with a value
+  // that can be queried at any time, but it is not known when the value
+  // changes on the source of information. In order to detect if the value of
+  // the variable changes, it has to be queried again.
+  kVariableModePoll,
+
+  // Async variables are able to produce a signal or callback whenever the
+  // value changes. This means that it's not required to poll the value to
+  // detect when it changes, instead, you should register an observer to get
+  // a notification when that happens.
+  kVariableModeAsync,
+};
+
 // This class is a base class with the common functionality that doesn't
 // deppend on the variable's type, implemented by all the variables.
 class BaseVariable {
  public:
-  BaseVariable(const std::string& name) : name_(name) {}
   virtual ~BaseVariable() {}
 
   // Returns the variable name as a string.
-  virtual const std::string& GetName() {
+  const std::string& GetName() const {
     return name_;
   }
 
+  // Returns the variable mode.
+  VariableMode GetMode() const {
+    return mode_;
+  }
+
+ protected:
+  BaseVariable(const std::string& name, VariableMode mode)
+      : name_(name), mode_(mode) {}
+
  private:
   // The variable's name as a string.
   const std::string name_;
+
+  // The variable's mode.
+  const VariableMode mode_;
 };
 
 // Interface to a Policy Manager variable of a given type. Implementation
@@ -35,7 +67,6 @@
 template<typename T>
 class Variable : public BaseVariable {
  public:
-  Variable(const std::string& name) : BaseVariable(name) {}
   virtual ~Variable() {}
 
  protected:
@@ -48,6 +79,9 @@
   friend class PmRealShillProviderTest;
   FRIEND_TEST(PmRealShillProviderTest, DefaultValues);
 
+  Variable(const std::string& name, VariableMode mode)
+      : BaseVariable(name, mode) {}
+
   // 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.