Commit d418d9be authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Convert away from method JSONReader::ReadDeprecated

Replace usage to instead use JSONReader::Read that returns a
base::Optional<base::Value>.

Bug: 925165
Change-Id: I31077cd95a605796ef5b08a7e6d1a963afdb1dd6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1503752
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Auto-Submit: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638067}
parent 868f5aac
...@@ -23,14 +23,6 @@ const char kInvalidDataTypeError[] = ...@@ -23,14 +23,6 @@ const char kInvalidDataTypeError[] =
const char kUnexpectedJSONFormatError[] = const char kUnexpectedJSONFormatError[] =
"Data from web resource server does not have expected format."; "Data from web resource server does not have expected format.";
// Runs |error_callback| with |error| on |task_runner|.
void PostErrorTask(base::TaskRunner* task_runner,
const WebResourceService::ErrorCallback& error_callback,
const char error[]) {
task_runner->PostTask(FROM_HERE,
base::BindOnce(error_callback, std::string(error)));
}
// Parses |data| as a JSON string and calls back on |task_runner|. // Parses |data| as a JSON string and calls back on |task_runner|.
// Must not be called on the UI thread, for performance reasons. // Must not be called on the UI thread, for performance reasons.
void ParseJSONOnBackgroundThread( void ParseJSONOnBackgroundThread(
...@@ -39,24 +31,29 @@ void ParseJSONOnBackgroundThread( ...@@ -39,24 +31,29 @@ void ParseJSONOnBackgroundThread(
const WebResourceService::SuccessCallback& success_callback, const WebResourceService::SuccessCallback& success_callback,
const WebResourceService::ErrorCallback& error_callback) { const WebResourceService::ErrorCallback& error_callback) {
if (data.empty()) { if (data.empty()) {
PostErrorTask(task_runner, error_callback, kInvalidDataTypeError); task_runner->PostTask(
FROM_HERE, base::BindOnce(error_callback, kInvalidDataTypeError));
return; return;
} }
std::unique_ptr<base::Value> value(base::JSONReader::ReadDeprecated(data)); base::Optional<base::Value> value(base::JSONReader::Read(data));
if (!value.get()) { if (!value) {
// Page information not properly read, or corrupted. // Page information not properly read, or corrupted.
PostErrorTask(task_runner, error_callback, kInvalidDataTypeError); task_runner->PostTask(
FROM_HERE, base::BindOnce(error_callback, kInvalidDataTypeError));
return; return;
} }
if (!value->is_dict()) { if (!value->is_dict()) {
PostErrorTask(task_runner, error_callback, kUnexpectedJSONFormatError); task_runner->PostTask(
FROM_HERE, base::BindOnce(error_callback, kUnexpectedJSONFormatError));
return; return;
} }
task_runner->PostTask(FROM_HERE, task_runner->PostTask(
base::BindOnce(success_callback, std::move(value))); FROM_HERE,
base::BindOnce(success_callback,
base::Value::ToUniquePtrValue(std::move(value).value())));
} }
// Starts the parsing of |data| as a JSON string asynchronously on a background // Starts the parsing of |data| as a JSON string asynchronously on a background
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment