Skip to content

Commit

Permalink
[Code Health][iOS] Update base::Value usages to v2 API
Browse files Browse the repository at this point in the history
Bug: 1187001
Change-Id: I511d2658a35643fa9c5a2a60486269ad8dc52a39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4323719
Commit-Queue: Duong Dac <ddac@chromium.org>
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115075}
  • Loading branch information
ddacw authored and Chromium LUCI CQ committed Mar 9, 2023
1 parent 85c6d8b commit 47196ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
19 changes: 10 additions & 9 deletions ios/web/annotations/annotations_java_script_feature.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@
return;
}

const std::string* command = response->FindStringKey("command");
const base::Value::Dict& dict = response->GetDict();

const std::string* command = dict.FindString("command");
if (!command) {
return;
}
Expand All @@ -124,29 +126,28 @@
}

if (*command == "annotations.extractedText") {
const std::string* text = response->FindStringKey("text");
absl::optional<double> seq_id = response->FindDoubleKey("seqId");
const std::string* text = dict.FindString("text");
absl::optional<double> seq_id = dict.FindDouble("seqId");
if (!text || !seq_id) {
return;
}
manager->OnTextExtracted(web_state, *text,
static_cast<int>(seq_id.value()));
} else if (*command == "annotations.decoratingComplete") {
absl::optional<double> optional_annotations =
response->FindDoubleKey("annotations");
absl::optional<double> optional_successes =
response->FindDoubleKey("successes");
dict.FindDouble("annotations");
absl::optional<double> optional_successes = dict.FindDouble("successes");
if (!optional_annotations || !optional_successes) {
return;
}
int annotations = static_cast<int>(optional_annotations.value());
int successes = static_cast<int>(optional_successes.value());
manager->OnDecorated(web_state, successes, annotations);
} else if (*command == "annotations.onClick") {
const std::string* data = response->FindStringKey("data");
const std::string* data = dict.FindString("data");
absl::optional<CGRect> rect =
shared_highlighting::ParseRect(response->GetDict().FindDict("rect"));
const std::string* text = response->FindStringKey("text");
shared_highlighting::ParseRect(dict.FindDict("rect"));
const std::string* text = dict.FindString("text");
if (!data || !rect || !text) {
return;
}
Expand Down
15 changes: 8 additions & 7 deletions ios/web/text_fragments/text_fragments_java_script_feature.mm
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
return;
}

const std::string* command = response->FindStringKey("command");
const base::Value::Dict& dict = response->GetDict();

const std::string* command = dict.FindString("command");
if (!command) {
return;
}
Expand All @@ -115,9 +117,9 @@
if (*command == "textFragments.processingComplete") {
// Extract success metrics.
absl::optional<double> optional_fragment_count =
response->FindDoublePath("result.fragmentsCount");
dict.FindDoubleByDottedPath("result.fragmentsCount");
absl::optional<double> optional_success_count =
response->FindDoublePath("result.successCount");
dict.FindDoubleByDottedPath("result.successCount");

// Since the response can't be trusted, don't log metrics if the results
// look invalid.
Expand All @@ -143,11 +145,10 @@
manager->OnClick();
} else if (*command == "textFragments.onClickWithSender") {
absl::optional<CGRect> rect =
shared_highlighting::ParseRect(response->GetDict().FindDict("rect"));
const std::string* text = response->FindStringKey("text");
shared_highlighting::ParseRect(dict.FindDict("rect"));
const std::string* text = dict.FindString("text");

const base::Value::List* fragment_values_list =
response->GetDict().FindList("fragments");
const base::Value::List* fragment_values_list = dict.FindList("fragments");
std::vector<shared_highlighting::TextFragment> fragments;
if (fragment_values_list) {
for (const base::Value& val : *fragment_values_list) {
Expand Down

0 comments on commit 47196ab

Please sign in to comment.