Revise the SystemState hierarchy.

* Removed all #includes from SystemState; added includes in .cc files
  that use the various objects (MetricsLibrary, DevicePolicy, etc).

* MockSystemState:

  - Regulated the set of getters/setters: foo() returns the current Foo
    object interface; this object can be overridden by set_foo();
    mock_foo() or fake_foo() returns the default (internal) mock/fake
    equivalent, and fails if it is different from foo() (safety).

  - Make member declaration order consistent with that of API.

  - Removed MOCK_METHOD declarations for two methods and replaced them
    with fake getter/setter. This means that MockSystemState is now
    reduced to a fake, and can be renamed (separate CL). This also means
    that a few tests have a slightly different semantics now.

* All virtual overrides are qualified as such. However, removed the
  'const' method qualified from all getters: it made little sense,
  especially when considering that getters are handing addresses of
  internal mock members.

* Made the UpdateAttempter a contained member of both
  {Real,Mock}SystemState, resolving initialization dependencies. In
  general, the invariant is that all members of the SystemState that
  rely on it being fully populated by the time of their initialization,
  need to export a separate Init() method, that will be called (by the
  SystemState implementation constructor or Init() method) only after
  all members are set.

* Made the mock GPIO handler and connection manager contained members of
  MockSystemState; the destructor could safely be moved.

* Cleanup in UpdateAttempter (part of resolving dependencies):

  - Ordinary member initialization done via default initializers
    (constants) or initializer list in the constructor (parameters).

  - Init() method only does work that cannot be done during
    construction, with appropriate comment documenting the need for it.

  - Better reuse via constructor delegation.

BUG=chromium:358278
TEST=Unit tests.

Change-Id: I96ff6fc7e7400b0a9feb6cc8d4ffe97a51000f91
Reviewed-on: https://chromium-review.googlesource.com/193587
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
diff --git a/real_system_state.cc b/real_system_state.cc
index eb8a2ba..b06830f 100644
--- a/real_system_state.cc
+++ b/real_system_state.cc
@@ -5,7 +5,6 @@
 #include "update_engine/real_system_state.h"
 
 #include <base/file_util.h>
-#include <base/time/time.h>
 
 #include "update_engine/constants.h"
 #include "update_engine/policy_manager/state_factory.h"
@@ -16,8 +15,8 @@
 RealSystemState::RealSystemState()
     : device_policy_(nullptr),
       connection_manager_(this),
+      update_attempter_(this, &dbus_),
       request_params_(this),
-      p2p_manager_(),
       system_rebooted_(false) {}
 
 bool RealSystemState::Initialize(bool enable_gpio) {
@@ -45,11 +44,16 @@
                                            kMaxP2PFilesToKeep));
 
   // Initialize the PolicyManager using the default State Factory.
-  policy_manager_.Init(
-      chromeos_policy_manager::DefaultStateFactory(&dbus_, this));
-
-  if (!payload_state_.Initialize(this))
+  if (!policy_manager_.Init(
+          chromeos_policy_manager::DefaultStateFactory(&dbus_, this))) {
+    LOG(ERROR) << "Failed to initialize the policy manager.";
     return false;
+  }
+
+  if (!payload_state_.Initialize(this)) {
+    LOG(ERROR) << "Failed to initialize the payload state object.";
+    return false;
+  }
 
   // Initialize the GPIO handler as instructed.
   if (enable_gpio) {
@@ -67,8 +71,8 @@
     gpio_handler_.reset(new NoopGpioHandler(false));
   }
 
-  // Create the update attempter.
-  update_attempter_.reset(new UpdateAttempter(this, &dbus_));
+  // Initialize the update attempter.
+  update_attempter_.Init();
 
   // All is well. Initialization successful.
   return true;