Eliminate DictionaryValue::GetInteger in net/
Bug: 1187034
Change-Id: I1ce3af08e998b640fe6d4c5bf4733f9155dc5382
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3222808
Reviewed-by: Yutaka Hirano <yhirano@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/main@{#933375}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
df4c4fe8f0
commit
0a22563071
net
cert
network_error_logging
reporting
@ -226,14 +226,11 @@ bool CRLSet::Parse(base::StringPiece data, scoped_refptr<CRLSet>* out_crl_set) {
|
||||
if (contents != "CRLSet")
|
||||
return false;
|
||||
|
||||
int version;
|
||||
if (!header_dict->GetInteger("Version", &version) ||
|
||||
version != kCurrentFileVersion) {
|
||||
if (header_dict->FindIntKey("Version") != kCurrentFileVersion)
|
||||
return false;
|
||||
}
|
||||
|
||||
int sequence;
|
||||
if (!header_dict->GetInteger("Sequence", &sequence))
|
||||
absl::optional<int> sequence = header_dict->FindIntKey("Sequence");
|
||||
if (!sequence)
|
||||
return false;
|
||||
|
||||
// NotAfter is optional for now.
|
||||
@ -242,7 +239,7 @@ bool CRLSet::Parse(base::StringPiece data, scoped_refptr<CRLSet>* out_crl_set) {
|
||||
return false;
|
||||
|
||||
scoped_refptr<CRLSet> crl_set(new CRLSet());
|
||||
crl_set->sequence_ = static_cast<uint32_t>(sequence);
|
||||
crl_set->sequence_ = static_cast<uint32_t>(*sequence);
|
||||
crl_set->not_after_ = static_cast<uint64_t>(not_after);
|
||||
crl_set->crls_.reserve(64); // Value observed experimentally.
|
||||
|
||||
|
@ -220,8 +220,8 @@ void ExpectDictDoubleValue(double expected_value,
|
||||
const base::DictionaryValue& value,
|
||||
const std::string& key) {
|
||||
absl::optional<double> double_value = value.FindDoubleKey(key);
|
||||
EXPECT_TRUE(double_value.has_value()) << key;
|
||||
EXPECT_DOUBLE_EQ(expected_value, double_value.value_or(0.0)) << key;
|
||||
ASSERT_TRUE(double_value) << key;
|
||||
EXPECT_DOUBLE_EQ(expected_value, *double_value) << key;
|
||||
}
|
||||
|
||||
TEST_P(NetworkErrorLoggingServiceTest, CreateService) {
|
||||
|
@ -92,15 +92,21 @@ bool ProcessEndpoint(ReportingDelegate* delegate,
|
||||
endpoint_info_out->url = std::move(endpoint_url);
|
||||
|
||||
int priority = ReportingEndpoint::EndpointInfo::kDefaultPriority;
|
||||
if (dict->HasKey(kPriorityKey) && !dict->GetInteger(kPriorityKey, &priority))
|
||||
return false;
|
||||
if (const base::Value* value = dict->FindKey(kPriorityKey)) {
|
||||
if (!value->is_int())
|
||||
return false;
|
||||
priority = value->GetInt();
|
||||
}
|
||||
if (priority < 0)
|
||||
return false;
|
||||
endpoint_info_out->priority = priority;
|
||||
|
||||
int weight = ReportingEndpoint::EndpointInfo::kDefaultWeight;
|
||||
if (dict->HasKey(kWeightKey) && !dict->GetInteger(kWeightKey, &weight))
|
||||
return false;
|
||||
if (const base::Value* value = dict->FindKey(kWeightKey)) {
|
||||
if (!value->is_int())
|
||||
return false;
|
||||
weight = value->GetInt();
|
||||
}
|
||||
if (weight < 0)
|
||||
return false;
|
||||
endpoint_info_out->weight = weight;
|
||||
@ -133,11 +139,7 @@ bool ProcessEndpointGroup(ReportingDelegate* delegate,
|
||||
group_name);
|
||||
parsed_endpoint_group_out->group_key = group_key;
|
||||
|
||||
int ttl_sec = -1;
|
||||
if (!dict->HasKey(kMaxAgeKey))
|
||||
return false;
|
||||
if (!dict->GetInteger(kMaxAgeKey, &ttl_sec))
|
||||
return false;
|
||||
int ttl_sec = dict->FindIntKey(kMaxAgeKey).value_or(-1);
|
||||
if (ttl_sec < 0)
|
||||
return false;
|
||||
// max_age: 0 signifies removal of the endpoint group.
|
||||
|
Reference in New Issue
Block a user