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.h b/real_system_state.h
index df1280f..b9c0a26 100644
--- a/real_system_state.h
+++ b/real_system_state.h
@@ -7,6 +7,9 @@
 
 #include "update_engine/system_state.h"
 
+#include <policy/device_policy.h>
+
+#include "metrics/metrics_library.h"
 #include "update_engine/clock.h"
 #include "update_engine/connection_manager.h"
 #include "update_engine/gpio_handler.h"
@@ -24,77 +27,76 @@
 // used by the actual product code.
 class RealSystemState : public SystemState {
  public:
-  // Constructors and destructors.
+  // Constructs all system objects that do not require separate initialization;
+  // see Initialize() below for the remaining ones.
   RealSystemState();
-  virtual ~RealSystemState() {}
+
+  // Initializes and sets systems objects that require an initialization
+  // separately from construction. Returns |true| on success.
+  bool Initialize(bool enable_gpio);
 
   virtual inline void set_device_policy(
-      const policy::DevicePolicy* device_policy) {
+      const policy::DevicePolicy* device_policy) override {
     device_policy_ = device_policy;
   }
 
-  virtual inline const policy::DevicePolicy* device_policy() const {
+  virtual inline const policy::DevicePolicy* device_policy() override {
     return device_policy_;
   }
 
-  virtual inline ClockInterface* clock() {
+  virtual inline ClockInterface* clock() override {
     return &clock_;
   }
 
-  virtual inline ConnectionManager* connection_manager() {
+  virtual inline ConnectionManager* connection_manager() override {
     return &connection_manager_;
   }
 
-  virtual inline HardwareInterface* hardware() {
+  virtual inline HardwareInterface* hardware() override {
     return &hardware_;
   }
 
-  virtual inline MetricsLibraryInterface* metrics_lib() {
+  virtual inline MetricsLibraryInterface* metrics_lib() override {
     return &metrics_lib_;
   }
 
-  virtual inline PrefsInterface* prefs() {
+  virtual inline PrefsInterface* prefs() override {
     return &prefs_;
   }
 
-  virtual inline PrefsInterface* powerwash_safe_prefs() {
+  virtual inline PrefsInterface* powerwash_safe_prefs() override {
       return &powerwash_safe_prefs_;
     }
 
-  virtual inline PayloadStateInterface* payload_state() {
+  virtual inline PayloadStateInterface* payload_state() override {
     return &payload_state_;
   }
 
-  virtual inline GpioHandler* gpio_handler() const {
+  virtual inline GpioHandler* gpio_handler() override {
     return gpio_handler_.get();
   }
 
-  virtual inline UpdateAttempter* update_attempter() const override {
-    return update_attempter_.get();
+  virtual inline UpdateAttempter* update_attempter() override {
+    return &update_attempter_;
   }
 
-  // Returns a pointer to the object that stores the parameters that are
-  // common to all Omaha requests.
-  virtual inline OmahaRequestParams* request_params() {
+  virtual inline OmahaRequestParams* request_params() override {
     return &request_params_;
   }
 
-  virtual inline P2PManager* p2p_manager() {
+  virtual inline P2PManager* p2p_manager() override {
     return p2p_manager_.get();
   }
 
-  virtual inline chromeos_policy_manager::PolicyManager* policy_manager() {
+  virtual inline chromeos_policy_manager::PolicyManager* policy_manager()
+      override {
     return &policy_manager_;
   }
 
-  virtual inline bool system_rebooted() {
+  virtual inline bool system_rebooted() override {
     return system_rebooted_;
   }
 
-  // Initializes this concrete object. Other methods should be invoked only
-  // if the object has been initialized successfully.
-  bool Initialize(bool enable_gpio);
-
  private:
   // Interface for the clock.
   Clock clock_;
@@ -133,7 +135,7 @@
   RealDBusWrapper dbus_;
 
   // Pointer to the update attempter object.
-  scoped_ptr<UpdateAttempter> update_attempter_;
+  UpdateAttempter update_attempter_;
 
   // Common parameters for all Omaha requests.
   OmahaRequestParams request_params_;