PolicyManager: Schedule re-evaluations based on variable usage.

This patch makes the EvaluationContext re-schedule a policy request
based on the variables used by that method, waiting for the Async
variables and polling the Poll variables on the suggested interval.

In order to use the main loop functions from the EvaluationContext
they were moved to its own file called event_loop.h.

BUG=chromium:340871
TEST=Unit tests added.

Change-Id: Ibfc52e4dfd12c5e1ef87b5ad9cc318f9821dcfdd
Reviewed-on: https://chromium-review.googlesource.com/190424
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/policy_manager/policy_manager.cc b/policy_manager/policy_manager.cc
index 1357707..4f19f99 100644
--- a/policy_manager/policy_manager.cc
+++ b/policy_manager/policy_manager.cc
@@ -13,8 +13,8 @@
 
 template <typename T>
 bool InitProvider(scoped_ptr<T>* handle_ptr, T* provider) {
-   handle_ptr->reset(provider);
-   return handle_ptr->get() && (*handle_ptr)->Init();
+  handle_ptr->reset(provider);
+  return handle_ptr->get() && (*handle_ptr)->Init();
 }
 
 bool PolicyManager::Init(State* state) {
@@ -27,28 +27,4 @@
   return true;
 }
 
-void PolicyManager::RunFromMainLoop(const Closure& callback) {
-  Closure* callback_p = new base::Closure(callback);
-  g_idle_add_full(G_PRIORITY_DEFAULT,
-                  OnRanFromMainLoop,
-                  reinterpret_cast<gpointer>(callback_p),
-                  NULL);
-}
-
-void PolicyManager::RunFromMainLoopAfterTimeout(
-    const Closure& callback,
-    base::TimeDelta timeout) {
-  Closure* callback_p = new Closure(callback);
-  g_timeout_add_seconds(timeout.InSeconds(),
-                        OnRanFromMainLoop,
-                        reinterpret_cast<gpointer>(callback_p));
-}
-
-gboolean PolicyManager::OnRanFromMainLoop(gpointer user_data) {
-  Closure* callback_p = reinterpret_cast<Closure*>(user_data);
-  callback_p->Run();
-  delete callback_p;
-  return FALSE;  // Removes the source since a callback can only be called once.
-}
-
 }  // namespace chromeos_policy_manager