update_engine: Ditch UpdateCheckScheduler, use UpdateCheckAllowed instead.

This change removes the update_check_scheduler module and replaces it
with async requests to the UpdateCheckAllowed policy, done by the
UpdateAttempter directly.

* A new UpdateAttempter::ScheduleUpdates() is used as a replacement for
  UpdateCheckScheduler::Run() and rescheduling of periodic checks inside
  UpdateCheckScheduler. The callback
  UpdateAttempter::OnUpdateScheduled() handles both periodic and
  interactive checks.

* The UpdateAttempter keeps track of whether or not an update check is
  being waited for (waiting_for_scheduled_check_) so that we can ensure
  liveness. This is a similar check to the one performed inside the
  UpdateCheckScheduler.

* Inference of the update target version prefix and channel (via device
  policy), as well as update disabled, are now performed by the
  UpdateManager policy. Also eliminating reference to the list of
  network types allowed by policy, which is not enforced anyway and will
  be superceded by another policy request (UpdateDownloadAllowed).

* Since update check scheduling is now performed relative to the last
  update check time (as recorded by the UpdateAttempter), we care to
  update this time as soon as the request is issued (in addition to when
  a response is received). This ensures that we won't be scheduling
  back-to-back update requests in the case where a response was not
  received.  Updating the last check time is delegated to a method call;
  we replace raw use of time(2) with the ClockInterface abstraction.

* Handling of forced update checks has been revised: the UpdateAttempter
  keeps track of the most recent app_version and omaha_url values that
  were received through DBus events; it notifies the UpdateManager not
  only of whether or not a forced (formerly, "interactive") update
  request is pending, but also whether or not it is indeed interactive
  or should be treated as a normal periodic one. The UpdateManager
  reflects this back to the updater via the result output of
  UpdateCheckAllowed, which tells the UpdateManager whether the custom
  app_version and omaha_url should be used (interactive) or not.

BUG=chromium:358269
TEST=Unit tests.

Change-Id: Ifa9857b98e58fdd974f91a0fec674fa4472e3a9d
Reviewed-on: https://chromium-review.googlesource.com/209101
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/update_manager/boxed_value.cc b/update_manager/boxed_value.cc
index 56b42b8..773431c 100644
--- a/update_manager/boxed_value.cc
+++ b/update_manager/boxed_value.cc
@@ -24,56 +24,56 @@
 // Keep in sync with boxed_value_unitttest.cc.
 
 template<>
-string BoxedValue::ValuePrinter<string>(const void *value) {
+string BoxedValue::ValuePrinter<string>(const void* value) {
   const string* val = reinterpret_cast<const string*>(value);
   return *val;
 }
 
 template<>
-string BoxedValue::ValuePrinter<int>(const void *value) {
+string BoxedValue::ValuePrinter<int>(const void* value) {
   const int* val = reinterpret_cast<const int*>(value);
   return base::IntToString(*val);
 }
 
 template<>
-string BoxedValue::ValuePrinter<unsigned int>(const void *value) {
+string BoxedValue::ValuePrinter<unsigned int>(const void* value) {
   const unsigned int* val = reinterpret_cast<const unsigned int*>(value);
   return base::UintToString(*val);
 }
 
 template<>
-string BoxedValue::ValuePrinter<int64_t>(const void *value) {
+string BoxedValue::ValuePrinter<int64_t>(const void* value) {
   const int64_t* val = reinterpret_cast<const int64_t*>(value);
   return base::Int64ToString(*val);
 }
 
 template<>
-string BoxedValue::ValuePrinter<uint64_t>(const void *value) {
+string BoxedValue::ValuePrinter<uint64_t>(const void* value) {
   const uint64_t* val =
     reinterpret_cast<const uint64_t*>(value);
   return base::Uint64ToString(static_cast<uint64_t>(*val));
 }
 
 template<>
-string BoxedValue::ValuePrinter<bool>(const void *value) {
+string BoxedValue::ValuePrinter<bool>(const void* value) {
   const bool* val = reinterpret_cast<const bool*>(value);
   return *val ? "true" : "false";
 }
 
 template<>
-string BoxedValue::ValuePrinter<double>(const void *value) {
+string BoxedValue::ValuePrinter<double>(const void* value) {
   const double* val = reinterpret_cast<const double*>(value);
   return base::DoubleToString(*val);
 }
 
 template<>
-string BoxedValue::ValuePrinter<base::Time>(const void *value) {
+string BoxedValue::ValuePrinter<base::Time>(const void* value) {
   const base::Time* val = reinterpret_cast<const base::Time*>(value);
   return chromeos_update_engine::utils::ToString(*val);
 }
 
 template<>
-string BoxedValue::ValuePrinter<base::TimeDelta>(const void *value) {
+string BoxedValue::ValuePrinter<base::TimeDelta>(const void* value) {
   const base::TimeDelta* val = reinterpret_cast<const base::TimeDelta*>(value);
   return chromeos_update_engine::utils::FormatTimeDelta(*val);
 }
@@ -98,13 +98,13 @@
 }
 
 template<>
-string BoxedValue::ValuePrinter<ConnectionType>(const void *value) {
+string BoxedValue::ValuePrinter<ConnectionType>(const void* value) {
   const ConnectionType* val = reinterpret_cast<const ConnectionType*>(value);
   return ConnectionTypeToString(*val);
 }
 
 template<>
-string BoxedValue::ValuePrinter<set<ConnectionType>>(const void *value) {
+string BoxedValue::ValuePrinter<set<ConnectionType>>(const void* value) {
   string ret = "";
   const set<ConnectionType>* val =
       reinterpret_cast<const set<ConnectionType>*>(value);
@@ -118,7 +118,7 @@
 }
 
 template<>
-string BoxedValue::ValuePrinter<ConnectionTethering>(const void *value) {
+string BoxedValue::ValuePrinter<ConnectionTethering>(const void* value) {
   const ConnectionTethering* val =
       reinterpret_cast<const ConnectionTethering*>(value);
   switch (*val) {
@@ -136,7 +136,7 @@
 }
 
 template<>
-string BoxedValue::ValuePrinter<Stage>(const void *value) {
+string BoxedValue::ValuePrinter<Stage>(const void* value) {
   const Stage* val = reinterpret_cast<const Stage*>(value);
   switch (*val) {
     case Stage::kIdle:
@@ -162,4 +162,20 @@
   return "Unknown";
 }
 
+template<>
+string BoxedValue::ValuePrinter<UpdateRequestStatus>(const void* value) {
+  const UpdateRequestStatus* val =
+      reinterpret_cast<const UpdateRequestStatus*>(value);
+  switch (*val) {
+    case UpdateRequestStatus::kNone:
+      return "None";
+    case UpdateRequestStatus::kInteractive:
+      return "Interactive";
+    case UpdateRequestStatus::kPeriodic:
+      return "Periodic";
+  }
+  NOTREACHED();
+  return "Unknown";
+}
+
 }  // namespace chromeos_update_manager