Migrate ash/services/device_sync to new pref update classes.

ListPrefUpdate and DictPrefUpdate are now deprecated, in favor of
ScopedListPrefUpdate and ScopedDictPrefUpdate, which only expose
Value::List and Valud::Dict, respectively, to discourage use of other
APIs to manipulate lists and dicts, which are all deprecated.

Also update some of the surrounding code to use Value::Dict to create
dicts, instead of deprecated Set.*Key calls.

Bug: 1362719
Change-Id: I9cef00fba73aac640c23a6a106c697a85622abf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3904565
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: Ryan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1048714}
diff --git a/ash/services/device_sync/cryptauth_device_manager_impl.cc b/ash/services/device_sync/cryptauth_device_manager_impl.cc
index a7715ea..758fdc7 100644
--- a/ash/services/device_sync/cryptauth_device_manager_impl.cc
+++ b/ash/services/device_sync/cryptauth_device_manager_impl.cc
@@ -684,7 +684,7 @@
 void CryptAuthDeviceManagerImpl::OnGetMyDevicesSuccess(
     const cryptauth::GetMyDevicesResponse& response) {
   // Update the synced devices stored in the user's prefs.
-  base::Value devices_as_list(base::Value::Type::LIST);
+  base::Value::List devices_as_list;
 
   if (!response.devices().empty()) {
     PA_LOG(VERBOSE) << "Devices were successfully synced.";
@@ -709,8 +709,9 @@
       devices_as_list !=
       pref_service_->GetList(prefs::kCryptAuthDeviceSyncUnlockKeys);
   {
-    ListPrefUpdate update(pref_service_, prefs::kCryptAuthDeviceSyncUnlockKeys);
-    *update.Get() = std::move(devices_as_list);
+    ScopedListPrefUpdate update(pref_service_,
+                                prefs::kCryptAuthDeviceSyncUnlockKeys);
+    *update = std::move(devices_as_list);
   }
   UpdateUnlockKeysFromPrefs();
 
diff --git a/ash/services/device_sync/cryptauth_device_manager_impl_unittest.cc b/ash/services/device_sync/cryptauth_device_manager_impl_unittest.cc
index 8bee5ced..1f9a443 100644
--- a/ash/services/device_sync/cryptauth_device_manager_impl_unittest.cc
+++ b/ash/services/device_sync/cryptauth_device_manager_impl_unittest.cc
@@ -529,7 +529,7 @@
         prefs::kCryptAuthDeviceSyncReason,
         std::make_unique<base::Value>(cryptauth::INVOCATION_REASON_UNKNOWN));
 
-    base::Value device_dictionary(base::Value::Type::DICTIONARY);
+    base::Value::Dict device_dictionary;
 
     std::string public_key_b64, device_name_b64, bluetooth_address_b64;
     base::Base64UrlEncode(kStoredPublicKey,
@@ -542,19 +542,17 @@
                           base::Base64UrlEncodePolicy::INCLUDE_PADDING,
                           &bluetooth_address_b64);
 
-    device_dictionary.SetStringKey("public_key", public_key_b64);
-    device_dictionary.SetStringKey("device_name", device_name_b64);
-    device_dictionary.SetStringKey("bluetooth_address", bluetooth_address_b64);
-    device_dictionary.SetBoolKey("unlockable", kStoredUnlockable);
-    device_dictionary.SetKey("beacon_seeds",
-                             base::Value(base::Value::Type::LIST));
-    device_dictionary.SetKey("software_features",
-                             base::Value(base::Value::Type::DICTIONARY));
+    device_dictionary.Set("public_key", public_key_b64);
+    device_dictionary.Set("device_name", device_name_b64);
+    device_dictionary.Set("bluetooth_address", bluetooth_address_b64);
+    device_dictionary.Set("unlockable", kStoredUnlockable);
+    device_dictionary.Set("beacon_seeds", base::Value::List());
+    device_dictionary.Set("software_features", base::Value::Dict());
 
     {
-      ListPrefUpdate update(&pref_service_,
-                            prefs::kCryptAuthDeviceSyncUnlockKeys);
-      update.Get()->Append(std::move(device_dictionary));
+      ScopedListPrefUpdate update(&pref_service_,
+                                  prefs::kCryptAuthDeviceSyncUnlockKeys);
+      update->Append(std::move(device_dictionary));
     }
 
     device_manager_ = std::make_unique<TestCryptAuthDeviceManager>(
@@ -724,24 +722,24 @@
 TEST_F(
     DeviceSyncCryptAuthDeviceManagerImplTest,
     InitWithExistingPrefs_MigrateDeprecateBooleansFromPrefsToSoftwareFeature) {
-  ListPrefUpdate update_clear(&pref_service_,
-                              prefs::kCryptAuthDeviceSyncUnlockKeys);
-  update_clear.Get()->ClearList();
+  ScopedListPrefUpdate update_clear(&pref_service_,
+                                    prefs::kCryptAuthDeviceSyncUnlockKeys);
+  update_clear->clear();
 
   // Simulate a deprecated device being persisted to prefs.
-  base::Value device_dictionary(base::Value::Type::DICTIONARY);
+  base::Value::Dict device_dictionary;
   std::string public_key_b64;
   base::Base64UrlEncode(kStoredPublicKey,
                         base::Base64UrlEncodePolicy::INCLUDE_PADDING,
                         &public_key_b64);
-  device_dictionary.SetStringKey("public_key", public_key_b64);
-  device_dictionary.SetBoolKey("unlock_key", true);
-  device_dictionary.SetBoolKey("mobile_hotspot_supported", true);
-  device_dictionary.SetKey("software_features",
-                           base::Value(base::Value::Type::DICTIONARY));
+  device_dictionary.Set("public_key", public_key_b64);
+  device_dictionary.Set("unlock_key", true);
+  device_dictionary.Set("mobile_hotspot_supported", true);
+  device_dictionary.Set("software_features", base::Value::Dict());
 
-  ListPrefUpdate update(&pref_service_, prefs::kCryptAuthDeviceSyncUnlockKeys);
-  update.Get()->Append(std::move(device_dictionary));
+  ScopedListPrefUpdate update(&pref_service_,
+                              prefs::kCryptAuthDeviceSyncUnlockKeys);
+  update->Append(std::move(device_dictionary));
 
   device_manager_ = std::make_unique<TestCryptAuthDeviceManager>(
       &clock_, client_factory_.get(), &gcm_manager_, &pref_service_);