[CodeHealth] Remove deprecated uses of base::Value (#17293)
A number of base::Value functions have been marked as deprecated. This PR removes some of those cases in favour of the new interfaces, as these function will soon be removed upstream.
This commit is contained in:
@@ -139,8 +139,7 @@ class BraveVpnDnsObserverServiceUnitTest : public testing::Test {
|
||||
}
|
||||
|
||||
void SetManagedMode(const std::string& value) {
|
||||
local_state_.SetManagedPref(::prefs::kDnsOverHttpsMode,
|
||||
std::make_unique<base::Value>(value));
|
||||
local_state_.SetManagedPref(::prefs::kDnsOverHttpsMode, base::Value(value));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -1225,7 +1225,7 @@ TEST_F(BraveWalletServiceUnitTest, NetworkListChangedEvent) {
|
||||
ScopedDictPrefUpdate update(GetPrefs(), kBraveWalletCustomNetworks);
|
||||
base::Value::List* list = update->FindList(kEthereumPrefKey);
|
||||
list->EraseIf([&](const base::Value& v) {
|
||||
auto* chain_id_value = v.FindStringKey("chainId");
|
||||
auto* chain_id_value = v.GetDict().FindString("chainId");
|
||||
if (!chain_id_value)
|
||||
return false;
|
||||
return *chain_id_value == "0x5566";
|
||||
|
||||
@@ -1829,15 +1829,13 @@ TEST_F(KeyringServiceUnitTest, ImportedAccounts) {
|
||||
KeyringService::GetPrefForKeyring(*GetPrefs(), kImportedAccounts,
|
||||
mojom::kDefaultKeyringId);
|
||||
ASSERT_TRUE(imported_accounts_value);
|
||||
EXPECT_EQ(imported_accounts_value->GetList()[0]
|
||||
.FindKey(kAccountAddress)
|
||||
->GetString(),
|
||||
EXPECT_EQ(*imported_accounts_value->GetList()[0].GetDict().FindString(
|
||||
kAccountAddress),
|
||||
imported_accounts[0].address);
|
||||
// private key is encrypted
|
||||
const std::string encrypted_private_key =
|
||||
imported_accounts_value->GetList()[0]
|
||||
.FindKey(kEncryptedPrivateKey)
|
||||
->GetString();
|
||||
*imported_accounts_value->GetList()[0].GetDict().FindString(
|
||||
kEncryptedPrivateKey);
|
||||
EXPECT_FALSE(encrypted_private_key.empty());
|
||||
|
||||
std::vector<uint8_t> private_key0;
|
||||
@@ -1905,9 +1903,8 @@ TEST_F(KeyringServiceUnitTest, ImportedAccountFromJson) {
|
||||
mojom::kDefaultKeyringId);
|
||||
ASSERT_TRUE(imported_accounts_value);
|
||||
const std::string encrypted_private_key =
|
||||
imported_accounts_value->GetList()[0]
|
||||
.FindKey(kEncryptedPrivateKey)
|
||||
->GetString();
|
||||
*imported_accounts_value->GetList()[0].GetDict().FindString(
|
||||
kEncryptedPrivateKey);
|
||||
EXPECT_FALSE(encrypted_private_key.empty());
|
||||
|
||||
std::vector<uint8_t> private_key_bytes;
|
||||
@@ -3906,7 +3903,8 @@ class KeyringServiceAccountDiscoveryUnitTest : public KeyringServiceUnitTest {
|
||||
.AsStringPiece());
|
||||
absl::optional<base::Value> request_value =
|
||||
base::JSONReader::Read(request_string);
|
||||
if (*request_value->FindStringKey("method") == "eth_getTransactionCount") {
|
||||
if (*request_value->GetDict().FindString("method") ==
|
||||
"eth_getTransactionCount") {
|
||||
base::Value* params = request_value->FindListKey("params");
|
||||
EXPECT_TRUE(params);
|
||||
std::string* address = params->GetList()[0].GetIfString();
|
||||
|
||||
@@ -62,8 +62,7 @@ void NTPBackgroundPrefs::RegisterPref(
|
||||
dict.Set(kSelectedValueKey, "");
|
||||
registry->RegisterDictionaryPref(kPrefName, base::Value(std::move(dict)));
|
||||
|
||||
registry->RegisterListPref(kCustomImageListPrefName,
|
||||
base::Value(base::Value::Type::LIST));
|
||||
registry->RegisterListPref(kCustomImageListPrefName);
|
||||
}
|
||||
|
||||
void NTPBackgroundPrefs::MigrateOldPref() {
|
||||
|
||||
@@ -108,7 +108,6 @@ void SearchEngineProviderServiceFactory::RegisterProfilePrefs(
|
||||
#endif
|
||||
|
||||
registry->RegisterDictionaryPref(
|
||||
prefs::kSyncedDefaultPrivateSearchProviderData,
|
||||
base::Value(base::Value::Type::DICT),
|
||||
prefs::kSyncedDefaultPrivateSearchProviderData, base::Value::Dict(),
|
||||
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
|
||||
}
|
||||
|
||||
@@ -76,14 +76,14 @@ TEST_F(BraveBookmarkContextMenuControllerTest,
|
||||
|
||||
// Disabling the shorcut by policy doesn't cause the command to be added.
|
||||
prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
|
||||
std::make_unique<base::Value>(false));
|
||||
base::Value(false));
|
||||
EXPECT_FALSE(controller.menu_model()
|
||||
->GetIndexOfCommandId(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT)
|
||||
.has_value());
|
||||
|
||||
// And enabling the shortcut by policy doesn't cause the command to be added.
|
||||
prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
|
||||
std::make_unique<base::Value>(true));
|
||||
base::Value(true));
|
||||
EXPECT_FALSE(controller.menu_model()
|
||||
->GetIndexOfCommandId(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT)
|
||||
.has_value());
|
||||
@@ -91,7 +91,7 @@ TEST_F(BraveBookmarkContextMenuControllerTest,
|
||||
// And enabling the shortcut by user doesn't cause the command to be added.
|
||||
prefs->RemoveManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar);
|
||||
prefs->SetUserPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
|
||||
std::make_unique<base::Value>(true));
|
||||
base::Value(true));
|
||||
EXPECT_FALSE(controller.menu_model()
|
||||
->GetIndexOfCommandId(IDC_BOOKMARK_BAR_SHOW_APPS_SHORTCUT)
|
||||
.has_value());
|
||||
|
||||
@@ -47,9 +47,9 @@ TEST(TestIPFSDomHandler, AddComponentVersion) {
|
||||
handler.OnGetNodeInfo(true, info);
|
||||
const auto& data = *handler.web_ui()->call_data()[0];
|
||||
ASSERT_TRUE(data.arg1()->is_dict());
|
||||
EXPECT_EQ(*data.arg1()->FindStringKey("id"), info.id);
|
||||
EXPECT_EQ(*data.arg1()->FindStringKey("version"), info.version);
|
||||
EXPECT_EQ(*data.arg1()->FindStringKey("component_version"), component);
|
||||
EXPECT_EQ(*data.arg1()->GetDict().FindString("id"), info.id);
|
||||
EXPECT_EQ(*data.arg1()->GetDict().FindString("version"), info.version);
|
||||
EXPECT_EQ(*data.arg1()->GetDict().FindString("component_version"), component);
|
||||
}
|
||||
|
||||
TEST(TestIPFSDomHandler, ComponentNotRegistered) {
|
||||
@@ -60,7 +60,7 @@ TEST(TestIPFSDomHandler, ComponentNotRegistered) {
|
||||
handler.OnGetNodeInfo(true, info);
|
||||
const auto& data = *handler.web_ui()->call_data()[0];
|
||||
ASSERT_TRUE(data.arg1()->is_dict());
|
||||
EXPECT_EQ(*data.arg1()->FindStringKey("id"), info.id);
|
||||
EXPECT_EQ(*data.arg1()->FindStringKey("version"), info.version);
|
||||
ASSERT_FALSE(data.arg1()->FindStringKey("component_version"));
|
||||
EXPECT_EQ(*data.arg1()->GetDict().FindString("id"), info.id);
|
||||
EXPECT_EQ(*data.arg1()->GetDict().FindString("version"), info.version);
|
||||
ASSERT_FALSE(data.arg1()->GetDict().FindString("component_version"));
|
||||
}
|
||||
|
||||
@@ -462,12 +462,13 @@ void BraveNewTabMessageHandler::HandleBrandedWallpaperLogoClicked(
|
||||
}
|
||||
|
||||
if (auto* service = ViewCounterServiceFactory::GetForProfile(profile_)) {
|
||||
const auto& arg = args[0].GetDict();
|
||||
auto* creative_instance_id =
|
||||
args[0].FindStringKey(ntp_background_images::kCreativeInstanceIDKey);
|
||||
auto* destination_url =
|
||||
args[0].FindStringPath(ntp_background_images::kLogoDestinationURLPath);
|
||||
arg.FindString(ntp_background_images::kCreativeInstanceIDKey);
|
||||
auto* destination_url = arg.FindStringByDottedPath(
|
||||
ntp_background_images::kLogoDestinationURLPath);
|
||||
auto* wallpaper_id =
|
||||
args[0].FindStringPath(ntp_background_images::kWallpaperIDKey);
|
||||
arg.FindStringByDottedPath(ntp_background_images::kWallpaperIDKey);
|
||||
|
||||
DCHECK(creative_instance_id);
|
||||
DCHECK(destination_url);
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace brave {
|
||||
NSArray<MojoBaseValue*>* NSArrayFromBaseValue(const base::Value);
|
||||
|
||||
// Clone the contents of a `base::Value` whos type is
|
||||
// `base::Value::Type::DICTIONARY`. Any types found within the `base::Value`
|
||||
// `base::Value::Type::DICT`. Any types found within the `base::Value`
|
||||
// that are unsupported or `NONE` will become `NSNull`
|
||||
NSDictionary<NSString*, MojoBaseValue*>* NSDictionaryFromBaseValue(
|
||||
const base::Value);
|
||||
@@ -29,7 +29,7 @@ NSDictionary<NSString*, MojoBaseValue*>* NSDictionaryFromBaseValue(
|
||||
base::Value BaseValueFromNSArray(NSArray<MojoBaseValue*>*);
|
||||
|
||||
// Clone the contents of an NSDictionary into a `base::Value` with the type
|
||||
// `base::Value::Type::DICTIONARY`
|
||||
// `base::Value::Type::DICT`
|
||||
base::Value BaseValueFromNSDictionary(NSDictionary<NSString*, MojoBaseValue*>*);
|
||||
|
||||
NSDictionary<NSString*, MojoBaseValue*>* NSDictionaryFromBaseValueDict(
|
||||
|
||||
@@ -213,7 +213,7 @@
|
||||
return a;
|
||||
}();
|
||||
break;
|
||||
case base::Value::Type::DICTIONARY:
|
||||
case base::Value::Type::DICT:
|
||||
self.dictionaryValue = brave::NSDictionaryFromBaseValue(value.Clone());
|
||||
break;
|
||||
case base::Value::Type::LIST:
|
||||
@@ -334,12 +334,13 @@ base::Value BaseValueFromNSArray(NSArray<MojoBaseValue*>* array) {
|
||||
|
||||
base::Value BaseValueFromNSDictionary(
|
||||
NSDictionary<NSString*, MojoBaseValue*>* dictionary) {
|
||||
base::Value dict(base::Value::Type::DICTIONARY);
|
||||
base::Value result(base::Value::Type::DICT);
|
||||
base::Value::Dict& dict = result.GetDict();
|
||||
for (NSString* key in dictionary) {
|
||||
MojoBaseValue* value = dictionary[key];
|
||||
dict.SetKey(base::SysNSStringToUTF8(key), value.cppObjPtr);
|
||||
dict.Set(base::SysNSStringToUTF8(key), value.cppObjPtr);
|
||||
}
|
||||
return dict;
|
||||
return result;
|
||||
}
|
||||
|
||||
NSDictionary<NSString*, MojoBaseValue*>* NSDictionaryFromBaseValueDict(
|
||||
|
||||
@@ -522,8 +522,7 @@ class PrivacySandboxSettingsTestCookiesClearOnExitTurnedOff
|
||||
public:
|
||||
void InitializePrefsBeforeStart() override {
|
||||
prefs()->SetUserPref(prefs::kPrivacySandboxTopicsDataAccessibleSince,
|
||||
std::make_unique<base::Value>(::base::TimeToValue(
|
||||
base::Time::FromTimeT(12345))));
|
||||
base::TimeToValue(base::Time::FromTimeT(12345)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -542,8 +541,7 @@ class PrivacySandboxSettingsTestCookiesClearOnExitTurnedOn
|
||||
ContentSetting::CONTENT_SETTING_SESSION_ONLY);
|
||||
|
||||
prefs()->SetUserPref(prefs::kPrivacySandboxTopicsDataAccessibleSince,
|
||||
std::make_unique<base::Value>(::base::TimeToValue(
|
||||
base::Time::FromTimeT(12345))));
|
||||
base::TimeToValue(base::Time::FromTimeT(12345)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -183,18 +183,16 @@ TEST_F(BraveShieldsUtilTest, SetBraveShieldsEnabled_ForOrigin) {
|
||||
EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
|
||||
|
||||
// Set policy to disable shields for specific domain.
|
||||
auto disabled_list = base::Value(base::Value::Type::LIST);
|
||||
base::Value::List disabled_list;
|
||||
disabled_list.Append("[*.]host2.com");
|
||||
disabled_list.Append("*.*");
|
||||
profile()->GetTestingPrefService()->SetManagedPref(
|
||||
kManagedBraveShieldsDisabledForUrls,
|
||||
base::Value::ToUniquePtrValue(std::move(disabled_list)));
|
||||
kManagedBraveShieldsDisabledForUrls, std::move(disabled_list));
|
||||
|
||||
auto enabled_list = base::Value(base::Value::Type::LIST);
|
||||
base::Value::List enabled_list;
|
||||
enabled_list.Append("[*.]host1.com");
|
||||
profile()->GetTestingPrefService()->SetManagedPref(
|
||||
kManagedBraveShieldsEnabledForUrls,
|
||||
base::Value::ToUniquePtrValue(std::move(enabled_list)));
|
||||
kManagedBraveShieldsEnabledForUrls, std::move(enabled_list));
|
||||
|
||||
// setting should apply block to origin.
|
||||
setting =
|
||||
@@ -222,11 +220,10 @@ TEST_F(BraveShieldsUtilTest, IsBraveShieldsManaged) {
|
||||
EXPECT_FALSE(brave_shields::IsBraveShieldsManaged(
|
||||
profile()->GetTestingPrefService(), map, host2));
|
||||
|
||||
auto disabled_list = base::Value(base::Value::Type::LIST);
|
||||
base::Value::List disabled_list;
|
||||
disabled_list.Append("[*.]host2.com");
|
||||
profile()->GetTestingPrefService()->SetManagedPref(
|
||||
kManagedBraveShieldsDisabledForUrls,
|
||||
base::Value::ToUniquePtrValue(std::move(disabled_list)));
|
||||
kManagedBraveShieldsDisabledForUrls, std::move(disabled_list));
|
||||
// only disabled pref set
|
||||
EXPECT_TRUE(brave_shields::IsBraveShieldsManaged(
|
||||
profile()->GetTestingPrefService(), map, host2));
|
||||
@@ -234,11 +231,10 @@ TEST_F(BraveShieldsUtilTest, IsBraveShieldsManaged) {
|
||||
EXPECT_FALSE(brave_shields::IsBraveShieldsManaged(
|
||||
profile()->GetTestingPrefService(), map, GURL("http://host1.com")));
|
||||
|
||||
auto enabled_list = base::Value(base::Value::Type::LIST);
|
||||
base::Value::List enabled_list;
|
||||
enabled_list.Append("[*.]host1.com");
|
||||
profile()->GetTestingPrefService()->SetManagedPref(
|
||||
kManagedBraveShieldsEnabledForUrls,
|
||||
base::Value::ToUniquePtrValue(std::move(enabled_list)));
|
||||
kManagedBraveShieldsEnabledForUrls, std::move(enabled_list));
|
||||
|
||||
// both disabled/enabled prefs set
|
||||
EXPECT_TRUE(brave_shields::IsBraveShieldsManaged(
|
||||
|
||||
@@ -451,9 +451,9 @@ class BraveVPNServiceTest : public testing::Test {
|
||||
bool active_subscription = true) {
|
||||
std::string domain = skus::GetDomain("vpn", env);
|
||||
auto testing_payload = GenerateTestingCreds(domain, active_subscription);
|
||||
base::Value state(base::Value::Type::DICT);
|
||||
state.SetStringKey("skus:" + env, testing_payload);
|
||||
local_pref_service_.Set(skus::prefs::kSkusState, std::move(state));
|
||||
base::Value::Dict state;
|
||||
state.Set("skus:" + env, testing_payload);
|
||||
local_pref_service_.SetDict(skus::prefs::kSkusState, std::move(state));
|
||||
SetInterceptorResponse(GetRegionsData());
|
||||
return domain;
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ TEST(FilTransactionUnitTest, GetMessageToSignSecp) {
|
||||
ASSERT_TRUE(signature.has_value());
|
||||
auto signature_value = base::JSONReader::Read(*signature);
|
||||
EXPECT_TRUE(signature_value);
|
||||
auto* message = signature_value->FindKey("Message");
|
||||
auto* message = signature_value->GetDict().Find("Message");
|
||||
auto* signature_data = signature_value->FindStringPath("Signature.Data");
|
||||
EXPECT_TRUE(message);
|
||||
EXPECT_TRUE(signature_data);
|
||||
@@ -246,7 +246,7 @@ TEST(FilTransactionUnitTest, GetMessageToSignBLS) {
|
||||
ASSERT_TRUE(signature.has_value());
|
||||
auto signature_value = base::JSONReader::Read(*signature);
|
||||
EXPECT_TRUE(signature_value);
|
||||
auto* message = signature_value->FindKey("Message");
|
||||
auto* message = signature_value->GetDict().Find("Message");
|
||||
auto* signature_data = signature_value->FindStringPath("Signature.Data");
|
||||
EXPECT_TRUE(message);
|
||||
EXPECT_TRUE(signature_data);
|
||||
|
||||
@@ -211,36 +211,38 @@ std::unique_ptr<HDKey> HDKey::GenerateFromV3UTC(const std::string& password,
|
||||
return nullptr;
|
||||
}
|
||||
auto parsed_json = base::JSONReader::ReadAndReturnValueWithError(json);
|
||||
if (!parsed_json.has_value()) {
|
||||
if (!parsed_json.has_value() || !parsed_json->is_dict()) {
|
||||
VLOG(0) << __func__ << ": UTC v3 json parsed failed because "
|
||||
<< parsed_json.error().message;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto& dict = parsed_json->GetDict();
|
||||
// check version
|
||||
auto version = parsed_json->FindIntKey("version");
|
||||
auto version = dict.FindInt("version");
|
||||
if (!version || *version != 3) {
|
||||
VLOG(0) << __func__ << ": missing version or version is not 3";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto* crypto = parsed_json->FindKey("crypto");
|
||||
const auto* crypto = dict.FindDict("crypto");
|
||||
if (!crypto) {
|
||||
VLOG(0) << __func__ << ": missing crypto";
|
||||
return nullptr;
|
||||
}
|
||||
const auto* kdf = crypto->FindStringKey("kdf");
|
||||
const auto* kdf = crypto->FindString("kdf");
|
||||
if (!kdf) {
|
||||
VLOG(0) << __func__ << ": missing kdf";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<SymmetricKey> derived_key = nullptr;
|
||||
const auto* kdfparams = crypto->FindKey("kdfparams");
|
||||
const auto* kdfparams = crypto->FindDict("kdfparams");
|
||||
if (!kdfparams) {
|
||||
VLOG(0) << __func__ << ": missing kdfparams";
|
||||
return nullptr;
|
||||
}
|
||||
auto dklen = kdfparams->FindIntKey("dklen");
|
||||
auto dklen = kdfparams->FindInt("dklen");
|
||||
if (!dklen) {
|
||||
VLOG(0) << __func__ << ": missing dklen";
|
||||
return nullptr;
|
||||
@@ -249,7 +251,7 @@ std::unique_ptr<HDKey> HDKey::GenerateFromV3UTC(const std::string& password,
|
||||
VLOG(0) << __func__ << ": dklen must be >=32";
|
||||
return nullptr;
|
||||
}
|
||||
const auto* salt = kdfparams->FindStringKey("salt");
|
||||
const auto* salt = kdfparams->FindString("salt");
|
||||
if (!salt) {
|
||||
VLOG(0) << __func__ << ": missing salt";
|
||||
return nullptr;
|
||||
@@ -260,12 +262,12 @@ std::unique_ptr<HDKey> HDKey::GenerateFromV3UTC(const std::string& password,
|
||||
return nullptr;
|
||||
}
|
||||
if (*kdf == "pbkdf2") {
|
||||
auto c = kdfparams->FindIntKey("c");
|
||||
auto c = kdfparams->FindInt("c");
|
||||
if (!c) {
|
||||
VLOG(0) << __func__ << ": missing c";
|
||||
return nullptr;
|
||||
}
|
||||
const auto* prf = kdfparams->FindStringKey("prf");
|
||||
const auto* prf = kdfparams->FindString("prf");
|
||||
if (!prf) {
|
||||
VLOG(0) << __func__ << ": missing prf";
|
||||
return nullptr;
|
||||
@@ -283,17 +285,17 @@ std::unique_ptr<HDKey> HDKey::GenerateFromV3UTC(const std::string& password,
|
||||
return nullptr;
|
||||
}
|
||||
} else if (*kdf == "scrypt") {
|
||||
auto n = kdfparams->FindIntKey("n");
|
||||
auto n = kdfparams->FindInt("n");
|
||||
if (!n) {
|
||||
VLOG(0) << __func__ << ": missing n";
|
||||
return nullptr;
|
||||
}
|
||||
auto r = kdfparams->FindIntKey("r");
|
||||
auto r = kdfparams->FindInt("r");
|
||||
if (!r) {
|
||||
VLOG(0) << __func__ << ": missing r";
|
||||
return nullptr;
|
||||
}
|
||||
auto p = kdfparams->FindIntKey("p");
|
||||
auto p = kdfparams->FindInt("p");
|
||||
if (!p) {
|
||||
VLOG(0) << __func__ << ": missing p";
|
||||
return nullptr;
|
||||
@@ -312,12 +314,12 @@ std::unique_ptr<HDKey> HDKey::GenerateFromV3UTC(const std::string& password,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const auto* mac = crypto->FindStringKey("mac");
|
||||
const auto* mac = crypto->FindString("mac");
|
||||
if (!mac) {
|
||||
VLOG(0) << __func__ << ": missing mac";
|
||||
return nullptr;
|
||||
}
|
||||
const auto* ciphertext = crypto->FindStringKey("ciphertext");
|
||||
const auto* ciphertext = crypto->FindString("ciphertext");
|
||||
if (!ciphertext) {
|
||||
VLOG(0) << __func__ << ": missing ciphertext";
|
||||
return nullptr;
|
||||
@@ -332,7 +334,7 @@ std::unique_ptr<HDKey> HDKey::GenerateFromV3UTC(const std::string& password,
|
||||
*dklen))
|
||||
return nullptr;
|
||||
|
||||
const auto* cipher = crypto->FindStringKey("cipher");
|
||||
const auto* cipher = crypto->FindString("cipher");
|
||||
if (!cipher) {
|
||||
VLOG(0) << __func__ << ": missing cipher";
|
||||
return nullptr;
|
||||
@@ -344,7 +346,7 @@ std::unique_ptr<HDKey> HDKey::GenerateFromV3UTC(const std::string& password,
|
||||
}
|
||||
|
||||
std::vector<uint8_t> iv_bytes;
|
||||
const auto* iv = crypto->FindStringPath("cipherparams.iv");
|
||||
const auto* iv = crypto->FindStringByDottedPath("cipherparams.iv");
|
||||
if (!iv) {
|
||||
VLOG(0) << __func__ << ": missing cipherparams.iv";
|
||||
return nullptr;
|
||||
|
||||
@@ -296,12 +296,12 @@ class SkusServiceTestUnitTest : public testing::Test {
|
||||
};
|
||||
|
||||
TEST_F(SkusServiceTestUnitTest, CredentialSummarySuccess) {
|
||||
base::Value state(base::Value::Type::DICT);
|
||||
base::Value::Dict state;
|
||||
auto env = skus::GetDefaultEnvironment();
|
||||
auto domain = skus::GetDomain("vpn", env);
|
||||
auto testing_payload = GenerateTestingCreds(domain);
|
||||
state.SetStringKey("skus:" + env, testing_payload);
|
||||
prefs()->Set(skus::prefs::kSkusState, std::move(state));
|
||||
state.Set("skus:" + env, testing_payload);
|
||||
prefs()->SetDict(skus::prefs::kSkusState, std::move(state));
|
||||
auto credentials = GetCredentialsSummary(domain);
|
||||
EXPECT_FALSE(credentials.empty());
|
||||
auto credentials_json = base::JSONReader::Read(credentials);
|
||||
@@ -312,7 +312,7 @@ TEST_F(SkusServiceTestUnitTest, CredentialSummarySuccess) {
|
||||
}
|
||||
|
||||
TEST_F(SkusServiceTestUnitTest, CredentialSummaryFailed) {
|
||||
base::Value state(base::Value::Type::DICT);
|
||||
base::Value::Dict state;
|
||||
auto env = skus::GetDefaultEnvironment();
|
||||
auto domain = skus::GetDomain("vpn", env);
|
||||
auto testing_payload = GenerateTestingCreds(domain);
|
||||
@@ -325,18 +325,18 @@ TEST_F(SkusServiceTestUnitTest, CredentialSummaryFailed) {
|
||||
base::JSONWriter::WriteWithOptions(
|
||||
payload_value.value(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
|
||||
// Save prefs with expired prefs only
|
||||
state.SetStringKey("skus:" + env, json);
|
||||
state.Set("skus:" + env, json);
|
||||
|
||||
prefs()->Set(skus::prefs::kSkusState, std::move(state));
|
||||
prefs()->SetDict(skus::prefs::kSkusState, std::move(state));
|
||||
auto credentials = GetCredentialsSummary(domain);
|
||||
EXPECT_EQ(credentials, "{}");
|
||||
}
|
||||
|
||||
TEST_F(SkusServiceTestUnitTest, CredentialSummaryWrongEnv) {
|
||||
base::Value state(base::Value::Type::DICT);
|
||||
base::Value::Dict state;
|
||||
auto testing_payload = GenerateTestingCreds("vpn.brave.software");
|
||||
state.SetStringKey("skus:staging", testing_payload);
|
||||
prefs()->Set(skus::prefs::kSkusState, std::move(state));
|
||||
state.Set("skus:staging", testing_payload);
|
||||
prefs()->SetDict(skus::prefs::kSkusState, std::move(state));
|
||||
auto credentials = GetCredentialsSummary("vpn.brave.software");
|
||||
EXPECT_EQ(credentials, "{}");
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ OBJC_EXPORT BraveSyncAPIWordsValidationStatus const
|
||||
auto device_list = _worker->GetDeviceList();
|
||||
auto* local_device_info = _worker->GetLocalDeviceInfo();
|
||||
|
||||
base::Value device_list_value(base::Value::Type::LIST);
|
||||
base::Value::List device_list_value;
|
||||
|
||||
for (const auto& device : device_list) {
|
||||
auto device_value = device->ToValue();
|
||||
|
||||
@@ -26,15 +26,16 @@ namespace {
|
||||
// TODO(https://github.com/brave/brave-browser/issues/24940): Reduce cognitive
|
||||
// complexity.
|
||||
absl::optional<TransformationVector> ParsePipelineTransformations(
|
||||
base::Value* transformations_value) {
|
||||
if (!transformations_value || !transformations_value->is_list()) {
|
||||
base::Value::List* transformations_value) {
|
||||
if (!transformations_value) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
absl::optional<TransformationVector> transformations = TransformationVector();
|
||||
for (const base::Value& transformation : transformations_value->GetList()) {
|
||||
for (const base::Value& item : *transformations_value) {
|
||||
const base::Value::Dict& transformation = item.GetDict();
|
||||
const std::string* const transformation_type =
|
||||
transformation.FindStringKey("transformation_type");
|
||||
transformation.FindString("transformation_type");
|
||||
|
||||
if (!transformation_type) {
|
||||
return absl::nullopt;
|
||||
@@ -52,28 +53,28 @@ absl::optional<TransformationVector> ParsePipelineTransformations(
|
||||
}
|
||||
|
||||
if (parsed_transformation_type == "HASHED_NGRAMS") {
|
||||
const base::Value* const transformation_params =
|
||||
transformation.FindKey("params");
|
||||
const base::Value::Dict* const transformation_params =
|
||||
transformation.FindDict("params");
|
||||
|
||||
if (!transformation_params) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
const absl::optional<int> nb =
|
||||
transformation_params->FindIntKey("num_buckets");
|
||||
transformation_params->FindInt("num_buckets");
|
||||
if (!nb) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
const int num_buckets = *nb;
|
||||
|
||||
const base::Value* const ngram_sizes =
|
||||
transformation_params->FindListKey("ngrams_range");
|
||||
const base::Value::List* const ngram_sizes =
|
||||
transformation_params->FindList("ngrams_range");
|
||||
if (!ngram_sizes) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
std::vector<int> ngram_range;
|
||||
for (const base::Value& n : ngram_sizes->GetList()) {
|
||||
for (const base::Value& n : *ngram_sizes) {
|
||||
if (n.is_int()) {
|
||||
ngram_range.push_back(n.GetInt());
|
||||
} else {
|
||||
@@ -91,13 +92,13 @@ absl::optional<TransformationVector> ParsePipelineTransformations(
|
||||
// TODO(https://github.com/brave/brave-browser/issues/24941): Reduce cognitive
|
||||
// complexity.
|
||||
absl::optional<model::Linear> ParsePipelineClassifier(
|
||||
base::Value* classifier_value) {
|
||||
base::Value::Dict* classifier_value) {
|
||||
if (!classifier_value) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
const std::string* const classifier_type =
|
||||
classifier_value->FindStringKey("classifier_type");
|
||||
classifier_value->FindString("classifier_type");
|
||||
|
||||
if (!classifier_type) {
|
||||
return absl::nullopt;
|
||||
@@ -109,14 +110,14 @@ absl::optional<model::Linear> ParsePipelineClassifier(
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
base::Value* specified_classes = classifier_value->FindListKey("classes");
|
||||
base::Value::List* specified_classes = classifier_value->FindList("classes");
|
||||
if (!specified_classes) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
std::vector<std::string> classes;
|
||||
classes.reserve(specified_classes->GetList().size());
|
||||
for (const base::Value& class_name : specified_classes->GetList()) {
|
||||
classes.reserve(specified_classes->size());
|
||||
for (const base::Value& class_name : *specified_classes) {
|
||||
if (!class_name.is_string()) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
@@ -129,24 +130,22 @@ absl::optional<model::Linear> ParsePipelineClassifier(
|
||||
classes.push_back(class_string);
|
||||
}
|
||||
|
||||
base::Value* class_weights = classifier_value->FindDictKey("class_weights");
|
||||
base::Value::Dict* class_weights =
|
||||
classifier_value->FindDict("class_weights");
|
||||
if (!class_weights) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
std::map<std::string, VectorData> weights;
|
||||
for (const std::string& class_string : classes) {
|
||||
base::Value* this_class = class_weights->FindListKey(class_string);
|
||||
if (!this_class) {
|
||||
base::Value::List* list = class_weights->FindList(class_string);
|
||||
if (!list) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
// Consume the list to save memory.
|
||||
const auto list = std::move(this_class->GetList());
|
||||
|
||||
std::vector<float> class_coef_weights;
|
||||
class_coef_weights.reserve(list.size());
|
||||
for (const base::Value& weight : list) {
|
||||
class_coef_weights.reserve(list->size());
|
||||
for (const base::Value& weight : *list) {
|
||||
if (weight.is_double() || weight.is_int()) {
|
||||
class_coef_weights.push_back(weight.GetDouble());
|
||||
} else {
|
||||
@@ -157,18 +156,17 @@ absl::optional<model::Linear> ParsePipelineClassifier(
|
||||
}
|
||||
|
||||
std::map<std::string, double> specified_biases;
|
||||
base::Value* biases = classifier_value->FindListKey("biases");
|
||||
base::Value::List* biases = classifier_value->FindList("biases");
|
||||
if (!biases) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
const auto& biases_list = biases->GetList();
|
||||
if (biases_list.size() != classes.size()) {
|
||||
if (biases->size() != classes.size()) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < biases_list.size(); i++) {
|
||||
const base::Value& this_bias = biases_list[i];
|
||||
for (size_t i = 0; i < biases->size(); i++) {
|
||||
const base::Value& this_bias = (*biases)[i];
|
||||
if (this_bias.is_double() || this_bias.is_int()) {
|
||||
specified_biases[classes[i]] = this_bias.GetDouble();
|
||||
} else {
|
||||
@@ -186,29 +184,31 @@ absl::optional<PipelineInfo> ParsePipelineValue(base::Value value) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
const absl::optional<int> version = value.FindIntKey("version");
|
||||
base::Value::Dict& dict = value.GetDict();
|
||||
|
||||
const absl::optional<int> version = dict.FindInt("version");
|
||||
if (!version) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
const std::string* const timestamp = value.FindStringKey("timestamp");
|
||||
const std::string* const timestamp = dict.FindString("timestamp");
|
||||
if (!timestamp) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
const std::string* const locale = value.FindStringKey("locale");
|
||||
const std::string* const locale = dict.FindString("locale");
|
||||
if (!locale) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
absl::optional<TransformationVector> transformations =
|
||||
ParsePipelineTransformations(value.FindListKey("transformations"));
|
||||
ParsePipelineTransformations(dict.FindList("transformations"));
|
||||
if (!transformations) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
absl::optional<model::Linear> linear_model =
|
||||
ParsePipelineClassifier(value.FindKey("classifier"));
|
||||
ParsePipelineClassifier(dict.FindDict("classifier"));
|
||||
if (!linear_model) {
|
||||
return absl::nullopt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user