update_engine: New BootControlInterface class.

The new BootControlInterface class is a platform-independent
abstraction to control the bootloader. It provides methods for setting
what partition slots are available for booting and getting the
bootloader status about the available slots.

The Chrome OS specific implementation of the bootloader was moved to
the BootControlChromeOS which now depends on the vboot_host
implementation used in Chrome OS. Follow up CL will implement the
equivalent class for Brillo.

BUG=b:23010637
TEST=unittests; cros flash from the new image and rolled back from it.

Change-Id: I0a03aeeb8c21d8c99e1866b625e6e8c96628215b
diff --git a/payload_state.cc b/payload_state.cc
index e7904c1..78c048b 100644
--- a/payload_state.cc
+++ b/payload_state.cc
@@ -1422,8 +1422,14 @@
       LOG(ERROR) << "Error reading TargetVersionInstalledFrom on reboot.";
       return;
     }
-    if (static_cast<int>(installed_from) ==
-        utils::GetPartitionNumber(system_state_->hardware()->BootDevice())) {
+    // Old Chrome OS devices will write 2 or 4 in this setting, with the
+    // partition number. We are now using slot numbers (0 or 1) instead, so
+    // the following comparison will not match if we are comparing an old
+    // partition number against a new slot number, which is the correct outcome
+    // since we successfully booted the new update in that case. If the boot
+    // failed, we will read this value from the same version, so it will always
+    // be compatible.
+    if (installed_from == system_state_->boot_control()->GetCurrentSlot()) {
       // A reboot was pending, but the chromebook is again in the same
       // BootDevice where the update was installed from.
       int64_t target_attempt;
@@ -1483,8 +1489,7 @@
   prefs_->SetInt64(kPrefsTargetVersionAttempt, target_attempt + 1);
 
   prefs_->SetInt64(kPrefsTargetVersionInstalledFrom,
-                    utils::GetPartitionNumber(
-                        system_state_->hardware()->BootDevice()));
+                   system_state_->boot_control()->GetCurrentSlot());
 }
 
 void PayloadState::ResetUpdateStatus() {
@@ -1496,7 +1501,7 @@
   // Also decrement the attempt number if it exists.
   int64_t target_attempt;
   if (prefs_->GetInt64(kPrefsTargetVersionAttempt, &target_attempt))
-    prefs_->SetInt64(kPrefsTargetVersionAttempt, target_attempt-1);
+    prefs_->SetInt64(kPrefsTargetVersionAttempt, target_attempt - 1);
 }
 
 int PayloadState::GetP2PNumAttempts() {