PM: CopyVariable renamed PollCopyVariable.

This is in effect always used as a polled variable, so we restrict it to
be such.

BUG=None
TEST=Unit tests.

Change-Id: I5a824e3140e461262f9f4e1f2b0ee14f0856713c
Reviewed-on: https://chromium-review.googlesource.com/200619
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/generic_variables.h b/policy_manager/generic_variables.h
index 42e991d..b010a33 100644
--- a/policy_manager/generic_variables.h
+++ b/policy_manager/generic_variables.h
@@ -9,17 +9,12 @@
 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_GENERIC_VARIABLES_H_
 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_GENERIC_VARIABLES_H_
 
+#include <string>
+
 #include <base/callback.h>
 
 #include "update_engine/policy_manager/variable.h"
 
-namespace {
-
-const char* kCopyVariableDefaultErrMsg = "Requested value is not set";
-
-}  // namespace
-
-
 namespace chromeos_policy_manager {
 
 // Variable class returning a copy of a given object using the copy constructor.
@@ -34,52 +29,55 @@
 //   class SomethingProvider {
 //    public:
 //      SomethingProvider(...) {
-//        var_something_foo = new CopyVariable<MyType>(foo_);
+//        var_something_foo = new PollCopyVariable<MyType>(foo_);
 //      }
 //      ...
 //    private:
 //     MyType foo_;
 //   };
 template<typename T>
-class CopyVariable : public Variable<T> {
+class PollCopyVariable : public Variable<T> {
  public:
   // Creates the variable returning copies of the passed |ref|. The reference to
   // this object is kept and it should be available whenever the GetValue()
   // method is called. If |is_set_p| is not null, then this flag will be
   // consulted prior to returning the value, and an |errmsg| will be returned if
   // it is not set.
-  CopyVariable(const std::string& name, VariableMode mode, const T& ref,
-               const bool* is_set_p, const std::string& errmsg)
-      : Variable<T>(name, mode), ref_(ref), is_set_p_(is_set_p),
+  PollCopyVariable(const std::string& name, const T& ref, const bool* is_set_p,
+                   const std::string& errmsg)
+      : Variable<T>(name, kVariableModePoll), ref_(ref), is_set_p_(is_set_p),
         errmsg_(errmsg) {}
-  CopyVariable(const std::string& name, VariableMode mode, const T& ref,
-               const bool* is_set_p)
-      : CopyVariable(name, mode, ref, is_set_p, kCopyVariableDefaultErrMsg) {}
-  CopyVariable(const std::string& name, VariableMode mode, const T& ref)
-      : CopyVariable(name, mode, ref, nullptr) {}
+  PollCopyVariable(const std::string& name, const T& ref, const bool* is_set_p)
+      : PollCopyVariable(name, ref, is_set_p, std::string()) {}
+  PollCopyVariable(const std::string& name, const T& ref)
+      : PollCopyVariable(name, ref, nullptr) {}
 
-  CopyVariable(const std::string& name, const base::TimeDelta poll_interval,
-               const T& ref, const bool* is_set_p, const std::string& errmsg)
+  PollCopyVariable(const std::string& name, const base::TimeDelta poll_interval,
+                   const T& ref, const bool* is_set_p,
+                   const std::string& errmsg)
       : Variable<T>(name, poll_interval), ref_(ref), is_set_p_(is_set_p),
         errmsg_(errmsg) {}
-  CopyVariable(const std::string& name, const base::TimeDelta poll_interval,
-               const T& ref, const bool* is_set_p)
-      : CopyVariable(name, poll_interval, ref, is_set_p,
-                     kCopyVariableDefaultErrMsg) {}
-  CopyVariable(const std::string& name, const base::TimeDelta poll_interval,
-               const T& ref)
-      : CopyVariable(name, poll_interval, ref, nullptr) {}
+  PollCopyVariable(const std::string& name, const base::TimeDelta poll_interval,
+                   const T& ref, const bool* is_set_p)
+      : PollCopyVariable(name, poll_interval, ref, is_set_p, std::string()) {}
+  PollCopyVariable(const std::string& name, const base::TimeDelta poll_interval,
+                   const T& ref)
+      : PollCopyVariable(name, poll_interval, ref, nullptr) {}
 
  protected:
-  FRIEND_TEST(PmCopyVariableTest, SimpleTest);
-  FRIEND_TEST(PmCopyVariableTest, UseCopyConstructorTest);
+  FRIEND_TEST(PmPollCopyVariableTest, SimpleTest);
+  FRIEND_TEST(PmPollCopyVariableTest, UseCopyConstructorTest);
 
   // Variable override.
   virtual inline const T* GetValue(base::TimeDelta /* timeout */,
                                    std::string* errmsg) {
     if (is_set_p_ && !(*is_set_p_)) {
-      if (errmsg)
-        *errmsg = errmsg_;
+      if (errmsg) {
+        if (errmsg_.empty())
+          *errmsg = "No value set for " + this->GetName();
+        else
+          *errmsg = errmsg_;
+      }
       return nullptr;
     }
     return new T(ref_);
diff --git a/policy_manager/generic_variables_unittest.cc b/policy_manager/generic_variables_unittest.cc
index 279c729..370da04 100644
--- a/policy_manager/generic_variables_unittest.cc
+++ b/policy_manager/generic_variables_unittest.cc
@@ -16,13 +16,13 @@
 
 namespace chromeos_policy_manager {
 
-class PmCopyVariableTest : public ::testing::Test {};
+class PmPollCopyVariableTest : public ::testing::Test {};
 
 
-TEST_F(PmCopyVariableTest, SimpleTest) {
+TEST_F(PmPollCopyVariableTest, SimpleTest) {
   // Tests that copies are generated as intended.
   int source = 5;
-  CopyVariable<int> var("var", kVariableModePoll, source);
+  PollCopyVariable<int> var("var", source);
 
   // Generate and validate a copy.
   scoped_ptr<const int> copy_1(var.GetValue(
@@ -40,11 +40,11 @@
   PmTestUtils::ExpectVariableHasValue(42, &var);
 }
 
-TEST_F(PmCopyVariableTest, SetFlagTest) {
+TEST_F(PmPollCopyVariableTest, SetFlagTest) {
   // Tests that the set flag is being referred to as expected.
   int source = 5;
   bool is_set = false;
-  CopyVariable<int> var("var", kVariableModePoll, source, &is_set);
+  PollCopyVariable<int> var("var", source, &is_set);
 
   // Flag marked unset, nothing should be returned.
   PmTestUtils::ExpectVariableNotSet(&var);
@@ -69,12 +69,12 @@
 };
 
 
-TEST_F(PmCopyVariableTest, UseCopyConstructorTest) {
+TEST_F(PmPollCopyVariableTest, UseCopyConstructorTest) {
   // Ensures that CopyVariables indeed uses the copy contructor.
   const CopyConstructorTestClass source;
   ASSERT_FALSE(source.copied_);
 
-  CopyVariable<CopyConstructorTestClass> var("var", kVariableModePoll, source);
+  PollCopyVariable<CopyConstructorTestClass> var("var", source);
   scoped_ptr<const CopyConstructorTestClass> copy(
       var.GetValue(PmTestUtils::DefaultTimeout(), NULL));
   PMTEST_ASSERT_NOT_NULL(copy.get());