0

Use base::JSONReader::ReadDeprecated() in various [h-z]* directories.

This is part of the process to help migrate base::JSONReader::Read() to
return base::Optional<base::Value>.

Do the same for ReadAndReturnError() and ReadToValue().

BUG=925165
TBR=eroman@chromium.org,pfeldman@chromium.org,sandersd@chromium.org,sergeyu@chromium.org,thakis@chromium.org

Change-Id: I0550baa36f24e6b27a4479543e55c8734c3c6956
Reviewed-on: https://chromium-review.googlesource.com/c/1476099
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#632889}
This commit is contained in:
Lei Zhang
2019-02-16 03:02:03 +00:00
committed by Commit Bot
parent 4b8e54432d
commit a8b4c5fbfa
35 changed files with 76 additions and 59 deletions

@ -131,7 +131,8 @@ int HeadlessDevToolsClientImpl::GetNextRawDevToolsMessageId() {
void HeadlessDevToolsClientImpl::SendRawDevToolsMessage(
const std::string& json_message) {
std::unique_ptr<base::Value> message = base::JSONReader::Read(json_message);
std::unique_ptr<base::Value> message =
base::JSONReader::ReadDeprecated(json_message);
if (!message->is_dict()) {
LOG(ERROR) << "Malformed raw message";
return;
@ -153,7 +154,7 @@ void HeadlessDevToolsClientImpl::ReceiveProtocolMessage(
const std::string& json_message) {
// LOG(ERROR) << "[RECV] " << json_message;
std::unique_ptr<base::Value> message =
base::JSONReader::Read(json_message, base::JSON_PARSE_RFC);
base::JSONReader::ReadDeprecated(json_message, base::JSON_PARSE_RFC);
if (!message || !message->is_dict()) {
NOTREACHED() << "Badly formed reply " << json_message;
return;

@ -26,7 +26,7 @@ TEST(TypesTest, IntegerProperty) {
TEST(TypesTest, IntegerPropertyParseError) {
const char json[] = "{\"entryId\": \"foo\"}";
std::unique_ptr<base::Value> object = base::JSONReader::Read(json);
std::unique_ptr<base::Value> object = base::JSONReader::ReadDeprecated(json);
ASSERT_TRUE(object);
#if DCHECK_IS_ON()
@ -52,7 +52,7 @@ TEST(TypesTest, BooleanProperty) {
TEST(TypesTest, BooleanPropertyParseError) {
const char json[] = "{\"suppressed\": \"foo\"}";
std::unique_ptr<base::Value> object = base::JSONReader::Read(json);
std::unique_ptr<base::Value> object = base::JSONReader::ReadDeprecated(json);
ASSERT_TRUE(object);
#if DCHECK_IS_ON()
@ -76,7 +76,7 @@ TEST(TypesTest, DoubleProperty) {
TEST(TypesTest, DoublePropertyParseError) {
const char json[] = "{\"latitude\": \"foo\"}";
std::unique_ptr<base::Value> object = base::JSONReader::Read(json);
std::unique_ptr<base::Value> object = base::JSONReader::ReadDeprecated(json);
ASSERT_TRUE(object);
#if DCHECK_IS_ON()
@ -99,7 +99,7 @@ TEST(TypesTest, StringProperty) {
TEST(TypesTest, StringPropertyParseError) {
const char json[] = "{\"url\": false}";
std::unique_ptr<base::Value> object = base::JSONReader::Read(json);
std::unique_ptr<base::Value> object = base::JSONReader::ReadDeprecated(json);
ASSERT_TRUE(object);
#if DCHECK_IS_ON()
@ -124,7 +124,7 @@ TEST(TypesTest, EnumProperty) {
TEST(TypesTest, EnumPropertyParseError) {
const char json[] = "{\"type\": false}";
std::unique_ptr<base::Value> object = base::JSONReader::Read(json);
std::unique_ptr<base::Value> object = base::JSONReader::ReadDeprecated(json);
ASSERT_TRUE(object);
#if DCHECK_IS_ON()
@ -162,7 +162,7 @@ TEST(TypesTest, ArrayProperty) {
TEST(TypesTest, ArrayPropertyParseError) {
const char json[] = "{\"nodeIds\": true}";
std::unique_ptr<base::Value> object = base::JSONReader::Read(json);
std::unique_ptr<base::Value> object = base::JSONReader::ReadDeprecated(json);
ASSERT_TRUE(object);
#if DCHECK_IS_ON()
@ -191,7 +191,7 @@ TEST(TypesTest, ObjectProperty) {
TEST(TypesTest, ObjectPropertyParseError) {
const char json[] = "{\"result\": 42}";
std::unique_ptr<base::Value> object = base::JSONReader::Read(json);
std::unique_ptr<base::Value> object = base::JSONReader::ReadDeprecated(json);
ASSERT_TRUE(object);
#if DCHECK_IS_ON()

@ -145,7 +145,7 @@ class HeadlessJsBindingsTest
void OnMessageFromJS(const std::string& json_message) {
std::unique_ptr<base::Value> message =
base::JSONReader::Read(json_message, base::JSON_PARSE_RFC);
base::JSONReader::ReadDeprecated(json_message, base::JSON_PARSE_RFC);
const base::Value* method_value = message->FindKey("method");
if (!method_value) {
FinishAsynchronousTest();

@ -104,7 +104,8 @@ class HeadlessProtocolBrowserTest
// runtime::Observer implementation.
void OnBindingCalled(const runtime::BindingCalledParams& params) override {
std::string json_message = params.GetPayload();
std::unique_ptr<base::Value> message = base::JSONReader::Read(json_message);
std::unique_ptr<base::Value> message =
base::JSONReader::ReadDeprecated(json_message);
const base::DictionaryValue* message_dict;
const base::DictionaryValue* params_dict;
std::string method;

@ -77,8 +77,8 @@ std::string SerializeP2PCandidate(const cricket::Candidate& candidate) {
bool DeserializeP2PCandidate(const std::string& candidate_str,
cricket::Candidate* candidate) {
std::unique_ptr<base::Value> value(
base::JSONReader::Read(candidate_str, base::JSON_ALLOW_TRAILING_COMMAS));
std::unique_ptr<base::Value> value(base::JSONReader::ReadDeprecated(
candidate_str, base::JSON_ALLOW_TRAILING_COMMAS));
if (!value.get() || !value->is_dict()) {
return false;
}

@ -199,7 +199,7 @@ class VideoDecoder::FakeImpl : public VideoDecoder::ImplBase {
// Make sure this is a JSON string.
if (!len || data[0] != '{')
return NULL;
std::unique_ptr<base::Value> values(base::JSONReader::Read(
std::unique_ptr<base::Value> values(base::JSONReader::ReadDeprecated(
base::StringPiece(reinterpret_cast<char*>(data), len)));
if (!values)
return NULL;

@ -59,7 +59,8 @@ MATCHER(NotEmpty, "") {
}
MATCHER(IsJSONDictionary, "") {
std::string result(arg.begin(), arg.end());
std::unique_ptr<base::Value> root(base::JSONReader().ReadToValue(result));
std::unique_ptr<base::Value> root(
base::JSONReader().ReadToValueDeprecated(result));
return (root.get() && root->type() == base::Value::Type::DICTIONARY);
}
MATCHER(IsNullTime, "") {

@ -172,7 +172,8 @@ bool ExtractKeysFromJWKSet(const std::string& jwk_set,
return false;
}
std::unique_ptr<base::Value> root(base::JSONReader().ReadToValue(jwk_set));
std::unique_ptr<base::Value> root(
base::JSONReader().ReadToValueDeprecated(jwk_set));
if (!root.get() || root->type() != base::Value::Type::DICTIONARY) {
DVLOG(1) << "Not valid JSON: " << jwk_set << ", root: " << root.get();
return false;
@ -241,7 +242,8 @@ bool ExtractKeyIdsFromKeyIdsInitData(const std::string& input,
return false;
}
std::unique_ptr<base::Value> root(base::JSONReader().ReadToValue(input));
std::unique_ptr<base::Value> root(
base::JSONReader().ReadToValueDeprecated(input));
if (!root.get() || root->type() != base::Value::Type::DICTIONARY) {
error_message->assign("Not valid JSON: ");
error_message->append(ShortenTo64Characters(input));
@ -375,7 +377,7 @@ bool ExtractFirstKeyIdFromLicenseRequest(const std::vector<uint8_t>& license,
}
std::unique_ptr<base::Value> root(
base::JSONReader().ReadToValue(license_as_str));
base::JSONReader().ReadToValueDeprecated(license_as_str));
if (!root.get() || root->type() != base::Value::Type::DICTIONARY) {
DVLOG(1) << "Not valid JSON: " << license_as_str;
return false;

@ -103,7 +103,8 @@ bool Image::LoadMetadata() {
}
base::JSONReader reader;
std::unique_ptr<base::Value> metadata(reader.ReadToValue(json_data));
std::unique_ptr<base::Value> metadata(
reader.ReadToValueDeprecated(json_data));
if (!metadata) {
VLOGF(1) << "Failed to parse image metadata: " << json_path << ": "
<< reader.GetErrorMessage();

@ -124,7 +124,8 @@ bool Video::LoadMetadata() {
}
base::JSONReader reader;
std::unique_ptr<base::Value> metadata(reader.ReadToValue(json_data));
std::unique_ptr<base::Value> metadata(
reader.ReadToValueDeprecated(json_data));
if (!metadata) {
VLOGF(1) << "Failed to parse video metadata: " << json_path << ": "
<< reader.GetErrorMessage();

@ -54,8 +54,8 @@ base::DictionaryValue* ReadHeader(base::StringPiece* data) {
const base::StringPiece header_bytes(data->data(), header_len);
data->remove_prefix(header_len);
std::unique_ptr<base::Value> header =
base::JSONReader::Read(header_bytes, base::JSON_ALLOW_TRAILING_COMMAS);
std::unique_ptr<base::Value> header = base::JSONReader::ReadDeprecated(
header_bytes, base::JSON_ALLOW_TRAILING_COMMAS);
if (header.get() == nullptr)
return nullptr;

@ -1242,7 +1242,7 @@ TEST_P(HttpServerPropertiesManagerTest,
}
TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) {
std::unique_ptr<base::Value> server_value = base::JSONReader::Read(
std::unique_ptr<base::Value> server_value = base::JSONReader::ReadDeprecated(
"{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"h2\"},"
"{\"port\":123,\"protocol_str\":\"quic\","
"\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\","
@ -1294,7 +1294,7 @@ TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) {
// Regression test for https://crbug.com/615497.
TEST_P(HttpServerPropertiesManagerTest, DoNotLoadAltSvcForInsecureOrigins) {
std::unique_ptr<base::Value> server_value = base::JSONReader::Read(
std::unique_ptr<base::Value> server_value = base::JSONReader::ReadDeprecated(
"{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"h2\","
"\"expiration\":\"9223372036854775807\"}]}");
ASSERT_TRUE(server_value);
@ -1515,7 +1515,7 @@ TEST_P(HttpServerPropertiesManagerTest, PersistAdvertisedVersionsToPref) {
}
TEST_P(HttpServerPropertiesManagerTest, ReadAdvertisedVersionsFromPref) {
std::unique_ptr<base::Value> server_value = base::JSONReader::Read(
std::unique_ptr<base::Value> server_value = base::JSONReader::ReadDeprecated(
"{\"alternative_service\":["
"{\"port\":443,\"protocol_str\":\"quic\"},"
"{\"port\":123,\"protocol_str\":\"quic\","
@ -1686,7 +1686,7 @@ TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
std::string expiration_str =
base::NumberToString(static_cast<int64_t>(one_day_from_now_.ToTimeT()));
std::unique_ptr<base::Value> server_value = base::JSONReader::Read(
std::unique_ptr<base::Value> server_value = base::JSONReader::ReadDeprecated(
"{"
"\"broken_alternative_services\":["
"{\"broken_until\":\"" +

@ -292,7 +292,8 @@ bool TransportSecurityPersister::LoadEntries(const std::string& serialized,
bool TransportSecurityPersister::Deserialize(const std::string& serialized,
bool* dirty,
TransportSecurityState* state) {
std::unique_ptr<base::Value> value = base::JSONReader::Read(serialized);
std::unique_ptr<base::Value> value =
base::JSONReader::ReadDeprecated(serialized);
base::DictionaryValue* dict_value = NULL;
if (!value.get() || !value->GetAsDictionary(&dict_value))
return false;

@ -239,7 +239,7 @@ void CheckHPKPReport(
const scoped_refptr<X509Certificate>& served_certificate_chain,
const scoped_refptr<X509Certificate>& validated_certificate_chain,
const HashValueVector& known_pins) {
std::unique_ptr<base::Value> value(base::JSONReader::Read(report));
std::unique_ptr<base::Value> value(base::JSONReader::ReadDeprecated(report));
ASSERT_TRUE(value);
ASSERT_TRUE(value->is_dict());

@ -127,7 +127,7 @@ struct ParsedNetLog {
}
base::JSONReader reader;
container = reader.ReadToValue(input);
container = reader.ReadToValueDeprecated(input);
if (!container) {
return ::testing::AssertionFailure() << reader.GetErrorMessage();
}

@ -108,8 +108,8 @@ class TraceNetLogObserverTest : public TestWithScopedTaskEnvironment {
trace_buffer_.Finish();
std::unique_ptr<base::Value> trace_value;
trace_value =
base::JSONReader::Read(json_output_.json_output, base::JSON_PARSE_RFC);
trace_value = base::JSONReader::ReadDeprecated(json_output_.json_output,
base::JSON_PARSE_RFC);
ASSERT_TRUE(trace_value) << json_output_.json_output;
base::ListValue* trace_events = nullptr;

@ -403,8 +403,8 @@ class NetworkErrorLoggingServiceImpl : public NetworkErrorLoggingService {
if (json_value.size() > kMaxJsonSize)
return HeaderOutcome::DISCARDED_JSON_TOO_BIG;
std::unique_ptr<base::Value> value =
base::JSONReader::Read(json_value, base::JSON_PARSE_RFC, kMaxJsonDepth);
std::unique_ptr<base::Value> value = base::JSONReader::ReadDeprecated(
json_value, base::JSON_PARSE_RFC, kMaxJsonDepth);
if (!value)
return HeaderOutcome::DISCARDED_JSON_INVALID;

@ -37,7 +37,7 @@ void FuzzReportingHeaderParser(const std::string& data_json,
// Emulate what ReportingService::OnHeader does before calling
// ReportingHeaderParser::ParseHeader.
std::unique_ptr<base::Value> data_value =
base::JSONReader::Read("[" + data_json + "]");
base::JSONReader::ReadDeprecated("[" + data_json + "]");
if (!data_value)
return;

@ -26,7 +26,7 @@ class ReportingHeaderParserTest : public ReportingTestBase {
protected:
void ParseHeader(const GURL& url, const std::string& json) {
std::unique_ptr<base::Value> value =
base::JSONReader::Read("[" + json + "]");
base::JSONReader::ReadDeprecated("[" + json + "]");
if (value)
ReportingHeaderParser::ParseHeader(context(), url, std::move(value));
}

@ -66,8 +66,9 @@ class ReportingServiceImpl : public ReportingService {
return;
}
std::unique_ptr<base::Value> header_value = base::JSONReader::Read(
"[" + header_string + "]", base::JSON_PARSE_RFC, kMaxJsonDepth);
std::unique_ptr<base::Value> header_value =
base::JSONReader::ReadDeprecated("[" + header_string + "]",
base::JSON_PARSE_RFC, kMaxJsonDepth);
if (!header_value) {
ReportingHeaderParser::RecordHeaderDiscardedForJsonInvalid();
return;

@ -53,7 +53,7 @@ class PendingUploadImpl : public TestReportingUploader::PendingUpload {
const GURL& url() const override { return url_; }
const std::string& json() const override { return json_; }
std::unique_ptr<base::Value> GetValue() const override {
return base::JSONReader::Read(json_);
return base::JSONReader::ReadDeprecated(json_);
}
void Complete(ReportingUploader::Outcome outcome) override {

@ -502,7 +502,8 @@ bool BaseTestServer::SetAndParseServerData(const std::string& server_data,
int* port) {
VLOG(1) << "Server data: " << server_data;
base::JSONReader json_reader;
std::unique_ptr<base::Value> value(json_reader.ReadToValue(server_data));
std::unique_ptr<base::Value> value(
json_reader.ReadToValueDeprecated(server_data));
if (!value.get() || !value->is_dict()) {
LOG(ERROR) << "Could not parse server data: "
<< json_reader.GetErrorMessage();

@ -59,8 +59,8 @@ RemoteTestServerConfig RemoteTestServerConfig::Load() {
if (!ReadFileToString(config_path, &config_json))
LOG(FATAL) << "Failed to read " << config_path.value();
std::unique_ptr<base::DictionaryValue> config =
base::DictionaryValue::From(base::JSONReader::Read(config_json));
std::unique_ptr<base::DictionaryValue> config = base::DictionaryValue::From(
base::JSONReader::ReadDeprecated(config_json));
if (!config)
LOG(FATAL) << "Failed to parse " << config_path.value();

@ -62,7 +62,7 @@ bool ReadTestCase(const char* filename,
return false;
}
std::unique_ptr<base::Value> value = base::JSONReader::Read(json);
std::unique_ptr<base::Value> value = base::JSONReader::ReadDeprecated(json);
if (!value.get()) {
LOG(ERROR) << filename << ": couldn't parse JSON.";
return false;

@ -310,7 +310,7 @@ bool ParseJSON(base::StringPiece json,
"test", "public-suffix", "google", "custom",
"bulk-legacy", "bulk-18-weeks", "bulk-1-year", "public-suffix-requested"};
std::unique_ptr<base::Value> value = base::JSONReader::Read(json);
std::unique_ptr<base::Value> value = base::JSONReader::ReadDeprecated(json);
base::DictionaryValue* dict_value = nullptr;
if (!value.get() || !value->GetAsDictionary(&dict_value)) {
LOG(ERROR) << "Could not parse the input JSON file";

@ -6664,7 +6664,7 @@ TEST_F(URLRequestTestHTTP, ProcessPKPAndSendReport) {
EXPECT_EQ("application/json; charset=utf-8",
mock_report_sender.latest_content_type());
std::unique_ptr<base::Value> value(
base::JSONReader::Read(mock_report_sender.latest_report()));
base::JSONReader::ReadDeprecated(mock_report_sender.latest_report()));
ASSERT_TRUE(value);
ASSERT_TRUE(value->is_dict());
base::DictionaryValue* report_dict;

@ -47,7 +47,8 @@ const char kPrinterSettings[] = R"({
}
TEST(PrintSettingsConversionTest, ConversionTest) {
std::unique_ptr<base::Value> value = base::JSONReader::Read(kPrinterSettings);
std::unique_ptr<base::Value> value =
base::JSONReader::ReadDeprecated(kPrinterSettings);
ASSERT_TRUE(value);
PrintSettings settings;
bool success = PrintSettingsFromJobSettings(
@ -61,7 +62,8 @@ TEST(PrintSettingsConversionTest, ConversionTest) {
#if defined(OS_CHROMEOS)
TEST(PrintSettingsConversionTest, ConversionTest_DontSendUsername) {
std::unique_ptr<base::Value> value = base::JSONReader::Read(kPrinterSettings);
std::unique_ptr<base::Value> value =
base::JSONReader::ReadDeprecated(kPrinterSettings);
ASSERT_TRUE(value);
value->SetKey(kSettingSendUserInfo, base::Value(false));
PrintSettings settings;

@ -28,7 +28,8 @@ bool OriginPolicyParser::DoParse(base::StringPiece policy_text) {
if (policy_text.empty())
return false;
std::unique_ptr<base::Value> json = base::JSONReader::Read(policy_text);
std::unique_ptr<base::Value> json =
base::JSONReader::ReadDeprecated(policy_text);
if (!json || !json->is_dict())
return false;

@ -168,8 +168,8 @@ std::unique_ptr<TrialToken> TrialToken::Parse(
return nullptr;
}
std::unique_ptr<base::DictionaryValue> datadict =
base::DictionaryValue::From(base::JSONReader::Read(token_payload));
std::unique_ptr<base::DictionaryValue> datadict = base::DictionaryValue::From(
base::JSONReader::ReadDeprecated(token_payload));
if (!datadict) {
return nullptr;
}

@ -136,7 +136,7 @@ std::unique_ptr<Value> StringUtil::parseMessage(
reinterpret_cast<const uint8_t*>(message.data()),
message.length());
}
std::unique_ptr<base::Value> value = base::JSONReader::Read(message);
std::unique_ptr<base::Value> value = base::JSONReader::ReadDeprecated(message);
return toProtocolValue(value.get(), 1000);
}

@ -28,7 +28,7 @@ namespace {
// |json| is converted to a |c_str()| here because rapidjson and other parts
// of the standalone library use char* rather than std::string.
::std::unique_ptr<const base::Value> parsed(
base::JSONReader::Read(json.c_str()));
base::JSONReader::ReadDeprecated(json.c_str()));
*parser_error = !parsed || !parsed->is_dict();
if (*parser_error)

@ -16,8 +16,9 @@ namespace test_util {
std::unique_ptr<base::Value> ReadJson(const base::StringPiece& json) {
int error_code;
std::string error_msg;
std::unique_ptr<base::Value> result(base::JSONReader::ReadAndReturnError(
json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error_msg));
std::unique_ptr<base::Value> result(
base::JSONReader::ReadAndReturnErrorDeprecated(
json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code, &error_msg));
// CHECK not ASSERT since passing invalid |json| is a test error.
CHECK(result) << error_msg;
return result;

@ -983,7 +983,8 @@ TEST_F(LayerWithNullDelegateTest, EscapedDebugNames) {
std::string json;
debug_info->AppendAsTraceFormat(&json);
base::JSONReader json_reader;
std::unique_ptr<base::Value> debug_info_value(json_reader.ReadToValue(json));
std::unique_ptr<base::Value> debug_info_value(
json_reader.ReadToValueDeprecated(json));
EXPECT_TRUE(debug_info_value);
EXPECT_TRUE(debug_info_value->is_dict());
base::DictionaryValue* dictionary = 0;

@ -49,8 +49,9 @@ TEST(JsonConverterTest, JsonFromToDisplayLayout) {
"}";
int error_code = 0, error_line, error_column;
std::string error_msg;
std::unique_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError(
data, 0, &error_code, &error_msg, &error_line, &error_column));
std::unique_ptr<base::Value> read_value(
base::JSONReader::ReadAndReturnErrorDeprecated(
data, 0, &error_code, &error_msg, &error_line, &error_column));
ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":"
<< error_column;
EXPECT_TRUE(value.Equals(read_value.get()));
@ -72,8 +73,9 @@ TEST(JsonConverterTest, OldJsonToDisplayLayout) {
"}";
int error_code = 0, error_line, error_column;
std::string error_msg;
std::unique_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError(
data, 0, &error_code, &error_msg, &error_line, &error_column));
std::unique_ptr<base::Value> read_value(
base::JSONReader::ReadAndReturnErrorDeprecated(
data, 0, &error_code, &error_msg, &error_line, &error_column));
ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":"
<< error_column;

@ -16,7 +16,7 @@ CaptionStyle::~CaptionStyle() = default;
// static
CaptionStyle CaptionStyle::FromSpec(const std::string& spec) {
CaptionStyle style;
std::unique_ptr<base::Value> dict = base::JSONReader::Read(spec);
std::unique_ptr<base::Value> dict = base::JSONReader::ReadDeprecated(spec);
if (!dict || !dict->is_dict())
return style;