Cancel the current download if user chooses a different channel.

In my earlier CL, to keep the implementation simple, we disallowed changing
a channel until the previous change completed in its entirety. Given that
the UI is not going to be updated for M27, such a restriction turned out
to be very confusing when playing around with channel changing. So, we
decided to implement a simple form of canceling the download if the
user selected a different channel while we're downloading the bits. This
implementation can easily be extended to support a general form of cancel
in the future, if required.

This CL also adds validation of libchromeos API calls when interpreting
the policy values. It also cleans up some bogus error messages that were
logged earlier when we abort a download.

BUG=chromium:222617
TEST=All scenarios pass on ZGB. Unit Tests pass.

Change-Id: I7cd691fe461d9ce47314299f6e2598944650ee33
Reviewed-on: https://gerrit.chromium.org/gerrit/46095
Commit-Queue: Jay Srinivasan <jaysri@chromium.org>
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
diff --git a/update_attempter.h b/update_attempter.h
index 23b45c0..bcd730f 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -157,6 +157,12 @@
   // parameters used in the current update attempt.
   uint32_t GetErrorCodeFlags();
 
+  // Returns true if we should cancel the current download attempt based on the
+  // current state of the system, in which case |cancel_reason| indicates the
+  // reason for the cancellation.  False otherwise, in which case
+  // |cancel_reason| is untouched.
+  bool ShouldCancel(ActionExitCode* cancel_reason);
+
  private:
   // Update server URL for automated lab test.
   static const char* const kTestUpdateUrl;
@@ -238,6 +244,12 @@
   // update has been applied.
   void PingOmaha();
 
+  // Reloads the device policy from libchromeos. Note: This method doesn't
+  // cause a real-time policy fetch from the policy server. It just reloads the
+  // latest value that libchromeos has cached. libchromeos fetches the policies
+  // from the server asynchronously at its own frequency.
+  void RefreshDevicePolicy();
+
   // Helper method of Update() to calculate the update-related parameters
   // from various sources and set the appropriate state. Please refer to
   // Update() method for the meaning of the parametes.