Blacklist versions as part of Rollback along with unittests.

This CL adds version blacklisting as part of AU Rollback. A few additional
things:

1) Since this pref must persist across rollback I have introduced a
powerwash_safe_prefs as part of system_state that will persist across
powerwashes.
2) Fixed bug where we needed to read the device policy (which is read during an
update_check before Rollback would work).
3) Some refactoring to move pref constants to constants.
4) Passing keepimg into our powerwash command so we don't wipe the old
partitions.

BUG=chromium:252589 chromium:254217
TEST=Unittests + test on device + using rollback with and without powerwash
checking preserve state.

Change-Id: I991fad944594944425fd9941e10b30a919f2b83b
Reviewed-on: https://gerrit.chromium.org/gerrit/59518
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Chris Sosa <sosa@chromium.org>
diff --git a/payload_state.h b/payload_state.h
index 7c0d0d3..3c88622 100644
--- a/payload_state.h
+++ b/payload_state.h
@@ -40,6 +40,7 @@
   virtual void UpdateSucceeded();
   virtual void UpdateFailed(ErrorCode error);
   virtual bool ShouldBackoffDownload();
+  virtual void Rollback();
 
   virtual inline std::string GetResponseSignature() {
     return response_signature_;
@@ -87,6 +88,10 @@
 
   virtual void UpdateEngineStarted();
 
+  virtual inline std::string GetRollbackVersion() {
+    return rollback_version_;
+  }
+
  private:
   // Increments the payload attempt number which governs the backoff behavior
   // at the time of the next update check.
@@ -138,8 +143,9 @@
   void ResetDownloadSourcesOnNewUpdate();
 
   // Returns the persisted value for the given key. It also validates that
-  // the value returned is non-negative.
-  int64_t GetPersistedValue(const std::string& key);
+  // the value returned is non-negative. If |across_powerwash| is True,
+  // get the value that will persist across a powerwash.
+  int64_t GetPersistedValue(const std::string& key, bool across_powerwash);
 
   // Calculates the response "signature", which is basically a string composed
   // of the subset of the fields in the current response that affect the
@@ -249,6 +255,16 @@
                                uint64_t total_bytes_downloaded,
                                bool log);
 
+  // Loads the blacklisted version from our prefs file.
+  void LoadRollbackVersion();
+
+  // Blacklists this version from getting AU'd to until we receive a new update
+  // response.
+  void SetRollbackVersion(const std::string& rollback_version);
+
+  // Clears any blacklisted version.
+  void ResetRollbackVersion();
+
   inline uint32_t GetUrlIndex() {
     return url_index_;
   }
@@ -297,6 +313,11 @@
   // be set by calling the Initialize method before calling any other method.
   PrefsInterface* prefs_;
 
+  // Interface object with which we read/write persisted state. This must
+  // be set by calling the Initialize method before calling any other method.
+  // This object persists across powerwashes.
+  PrefsInterface* powerwash_safe_prefs_;
+
   // This is the current response object from Omaha.
   OmahaResponse response_;
 
@@ -390,6 +411,12 @@
   // allowed as per device policy.
   std::vector<std::string> candidate_urls_;
 
+  // This stores a blacklisted version set as part of rollback. When we rollback
+  // we store the version of the os from which we are rolling back from in order
+  // to guarantee that we do not re-update to it on the next au attempt after
+  // reboot.
+  std::string rollback_version_;
+
   DISALLOW_COPY_AND_ASSIGN(PayloadState);
 };