AU/PM: Some refactoring
* Introduced a Provider base class, used for defining interface and
shared logic (e.g. initialization semantics).
* Eliminated the Finalize() method in providers; release of resources is
done in destructors (safer, less boilerplate).
* Revised CamelCase capitalization: PMFooTest -> PmFooTest, plus various
cosmetics.
BUG=None
TEST=Builds and passes unit tests.
Change-Id: Ib959dfd2522e00928d735202b1448c9436cbb00b
Reviewed-on: https://chromium-review.googlesource.com/184352
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 321c89a..e78bbbd 100644
--- a/policy_manager/generic_variables.h
+++ b/policy_manager/generic_variables.h
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Generic and provider independent Variable subclasses. These variables can be
+// Generic and provider-independent Variable subclasses. These variables can be
// used by any state provider to implement simple variables to avoid repeat the
// same common code on different state providers.
@@ -19,24 +19,17 @@
// create copies of the provided object using the copy constructor of that
// class.
//
-// For example, a state provider exposing a private method as a variable could
-// be implemented in this way:
+// For example, a state provider exposing a private member as a variable can
+// implement this as follows:
//
-// * On something_vars.h:
-// Variable<MyType>* var_something;
-//
-// * On something_provider:
// class SomethingProvider {
// public:
// SomethingProvider(...) {
-// var_something = new CopyVariable<MyType>(priv_object_);
+// var_something_foo = new CopyVariable<MyType>(foo_);
// }
-// ~SomethingProvider() {
-// delete var_something;
-// var_something = NULL;
-// }
+// ...
// private:
-// MyType priv_object_;
+// MyType foo_;
// };
template<typename T>
class CopyVariable : public Variable<T> {
@@ -44,17 +37,20 @@
// Creates the variable returning copies of the passed |obj| reference. The
// reference to this object is kept and it should be available whenever the
// GetValue() method is called.
- CopyVariable(const T& obj);
+ CopyVariable(const T& ref) : ref_(ref) {};
virtual ~CopyVariable() {}
protected:
- friend class PMCopyVariableTest;
- FRIEND_TEST(PMCopyVariableTest, SimpleTest);
- FRIEND_TEST(PMCopyVariableTest, UseCopyConstructorTest);
+ friend class PmCopyVariableTest;
+ FRIEND_TEST(PmCopyVariableTest, SimpleTest);
+ FRIEND_TEST(PmCopyVariableTest, UseCopyConstructorTest);
// Variable override.
- virtual const T* GetValue(base::TimeDelta timeout, std::string* errmsg);
+ virtual const T* GetValue(base::TimeDelta /* timeout */,
+ std::string* /* errmsg */) {
+ return new T(ref_);
+ }
private:
// Reference to the object to be copied by GetValue().
@@ -63,7 +59,4 @@
} // namespace chromeos_policy_manager
-// Include implementation on header files for templates.
-#include "policy_manager/generic_variables-inl.h"
-
#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_GENERIC_VARIABLES_H