update_engine: Use powerd for rebooting.

Make update_engine call powerd's RequestRestart method to
restart the system instead of running "shutdown -r now"
directly. This avoids races where Chrome asks powerd to shut
down the system but then update_engine sees that an update
has been applied and reboots it instead.

BUG=chromium:372074
TEST=applied an update and requested a reboot from the UI;
     checked that the request was logged by powerd. held the
     power button to shut down while an update was pending
     and checked that the system shut down instead of
     rebooting. built update_engine with the
     power_management USE flag unset and checked that it was
     still able to reboot the system.
CQ-DEPEND=I73f67cca9875b00bd944e4ff9779ad24fc4cd738
CQ-DEPEND=I2888fdde50a71460b74f2ef33d63ac00c5938626

Change-Id: Ic5f7c33c3f7fc5fe92ac8a2e1800830678cac235
Reviewed-on: https://chromium-review.googlesource.com/206074
Tested-by: Daniel Erat <derat@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Daniel Erat <derat@chromium.org>
diff --git a/update_attempter.h b/update_attempter.h
index b765a2b..420b876 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -34,6 +34,7 @@
 
 namespace chromeos_update_engine {
 
+class DBusWrapperInterface;
 class UpdateCheckScheduler;
 
 enum UpdateStatus {
@@ -347,6 +348,14 @@
   // |update_completed_marker_| is empty.
   void WriteUpdateCompletedMarker();
 
+  // Sends a D-Bus message to the Chrome OS power manager asking it to reboot
+  // the system. Returns true on success.
+  bool RequestPowerManagerReboot();
+
+  // Reboots the system directly by calling /sbin/shutdown. Returns true on
+  // success.
+  bool RebootDirectly();
+
   // Last status notification timestamp used for throttling. Use monotonic
   // TimeTicks to ensure that notifications are sent even if the system clock is
   // set back in the middle of an update.
@@ -359,6 +368,9 @@
   // carved out separately to mock out easily in unit tests.
   SystemState* system_state_;
 
+  // Interface for getting D-Bus connections.
+  DBusWrapperInterface* dbus_iface_ = nullptr;
+
   // If non-null, this UpdateAttempter will send status updates over this
   // dbus service.
   UpdateEngineService* dbus_service_ = nullptr;