buffet: Change shared ownership of types/values to exclusive

In order to support array types in Buffet's type system, PropValue
must maintain a strong reference to the underlying PropType since
the array elements will have their own type reference and the current
implementation of using raw pointer for this isn't going to work.
In order to resolve this I had to make a lot of changes to the object
ownership inside Buffet's type system. I made it possible for both
PropType and PropValue to make a deep copy of itself using their
Clone() methods. Because of this now it is possible to have exclusive
ownership of objects and I got rid of most of shared pointer usage in
ObjectSchema, PropType and PropValue.

BUG=brillo:107
TEST=`FEATURES=test emerge-link buffet`

Change-Id: I02de455dfd40d4833041b63cbb80bcb00293b5a9
Reviewed-on: https://chromium-review.googlesource.com/261336
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/prop_values.h b/buffet/commands/prop_values.h
index bf0d88d..6f85a0c 100644
--- a/buffet/commands/prop_values.h
+++ b/buffet/commands/prop_values.h
@@ -69,9 +69,13 @@
 //     This is used to validate the values against "enum"/"one of" constraints.
 class PropValue {
  public:
-  explicit PropValue(const PropType* type)
-      : type_(type) {}
-  virtual ~PropValue() = default;
+  explicit PropValue(std::unique_ptr<const PropType> type);
+  // Special out-of-line constructor to help implement PropValue::Clone().
+  // That method needs to clone the underlying type but can't do this in this
+  // header file since PropType is just forward-declared (it needs PropValue
+  // fully defined in its own inner workings).
+  explicit PropValue(const PropType* type_ptr);
+  virtual ~PropValue();
 
   // Gets the type of the value.
   virtual ValueType GetType() const = 0;
@@ -89,7 +93,7 @@
   virtual ObjectValue const* GetObject() const { return nullptr; }
 
   // Makes a full copy of this value class.
-  virtual std::shared_ptr<PropValue> Clone() const = 0;
+  virtual std::unique_ptr<PropValue> Clone() const = 0;
 
   // Saves the value as a JSON object.
   // If it fails, returns nullptr value and fills in the details for the
@@ -106,12 +110,12 @@
   virtual chromeos::Any GetValueAsAny() const = 0;
 
   // Return the type definition of this value.
-  const PropType* GetPropType() const { return type_; }
+  const PropType* GetPropType() const { return type_.get(); }
   // Compares two values and returns true if they are equal.
   virtual bool IsEqual(const PropValue* value) const = 0;
 
  protected:
-  const PropType* type_;  // weak pointer
+  std::unique_ptr<const PropType> type_;
 };
 
 // A helper template base class for implementing simple (non-Object) value
@@ -127,8 +131,11 @@
 
   // Overrides from PropValue base class.
   ValueType GetType() const override { return GetValueType<T>(); }
-  std::shared_ptr<PropValue> Clone() const override {
-    return std::make_shared<Derived>(*static_cast<const Derived*>(this));
+
+  std::unique_ptr<PropValue> Clone() const override {
+    std::unique_ptr<Derived> derived{new Derived{type_.get()}};
+    derived->value_ = value_;
+    return std::move(derived);
   }
 
   std::unique_ptr<base::Value> ToJson(