PolicyManager: New main PolicyManager class.

The PolicyManager class is the singleton instance used by the Update
Engine to make policy requests. The PolicyManager uses a Policy pure
virtual class with the definition of all the public policy
implementation. Different platforms can implement a different
subclass of it or extend the existing one.

The Policy class comprises the set of policy related decision and
the logic implementing those.

This patch includes a new PolicyManager class and a sample Policy
for ChromeOS that will be extended when the actual policies are
migrated to this framework. A default policy is also included and
is used whenever the actual policy fails, as a safe default.

BUG=chromium:338591
TEST=Unit tests pass.

Change-Id: If60c87d8cb9031eb15b6d4d5e937f65f56c79a04
Reviewed-on: https://chromium-review.googlesource.com/186884
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/policy_manager/policy_manager-inl.h b/policy_manager/policy_manager-inl.h
new file mode 100644
index 0000000..6c99be2
--- /dev/null
+++ b/policy_manager/policy_manager-inl.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_POLICY_MANAGER_INL_H
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_POLICY_MANAGER_INL_H
+
+#include "update_engine/policy_manager/evaluation_context.h"
+
+namespace chromeos_policy_manager {
+
+// Provider of random values.
+template<typename T, typename R, typename... Args>
+EvalStatus PolicyManager::PolicyRequest(T policy_method, R* result,
+                                        Args... args) {
+  EvaluationContext ec;
+  std::string error;
+
+  // First try calling the actual policy.
+  EvalStatus status = (policy_.get()->*policy_method)(&ec, &error, result,
+                                                      args...);
+
+  if (status == EvalStatusFailed) {
+    LOG(WARNING) << "PolicyRequest() failed with error: " << error;
+    error.clear();
+    status = (default_policy_.*policy_method)(&ec, &error, result, args...);
+
+    if (status == EvalStatusFailed) {
+      LOG(WARNING) << "Request to DefaultPolicy also failed, passing error.";
+    }
+  }
+  // TODO(deymo): Log the actual state used from the EvaluationContext.
+  return status;
+}
+
+}  // namespace chromeos_policy_manager
+
+#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_POLICY_MANAGER_INL_H