Replace Get* methods returning unique_ptr with reference alternative

Existing code created temporarily objects and returned them to the
client. It was not efficient and error-prone as client code could
retrieve pointers to internal objects without keeping unique_ptr alive.

Change-Id: I9e17c8d9f66dfc9f52ce9ffc9a31992b16b00461
Reviewed-on: https://weave-review.googlesource.com/1672
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/src/device_registration_info.cc b/src/device_registration_info.cc
index 5c8625a..0c914b7 100644
--- a/src/device_registration_info.cc
+++ b/src/device_registration_info.cc
@@ -485,8 +485,7 @@
   if (!commands)
     return nullptr;
 
-  std::unique_ptr<base::DictionaryValue> state = state_manager_->GetState();
-  CHECK(state);
+  const base::DictionaryValue& state = state_manager_->GetState();
 
   std::unique_ptr<base::DictionaryValue> resource{new base::DictionaryValue};
   if (!GetSettings().cloud_id.empty())
@@ -507,7 +506,7 @@
   }
   resource->Set("channel", channel.release());
   resource->Set("commandDefs", commands.release());
-  resource->Set("state", state.release());
+  resource->Set("state", state.DeepCopy());
 
   return resource;
 }