0

Introduce grd file for metrics URLs

Currently, metrics (UMA) URLs are stored in a cc file. Depending on if
this is a Chrome-branded build, a src-internal version of the cc file
will be used instead.

Unfortunately, that set up is not LGPL compliant. Instead, they should
be moved to resources/grd files.

This CL is the first part. It introduces the resources files, and adds
them to the various build targets that will need it.

Additionally, native WebView unit tests (`android_webview_unittests`
build target) don't currently load any resources, like other test
suites (e.g. `components_unittests`). Since some native WebView unit
tests will need to access the URLs/resources in this CL, this CL also
adds a resource initialization step to this test suite. I copied the
set up of other test suites to do this, e.g.
https://source.chromium.org/chromium/chromium/src/+/main:components/test/components_test_suite.cc

Bug: 358224254
Change-Id: I44efd5a50e5ded05318e61de594f35550df4dfae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5953911
Reviewed-by: Richard (Torne) Coles <torne@chromium.org>
Owners-Override: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Luc Nguyen <lucnguyen@google.com>
Cr-Commit-Position: refs/heads/main@{#1374261}
This commit is contained in:
Luc Nguyen
2024-10-26 06:43:42 +00:00
committed by Chromium LUCI CQ
parent cc7e188ed6
commit ec29f0fca7
12 changed files with 131 additions and 1 deletions
android_webview
chrome
chromecast
components
ios/chrome/app/resources
tools/gritsettings

@ -1002,6 +1002,7 @@ android_assets("locale_pak_assets") {
repack("repack_pack") {
sources = [
"$root_gen_dir/components/metrics/metrics_url_constants.pak",
"$root_gen_dir/content/content_resources.pak",
"$root_gen_dir/content/histograms_resources.pak",
"$root_gen_dir/net/net_resources.pak",
@ -1015,6 +1016,7 @@ repack("repack_pack") {
":generate_components_resources",
":generate_mojo_resources",
":generate_webui_resources",
"//components/metrics:url_constants",
"//content:content_resources",
"//content/browser/resources/histograms:resources",
"//net:net_resources",

@ -17,6 +17,7 @@ include_rules = [
"+third_party/blink/public/common/switches.h",
"+tools/v8_context_snapshot/buildflags.h",
"+ui/events/gesture_detection",
"+ui/base",
"+ui/gl",
]

@ -4,13 +4,47 @@
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/test/allow_check_is_test_for_testing.h"
#include "base/test/test_suite.h"
#include "content/public/common/content_switches.h"
#include "mojo/core/embedder/embedder.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/test/gl_surface_test_support.h"
namespace {
class AndroidWebViewTestSuite : public base::TestSuite {
public:
AndroidWebViewTestSuite(int argc, char** argv)
: base::TestSuite(argc, argv) {}
AndroidWebViewTestSuite(const AndroidWebViewTestSuite&) = delete;
AndroidWebViewTestSuite& operator=(const AndroidWebViewTestSuite&) = delete;
private:
void Initialize() override {
base::TestSuite::Initialize();
ui::RegisterPathProvider();
base::FilePath pak_path;
ASSERT_TRUE(
base::PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path));
ui::ResourceBundle::InitSharedInstanceWithPakPath(
pak_path.AppendASCII("android_webview_unittests_resources.pak"));
}
void Shutdown() override {
ui::ResourceBundle::CleanupSharedInstance();
base::TestSuite::Shutdown();
}
};
} // namespace
int main(int argc, char** argv) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitch(switches::kSingleProcess);
@ -20,7 +54,7 @@ int main(int argc, char** argv) {
gl::GLSurfaceTestSupport::InitializeNoExtensionsOneOff();
base::test::AllowCheckIsTestForTesting();
base::TestSuite test_suite(argc, argv);
AndroidWebViewTestSuite test_suite(argc, argv);
mojo::core::Init();
return test_suite.Run();
}

@ -10,6 +10,7 @@ import("//build/config/python.gni")
import("//device/vr/buildflags/buildflags.gni")
import("//testing/test.gni")
import("//third_party/jni_zero/jni_zero.gni")
import("//tools/grit/repack.gni")
# Mark all targets as test only.
testonly = true
@ -595,6 +596,14 @@ source_set("webview_instrumentation_test_native_jni_impl") {
]
}
repack("android_webview_unittests_pak") {
sources = [ "$root_gen_dir/components/metrics/metrics_url_constants.pak" ]
deps = [ "//components/metrics:url_constants" ]
output = "$root_out_dir/android_webview_unittests_resources.pak"
}
test("android_webview_unittests") {
deps = [
":android_webview_unittests_assets",
@ -642,12 +651,16 @@ test("android_webview_unittests") {
"//net/third_party/quiche:blind_sign_auth",
"//services/cert_verifier/public/mojom",
"//services/network:test_support",
"//testing/gtest",
"//third_party/anonymous_tokens:anonymous_tokens_cc_proto",
"//ui/base",
"//ui/base:ui_base_jni_headers",
"//ui/gl",
"//ui/gl:test_support",
]
data_deps = [ ":android_webview_unittests_pak" ]
data = [ "data/" ]
sources = [

@ -117,6 +117,7 @@ template("chrome_extra_paks") {
"$root_gen_dir/components/autofill/core/browser/autofill_address_rewriter_resources.pak",
"$root_gen_dir/components/components_resources.pak",
"$root_gen_dir/components/flags_ui_resources.pak",
"$root_gen_dir/components/metrics/metrics_url_constants.pak",
"$root_gen_dir/components/version_ui_resources.pak",
"$root_gen_dir/content/attribution_internals_resources.pak",
"$root_gen_dir/content/content_resources.pak",
@ -138,6 +139,7 @@ template("chrome_extra_paks") {
"//chrome/browser/resources:resources",
"//chrome/common:resources",
"//components/autofill/core/browser:autofill_address_rewriter_resources",
"//components/metrics:url_constants",
"//components/resources",
"//content:content_resources",
"//content/browser/resources:resources",

@ -543,6 +543,7 @@ if (!is_fuchsia) {
sources = [
"$root_gen_dir/chromecast/app/shell_resources.pak",
"$root_gen_dir/components/cast/named_message_port_connector/named_message_port_connector_resources.pak",
"$root_gen_dir/components/metrics/metrics_url_constants.pak",
"$root_gen_dir/content/content_resources.pak",
"$root_gen_dir/content/gpu_resources.pak",
"$root_gen_dir/mojo/public/js/mojo_bindings_resources.pak",
@ -562,6 +563,7 @@ if (!is_fuchsia) {
deps = [
"//chromecast/app:resources",
"//components/cast/named_message_port_connector:resources",
"//components/metrics:url_constants",
"//content:content_resources",
"//content/browser/resources/gpu:resources",
"//mojo/public/js:resources",

@ -895,6 +895,7 @@ repack("components_tests_pak") {
"$root_gen_dir/components/arc/input_overlay_resources.pak",
"$root_gen_dir/components/autofill/core/browser/autofill_address_rewriter_resources.pak",
"$root_gen_dir/components/components_resources.pak",
"$root_gen_dir/components/metrics/metrics_url_constants.pak",
"$root_gen_dir/components/omnibox/resources/omnibox_pedal_synonyms_en-US.pak",
"$root_gen_dir/components/plus_addresses/resources/strings/plus_addresses_strings_en-US.pak",
"$root_gen_dir/components/strings/components_locale_settings_en-US.pak",
@ -907,6 +908,7 @@ repack("components_tests_pak") {
# thus not going to move this resource pak to under ash.
"//ash/components/arc/input_overlay/resources:resources_grit",
"//components/autofill/core/browser:autofill_address_rewriter_resources",
"//components/metrics:url_constants",
"//components/omnibox/resources:omnibox_pedal_synonyms",
"//components/plus_addresses/resources/strings",
"//components/resources",

@ -6,6 +6,7 @@ import("//build/config/chromeos/ui_mode.gni")
import("//build/config/cronet/config.gni")
import("//build/config/features.gni")
import("//testing/test.gni")
import("//tools/grit/grit_rule.gni")
if (is_android) {
import("//build/config/android/rules.gni")
@ -676,3 +677,15 @@ if (!is_cronet_build) {
]
}
}
grit("url_constants") {
if (is_chrome_branded) {
source = "internal/url_constants.grd"
} else {
source = "url_constants.grd"
}
outputs = [
"grit/metrics_url_constants.h",
"metrics_url_constants.pak",
]
}

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
The URL strings in this file are intentionally empty to prevent Chromium forks from
accidentally sending metrics to Google servers. The values for Chrome-branded builds can
be found here:
https://chrome-internal.googlesource.com/chrome/components/metrics/internal/+/main/url_constants.grd
Note that for LGPL compliance reasons, these URL strings are stored in resource files
rather than the code.
-->
<grit latest_public_release="0" current_release="1" output_all_resource_defines="false">
<outputs>
<output filename="grit/metrics_url_constants.h" type="rc_header">
<emit emit_type='prepend'></emit>
</output>
<output filename="metrics_url_constants.pak" type="data_package" />
</outputs>
<release seq="1">
<messages fallback_to_english="true">
<!-- Ideally, these would be empty strings, but Grit skips empty messages.
So instead, use a dash as a placeholder, which we manually interpret as
an empty string in the cpp code. -->
<message name="IDS_NEW_METRICS_SERVER_URL" translateable="false">
-
</message>
<message name="IDS_NEW_METRICS_SERVER_URL_INSECURE" translateable="false">
-
</message>
<message name="IDS_OLD_METRICS_SERVER_URL" translateable="false">
-
</message>
<message name="IDS_DEFAULT_METRICS_MIME_TYPE" translateable="false">
-
</message>
<message name="IDS_DEFAULT_UKM_SERVER_URL" translateable="false">
-
</message>
<message name="IDS_UKM_MIME_TYPE" translateable="false">
-
</message>
<message name="IDS_DEFAULT_DWA_SERVER_URL" translateable="false">
-
</message>
</messages>
</release>
</grit>

@ -64,6 +64,7 @@ repack("repack_unscaled_resources") {
"$root_gen_dir/components/dev_ui_components_resources.pak",
"$root_gen_dir/components/download_internals_resources.pak",
"$root_gen_dir/components/flags_ui_resources.pak",
"$root_gen_dir/components/metrics/metrics_url_constants.pak",
"$root_gen_dir/components/optimization_guide_internals_resources.pak",
"$root_gen_dir/components/policy_resources.pak",
"$root_gen_dir/components/sync_service_sync_internals_resources.pak",
@ -79,6 +80,7 @@ repack("repack_unscaled_resources") {
":ios_resources",
"//components/commerce/core/internals/resources",
"//components/download/resources/download_internals:resources",
"//components/metrics:url_constants",
"//components/optimization_guide/optimization_guide_internals/resources",
"//components/policy/resources/webui:resources",
"//components/resources",

@ -940,7 +940,17 @@
"components/headless/command_handler/headless_command.grd": {
"includes": [7120],
},
# metrics/internal/url_constants.grd and metrics/url_constants.grd must
# share the same id because they define the same strings, but only one of them
# is built depending on whether src_internal is available.
"components/metrics/internal/url_constants.grd": {
"messages": [7130],
},
"components/metrics/url_constants.grd": {
"messages": [7130],
},
"components/omnibox/resources/omnibox_pedal_synonyms.grd": {
"META": {"join": 2},
"messages": [7140],
},
# plus_addresses_internal_strings.grd and plus_addresses_strings.grd must

@ -123,6 +123,7 @@
"chrome/app/resources/locale_settings_win.grd": "Not UI strings; localized separately",
"chromecast/app/resources/chromecast_settings.grd": "Not UI strings; localized separately",
"components/components_locale_settings.grd": "Not UI strings; localized separately",
"components/metrics/url_constants.grd": "Not UI strings; URLs of metrics endpoints",
"components/search_engine_descriptions_strings.grd": "The strings are already translated when provided",
"components/plus_addresses/resources/strings/plus_addresses_strings.grd": "UX research ongoing - strings are not yet finalized",
"components/policy/resources/policy_templates.build.grd": "Copy of policy_templates.grd used locally for build only",