PolicyManager: UpdateCheckAllowed policy initial implementation.
This patch implements the UpdateCheckAllowed policy for ChromeOS
using the same logic we had on update_check_scheduler.cc. It checks
for updates onces every 45 minutes and does an exponential backoff
up to 4 hours when the update check fails. Some other parts of the
policy are not implemented, such as retry an update check with a
short delay on certain failures.
BUG=chromium:358269
TEST=Unittests added to the policy.
Change-Id: Ief8deff47fd6490bd70a22ba20abed05fcc37ab4
Reviewed-on: https://chromium-review.googlesource.com/197595
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
diff --git a/policy_manager/policy_utils.h b/policy_manager/policy_utils.h
new file mode 100644
index 0000000..61e0413
--- /dev/null
+++ b/policy_manager/policy_utils.h
@@ -0,0 +1,26 @@
+// 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_UTILS_H_
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_POLICY_UTILS_H_
+
+#include "update_engine/policy_manager/policy.h"
+
+// Checks that the passed pointer value is not null, returning kFailed on the
+// current context and setting the *error description when it is null. The
+// intended use is to validate variable failures while using
+// EvaluationContext::GetValue, for example:
+//
+// const int* my_value = ec->GetValue(state->my_provider()->var_my_value());
+// POLICY_CHECK_VALUE_AND_FAIL(my_value, error);
+//
+#define POLICY_CHECK_VALUE_AND_FAIL(ptr, error) \
+ do { \
+ if ((ptr) == nullptr) { \
+ *(error) = #ptr " is required but is null."; \
+ return EvalStatus::kFailed; \
+ } \
+ } while (false)
+
+#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_POLICY_UTILS_H_