libweave: remove base::JSONReader::.*Deprecated methods

This is a libchrome post r680000 uprev cleanup.
This also changes relevant usages of base::{Dictioanry,List}Value to
base::Value and TODO for future cleanup.

BUG=chromium:1054279, chromium:1099111
TEST=cros_run_unit_tests --board=eve --packages libweave

Change-Id: I53374688d98ea0054ee9014f4da6d694412dd468
Reviewed-on: https://chromium-review.googlesource.com/c/weave/libweave/+/2286709
Tested-by: Grace Cham <hscham@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Grace Cham <hscham@chromium.org>
diff --git a/src/device_registration_info.cc b/src/device_registration_info.cc
index b8ca3a7..c5c6c00 100644
--- a/src/device_registration_info.cc
+++ b/src/device_registration_info.cc
@@ -61,6 +61,7 @@
                "Unexpected GCD error");
 }
 
+// TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to base::Value.
 void ParseGCDError(const base::DictionaryValue* json, ErrorPtr* error) {
   const base::Value* list_value = nullptr;
   const base::ListValue* error_list = nullptr;
@@ -194,6 +195,7 @@
   DISALLOW_COPY_AND_ASSIGN(RequestSender);
 };
 
+// TODO(crbug.com/1099111): change return type to base::Value.
 std::unique_ptr<base::DictionaryValue> ParseJsonResponse(
     const HttpClient::Response& response,
     ErrorPtr* error) {
@@ -210,28 +212,23 @@
   }
 
   const std::string& json = response.GetData();
-  std::string error_message;
-  // TODO(crbug/1066447): migrate to new ReadAndReturnError API after uprev.
-  auto value = base::JSONReader::ReadAndReturnErrorDeprecated(
-      json, base::JSON_PARSE_RFC, nullptr, &error_message);
-  if (!value) {
+  auto result =
+      base::JSONReader::ReadAndReturnValueWithError(json, base::JSON_PARSE_RFC);
+  if (!result.value) {
     Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
                        errors::json::kParseError,
                        "Error '%s' occurred parsing JSON string '%s'",
-                       error_message.c_str(), json.c_str());
+                       result.error_message.c_str(), json.c_str());
     return std::unique_ptr<base::DictionaryValue>();
   }
   base::DictionaryValue* dict_value = nullptr;
-  if (!value->GetAsDictionary(&dict_value)) {
+  if (!result.value->GetAsDictionary(&dict_value)) {
     Error::AddToPrintf(
         error, FROM_HERE, errors::json::kDomain, errors::json::kObjectExpected,
         "Response is not a valid JSON object: '%s'", json.c_str());
     return std::unique_ptr<base::DictionaryValue>();
-  } else {
-    // |value| is now owned by |dict_value|, so release the unique_ptr now.
-    base::IgnoreResult(value.release());
   }
-  return std::unique_ptr<base::DictionaryValue>(dict_value);
+  return std::make_unique<base::DictionaryValue>(std::move(*dict_value));
 }
 
 bool IsSuccessful(const HttpClient::Response& response) {
@@ -490,6 +487,7 @@
   callback.Run(gcd_state_);
 }
 
+// TODO(crbug.com/1099111): change return type to base::Value.
 std::unique_ptr<base::DictionaryValue>
 DeviceRegistrationInfo::BuildDeviceResource(ErrorPtr* error) {
   // Limit only to commands that are visible to the cloud.
diff --git a/src/device_registration_info.h b/src/device_registration_info.h
index aee43d8..bda4091 100644
--- a/src/device_registration_info.h
+++ b/src/device_registration_info.h
@@ -50,6 +50,8 @@
 class DeviceRegistrationInfo : public NotificationDelegate,
                                public CloudCommandUpdateInterface {
  public:
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   using CloudRequestDoneCallback =
       base::Callback<void(const base::DictionaryValue& response,
                           ErrorPtr error)>;
@@ -113,6 +115,8 @@
   void SwitchXmppChannel(const std::string& channel);
 
   // Updates a command (override from CloudCommandUpdateInterface).
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void UpdateCommand(const std::string& command_id,
                      const base::DictionaryValue& command_patch,
                      const DoneCallback& callback) override;
@@ -158,6 +162,8 @@
 
   // Parse the OAuth response, and sets registration status to
   // kInvalidCredentials if our registration is no longer valid.
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   std::unique_ptr<base::DictionaryValue> ParseOAuthResponse(
       const provider::HttpClient::Response& response,
       ErrorPtr* error);
@@ -171,6 +177,8 @@
   // and device removal.  It is a recommended way to do cloud API
   // requests.
   // TODO(antonm): Consider moving into some other class.
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void DoCloudRequest(provider::HttpClient::Method method,
                       const std::string& url,
                       const base::DictionaryValue* body,
@@ -196,12 +204,16 @@
 
   void UpdateDeviceResource(const DoneCallback& callback);
   void StartQueuedUpdateDeviceResource();
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void OnUpdateDeviceResourceDone(const base::DictionaryValue& device_info,
                                   ErrorPtr error);
   void OnUpdateDeviceResourceError(ErrorPtr error);
 
   // Callback from GetDeviceInfo() to retrieve the device resource timestamp
   // and retry UpdateDeviceResource() call.
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void OnDeviceInfoRetrieved(const base::DictionaryValue& device_info,
                              ErrorPtr error);
 
@@ -209,11 +221,17 @@
   // |last_device_resource_updated_timestamp_|.
   // Returns false if the "lastUpdateTimeMs" field is not found in the device
   // resource or it is invalid.
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   bool UpdateDeviceInfoTimestamp(const base::DictionaryValue& device_info);
 
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void FetchCommands(
       const base::Callback<void(const base::ListValue&, ErrorPtr)>& callback,
       const std::string& reason);
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void OnFetchCommandsDone(
       const base::Callback<void(const base::ListValue&, ErrorPtr)>& callback,
       const base::DictionaryValue& json,
@@ -225,10 +243,16 @@
   // Processes the command list that is fetched from the server on connection.
   // Aborts commands which are in transitional states and publishes queued
   // commands which are queued.
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void ProcessInitialCommandList(const base::ListValue& commands,
                                  ErrorPtr error);
 
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void PublishCommands(const base::ListValue& commands, ErrorPtr error);
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void PublishCommand(const base::DictionaryValue& command);
 
   // Helper function to pull the pending command list from the server using
@@ -238,6 +262,8 @@
   void FetchAndPublishCommands(const std::string& reason);
 
   void PublishStateUpdates();
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void OnPublishStateDone(StateChangeQueueInterface::UpdateID update_id,
                           const base::DictionaryValue& reply,
                           ErrorPtr error);
@@ -250,6 +276,8 @@
   // Builds Cloud API devices collection REST resource which matches
   // current state of the device including command definitions
   // for all supported commands and current device state.
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   std::unique_ptr<base::DictionaryValue> BuildDeviceResource(ErrorPtr* error);
 
   void SetGcdState(GcdState new_state);
@@ -266,6 +294,8 @@
   void OnConnected(const std::string& channel_name) override;
   void OnDisconnected() override;
   void OnPermanentFailure() override;
+  // TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to
+  // base::Value.
   void OnCommandCreated(const base::DictionaryValue& command,
                         const std::string& channel_name) override;
   void OnDeviceDeleted(const std::string& cloud_id) override;
diff --git a/src/test/unittest_utils.cc b/src/test/unittest_utils.cc
index 9b99699..0e5cd77 100644
--- a/src/test/unittest_utils.cc
+++ b/src/test/unittest_utils.cc
@@ -9,6 +9,7 @@
 #include <base/json/json_reader.h>
 #include <base/json/json_writer.h>
 #include <base/logging.h>
+#include <base/values.h>
 
 namespace weave {
 namespace test {
@@ -17,15 +18,11 @@
   std::string json2(json);
   // Convert apostrophes to double-quotes so JSONReader can parse the string.
   std::replace(json2.begin(), json2.end(), '\'', '"');
-  int error = 0;
-  std::string message;
-  // TODO(crbug/1066447): migrate to new ReadAndReturnError API after uprev.
-  std::unique_ptr<base::Value> value{
-      base::JSONReader::ReadAndReturnErrorDeprecated(
-          json2, base::JSON_PARSE_RFC, &error, &message)
-          .release()};
-  CHECK(value) << "Failed to load JSON: " << message << ", " << json;
-  return value;
+  auto result = base::JSONReader::ReadAndReturnValueWithError(
+      json2, base::JSON_PARSE_RFC);
+  CHECK(result.value) << "Failed to load JSON: " << result.error_message << ", "
+                      << json;
+  return base::Value::ToUniquePtrValue(std::move(*result.value));
 }
 
 std::string ValueToString(const base::Value& value) {
diff --git a/src/utils.cc b/src/utils.cc
index daefd33..f3d87f8 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -4,6 +4,8 @@
 
 #include "src/utils.h"
 
+#include <utility>
+
 #include <base/bind_helpers.h>
 #include <base/json/json_reader.h>
 
@@ -38,32 +40,25 @@
 std::unique_ptr<base::DictionaryValue> LoadJsonDict(
     const std::string& json_string,
     ErrorPtr* error) {
-  std::unique_ptr<base::DictionaryValue> result;
-  std::string error_message;
-  // TODO(crbug/1066447): migrate to new ReadAndReturnError API after uprev.
-  auto value = base::JSONReader::ReadAndReturnErrorDeprecated(
-      json_string, base::JSON_PARSE_RFC, nullptr, &error_message);
-  if (!value) {
+  auto result = base::JSONReader::ReadAndReturnValueWithError(
+      json_string, base::JSON_PARSE_RFC);
+  if (!result.value) {
     Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
                        errors::json::kParseError,
                        "Error parsing JSON string '%s' (%zu): %s",
                        LimitString(json_string, kMaxStrLen).c_str(),
-                       json_string.size(), error_message.c_str());
-    return result;
+                       json_string.size(), result.error_message.c_str());
+    return std::make_unique<base::DictionaryValue>();
   }
   base::DictionaryValue* dict_value = nullptr;
-  if (!value->GetAsDictionary(&dict_value)) {
+  if (!result.value->GetAsDictionary(&dict_value)) {
     Error::AddToPrintf(error, FROM_HERE, errors::json::kDomain,
                        errors::json::kObjectExpected,
                        "JSON string '%s' is not a JSON object",
                        LimitString(json_string, kMaxStrLen).c_str());
-    return result;
-  } else {
-    // |value| is now owned by |dict_value|.
-    base::IgnoreResult(value.release());
+    return std::make_unique<base::DictionaryValue>();
   }
-  result.reset(dict_value);
-  return result;
+  return std::make_unique<base::DictionaryValue>(std::move(*dict_value));
 }
 
 std::unique_ptr<base::DictionaryValue> ErrorInfoToJson(const Error& error) {
diff --git a/src/utils.h b/src/utils.h
index bd69e94..136a216 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -26,10 +26,12 @@
 const char kDefaultCategory[] = "";
 
 // Helper function to load a JSON dictionary from a string.
+// TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to base::Value
 std::unique_ptr<base::DictionaryValue> LoadJsonDict(
     const std::string& json_string,
     ErrorPtr* error);
 
+// TODO(crbug.com/1099111): change base::{Dictioanry,List}Value to base::Value
 std::unique_ptr<base::DictionaryValue> ErrorInfoToJson(const Error& error);
 
 }  // namespace weave