Commit 0903a279 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

AppCache: Modernize base::Value usage in appcache_internals_ui.cc.

Change-Id: I8bfea548a2d9bea527effcdfa1a673ee0f8d06f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2360603
Commit-Queue: Victor Costan <pwnall@chromium.org>
Auto-Submit: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799022}
parent b8c5eb85
......@@ -34,6 +34,7 @@
#include "services/network/public/mojom/content_security_policy.mojom.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom.h"
#include "third_party/blink/public/mojom/appcache/appcache_info.mojom.h"
#include "ui/base/text/bytes_formatting.h"
namespace content {
......@@ -62,101 +63,93 @@ bool SortByResourceUrl(const blink::mojom::AppCacheResourceInfo& lhs,
return lhs.url.spec() < rhs.url.spec();
}
std::unique_ptr<base::DictionaryValue> GetDictionaryValueForResponseEnquiry(
base::Value GetDictionaryValueForResponseEnquiry(
const content::AppCacheInternalsUI::ProxyResponseEnquiry&
response_enquiry) {
auto dict_value = std::make_unique<base::DictionaryValue>();
dict_value->SetString("manifestURL", response_enquiry.manifest_url);
dict_value->SetString("groupId",
base::NumberToString(response_enquiry.group_id));
dict_value->SetString("responseId",
base::NumberToString(response_enquiry.response_id));
return dict_value;
base::Value dict(base::Value::Type::DICTIONARY);
dict.SetStringKey("manifestURL", response_enquiry.manifest_url);
dict.SetStringKey("groupId", base::NumberToString(response_enquiry.group_id));
dict.SetStringKey("responseId",
base::NumberToString(response_enquiry.response_id));
return dict;
}
std::unique_ptr<base::DictionaryValue> GetDictionaryValueForAppCacheInfo(
base::Value GetDictionaryValueForAppCacheInfo(
const blink::mojom::AppCacheInfo& appcache_info) {
auto dict_value = std::make_unique<base::DictionaryValue>();
dict_value->SetString("manifestURL", appcache_info.manifest_url.spec());
dict_value->SetDouble("creationTime", appcache_info.creation_time.ToJsTime());
dict_value->SetDouble("lastUpdateTime",
appcache_info.last_update_time.ToJsTime());
dict_value->SetDouble("lastAccessTime",
appcache_info.last_access_time.ToJsTime());
dict_value->SetDouble("tokenExpires", appcache_info.token_expires.ToJsTime());
dict_value->SetString("responseSizes",
base::UTF16ToUTF8(base::FormatBytesUnlocalized(
appcache_info.response_sizes)));
dict_value->SetString("paddingSizes",
base::UTF16ToUTF8(base::FormatBytesUnlocalized(
appcache_info.padding_sizes)));
dict_value->SetString(
"totalSize",
base::UTF16ToUTF8(base::FormatBytesUnlocalized(
appcache_info.response_sizes + appcache_info.padding_sizes)));
dict_value->SetString("groupId",
base::NumberToString(appcache_info.group_id));
dict_value->SetString(
base::Value dict(base::Value::Type::DICTIONARY);
dict.SetStringKey("manifestURL", appcache_info.manifest_url.spec());
dict.SetDoubleKey("creationTime", appcache_info.creation_time.ToJsTime());
dict.SetDoubleKey("lastUpdateTime",
appcache_info.last_update_time.ToJsTime());
dict.SetDoubleKey("lastAccessTime",
appcache_info.last_access_time.ToJsTime());
dict.SetDoubleKey("tokenExpires", appcache_info.token_expires.ToJsTime());
dict.SetStringKey("responseSizes",
ui::FormatBytes(appcache_info.response_sizes));
dict.SetStringKey("paddingSizes",
ui::FormatBytes(appcache_info.padding_sizes));
dict.SetStringKey("totalSize", ui::FormatBytes(appcache_info.response_sizes +
appcache_info.padding_sizes));
dict.SetStringKey("groupId", base::NumberToString(appcache_info.group_id));
dict.SetStringKey(
"manifestParserVersion",
base::NumberToString(appcache_info.manifest_parser_version));
dict_value->SetString("manifestScope", appcache_info.manifest_scope);
dict.SetStringKey("manifestScope", appcache_info.manifest_scope);
return dict_value;
return dict;
}
std::unique_ptr<base::ListValue> GetListValueForAppCacheInfoVector(
base::Value GetListValueForAppCacheInfoVector(
const std::vector<blink::mojom::AppCacheInfo> appcache_info_vector) {
auto list = std::make_unique<base::ListValue>();
base::Value list(base::Value::Type::LIST);
for (const blink::mojom::AppCacheInfo& info : appcache_info_vector)
list->Append(GetDictionaryValueForAppCacheInfo(info));
list.Append(GetDictionaryValueForAppCacheInfo(info));
return list;
}
std::unique_ptr<base::ListValue> GetListValueFromAppCacheInfoCollection(
base::Value GetListValueFromAppCacheInfoCollection(
AppCacheInfoCollection* appcache_collection) {
auto list = std::make_unique<base::ListValue>();
base::Value list(base::Value::Type::LIST);
for (const auto& key_value : appcache_collection->infos_by_origin) {
auto dict = std::make_unique<base::DictionaryValue>();
base::Value dict(base::Value::Type::DICTIONARY);
// Use GURL::spec() to keep consistency with previous version
dict->SetString("originURL", key_value.first.GetURL().spec());
dict->Set("manifests", GetListValueForAppCacheInfoVector(key_value.second));
list->Append(std::move(dict));
dict.SetStringKey("originURL", key_value.first.GetURL().spec());
dict.SetKey("manifests",
GetListValueForAppCacheInfoVector(key_value.second));
list.Append(std::move(dict));
}
return list;
}
std::unique_ptr<base::DictionaryValue>
GetDictionaryValueForAppCacheResourceInfo(
base::Value GetDictionaryValueForAppCacheResourceInfo(
const blink::mojom::AppCacheResourceInfo& resource_info) {
auto dict = std::make_unique<base::DictionaryValue>();
dict->SetString("url", resource_info.url.spec());
dict->SetString("responseSize",
base::UTF16ToUTF8(base::FormatBytesUnlocalized(
resource_info.response_size)));
dict->SetString("paddingSize", base::UTF16ToUTF8(base::FormatBytesUnlocalized(
resource_info.padding_size)));
dict->SetString("totalSize", base::UTF16ToUTF8(base::FormatBytesUnlocalized(
resource_info.response_size +
resource_info.padding_size)));
dict->SetString("responseId",
base::NumberToString(resource_info.response_id));
dict->SetBoolean("isExplicit", resource_info.is_explicit);
dict->SetBoolean("isManifest", resource_info.is_manifest);
dict->SetBoolean("isMaster", resource_info.is_master);
dict->SetBoolean("isFallback", resource_info.is_fallback);
dict->SetBoolean("isIntercept", resource_info.is_intercept);
dict->SetBoolean("isForeign", resource_info.is_foreign);
base::Value dict(base::Value::Type::DICTIONARY);
dict.SetStringKey("url", resource_info.url.spec());
dict.SetStringKey("responseSize",
ui::FormatBytes(resource_info.response_size));
dict.SetStringKey("paddingSize", ui::FormatBytes(resource_info.padding_size));
dict.SetStringKey("totalSize", ui::FormatBytes(resource_info.response_size +
resource_info.padding_size));
dict.SetStringKey("responseId",
base::NumberToString(resource_info.response_id));
dict.SetBoolKey("isExplicit", resource_info.is_explicit);
dict.SetBoolKey("isManifest", resource_info.is_manifest);
dict.SetBoolKey("isMaster", resource_info.is_master);
dict.SetBoolKey("isFallback", resource_info.is_fallback);
dict.SetBoolKey("isIntercept", resource_info.is_intercept);
dict.SetBoolKey("isForeign", resource_info.is_foreign);
return dict;
}
std::unique_ptr<base::ListValue> GetListValueForAppCacheResourceInfoVector(
base::Value GetListValueForAppCacheResourceInfoVector(
std::vector<blink::mojom::AppCacheResourceInfo>* resource_info_vector) {
auto list = std::make_unique<base::ListValue>();
base::Value list(base::Value::Type::LIST);
for (const blink::mojom::AppCacheResourceInfo& res_info :
*resource_info_vector)
list->Append(GetDictionaryValueForAppCacheResourceInfo(res_info));
*resource_info_vector) {
list.Append(GetDictionaryValueForAppCacheResourceInfo(res_info));
}
return list;
}
......@@ -446,7 +439,7 @@ void AppCacheInternalsUI::OnAllAppCacheInfoReady(
kFunctionOnAllAppCacheInfoReady,
base::Value(partition_path.AsUTF8Unsafe()),
base::Value(incognito_path_prefix + partition_path.AsUTF8Unsafe()),
*GetListValueFromAppCacheInfoCollection(collection.get()));
GetListValueFromAppCacheInfoCollection(collection.get()));
}
void AppCacheInternalsUI::OnAppCacheInfoDeleted(
......@@ -468,7 +461,7 @@ void AppCacheInternalsUI::OnAppCacheDetailsReady(
web_ui()->CallJavascriptFunctionUnsafe(
kFunctionOnAppCacheDetailsReady, base::Value(manifest_url),
base::Value(partition_path.AsUTF8Unsafe()),
*GetListValueForAppCacheResourceInfoVector(resource_info_vector.get()));
GetListValueForAppCacheResourceInfoVector(resource_info_vector.get()));
} else {
web_ui()->CallJavascriptFunctionUnsafe(
kFunctionOnAppCacheDetailsReady, base::Value(manifest_url),
......@@ -507,7 +500,7 @@ void AppCacheInternalsUI::OnFileDetailsReady(
hex_dump.append("</pre>");
web_ui()->CallJavascriptFunctionUnsafe(
kFunctionOnFileDetailsReady,
*GetDictionaryValueForResponseEnquiry(response_enquiry),
GetDictionaryValueForResponseEnquiry(response_enquiry),
base::Value(headers), base::Value(hex_dump));
}
......@@ -516,7 +509,7 @@ void AppCacheInternalsUI::OnFileDetailsFailed(
int net_result_code) {
web_ui()->CallJavascriptFunctionUnsafe(
kFunctionOnFileDetailsFailed,
*GetDictionaryValueForResponseEnquiry(response_enquiry),
GetDictionaryValueForResponseEnquiry(response_enquiry),
base::Value(net_result_code));
}
......
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