update_engine: Make SystemState pointer static only

The style guide does not allow a global object with non-trivial dtor. It
can cause hidden problems and it has caused issue this CL is
fixing (look at the attached bug). Instead of keeping the ownership of
the SystemState in global, we can keep the ownership in the high level
object DaemonChromeOS and keep a global static pointer to it so it can
easily be accessed by SystemState::Get().

BUG=b:174212887
TEST=cros_workon_make --board reef --test update_engine
TEST=cros deploy + stop update-engine -> The update_engine did not crash anymore.

Change-Id: I442f4220bfd8586c59fcdfd7d699776362143467
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/2566875
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/cros/daemon_chromeos.h b/cros/daemon_chromeos.h
index ab9d4b2..b23c2a6 100644
--- a/cros/daemon_chromeos.h
+++ b/cros/daemon_chromeos.h
@@ -23,6 +23,7 @@
 #include "update_engine/common/daemon_state_interface.h"
 #include "update_engine/common/subprocess.h"
 #include "update_engine/cros/dbus_service.h"
+#include "update_engine/cros/real_system_state.h"
 
 namespace chromeos_update_engine {
 
@@ -39,6 +40,13 @@
   // initialization.
   void OnDBusRegistered(bool succeeded);
 
+  // |SystemState| is a global context, but we can't have a static singleton of
+  // its object because the style guide does not allow that (it has non-trivial
+  // dtor). We need an instance of |SystemState| in this class instead and have
+  // a global pointer to it. This is better to be defined as the first variable
+  // of this class so it is initialized first and destructed last.
+  RealSystemState system_state_;
+
   // Main D-Bus service adaptor.
   std::unique_ptr<UpdateEngineAdaptor> dbus_adaptor_;