Commit fd47837f authored by Yue Ru Sun's avatar Yue Ru Sun Committed by Commit Bot

Fix duplication of UkmSamplingRate feature instance

This patch fixes the crash on debugging build when visiting chrome://ukm
due to CheckFeatureIdentity(UkmSamplingRate) failure.
COMPONENT_EXPORT makes the definition of the base::Feature
UkmSamplingRate from ukm_recorder_impl.cc exported and shared by the
libraries that reference it, ensuring there's only one copy of the
base::Feature in memory.

Bug-id: b/160004246
Change-Id: Icda0e0a403538a263f8132afc19dd0cb455395db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2274240
Commit-Queue: Yue Ru Sun <yrsun@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784145}
parent d467eb74
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "content/public/browser/browsing_data_remover.h" #include "content/public/browser/browsing_data_remover.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/browsing_data_remover_test_util.h" #include "content/public/test/browsing_data_remover_test_util.h"
...@@ -1441,4 +1442,26 @@ IN_PROC_BROWSER_TEST_F(UkmBrowserTest, NotMarkSourcesIfNavigationNotCommitted) { ...@@ -1441,4 +1442,26 @@ IN_PROC_BROWSER_TEST_F(UkmBrowserTest, NotMarkSourcesIfNavigationNotCommitted) {
} }
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
#if !defined(OS_ANDROID)
IN_PROC_BROWSER_TEST_F(UkmBrowserTest, DebugUiRenders) {
MetricsConsentOverride metrics_consent(true);
Profile* profile = ProfileManager::GetActiveUserProfile();
std::unique_ptr<ProfileSyncServiceHarness> harness =
EnableSyncForProfile(profile);
PlatformBrowser browser = CreatePlatformBrowser(profile);
ukm::UkmService* ukm_service(GetUkmService());
EXPECT_TRUE(ukm_service->IsSamplingEnabled());
// chrome://ukm
const GURL debug_url(content::GetWebUIURLString(content::kChromeUIUkmHost));
content::TestNavigationObserver waiter(debug_url);
waiter.WatchExistingWebContents();
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser, debug_url));
waiter.WaitForNavigationFinished();
}
#endif // !defined(OS_ANDROID)
} // namespace metrics } // namespace metrics
...@@ -4,6 +4,35 @@ ...@@ -4,6 +4,35 @@
import("//testing/test.gni") import("//testing/test.gni")
component("ukm_recorder") {
output_name = "ukm_recorder"
defines = [ "IS_UKM_RECORDER_IMPL" ]
friend = [
":test_support",
":unit_tests",
]
sources = [
"scheme_constants.cc",
"scheme_constants.h",
"ukm_entry_filter.h",
"ukm_recorder_impl.cc",
"ukm_recorder_impl.h",
]
deps = [
"//base",
"//components/variations",
"//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/cpp:ukm_builders",
"//services/metrics/public/mojom",
"//third_party/metrics_proto",
"//url",
]
}
# The Url-Keyed Metrics (UKM) service is responsible for gathering and # The Url-Keyed Metrics (UKM) service is responsible for gathering and
# uploading reports that contain fine grained performance metrics including # uploading reports that contain fine grained performance metrics including
# URLs for top-level navigations. # URLs for top-level navigations.
...@@ -13,13 +42,8 @@ static_library("ukm") { ...@@ -13,13 +42,8 @@ static_library("ukm") {
"app_source_url_recorder.h", "app_source_url_recorder.h",
"field_trials_provider_helper.cc", "field_trials_provider_helper.cc",
"field_trials_provider_helper.h", "field_trials_provider_helper.h",
"scheme_constants.cc",
"scheme_constants.h",
"ukm_entry_filter.h",
"ukm_pref_names.cc", "ukm_pref_names.cc",
"ukm_pref_names.h", "ukm_pref_names.h",
"ukm_recorder_impl.cc",
"ukm_recorder_impl.h",
"ukm_reporting_service.cc", "ukm_reporting_service.cc",
"ukm_reporting_service.h", "ukm_reporting_service.h",
"ukm_rotation_scheduler.cc", "ukm_rotation_scheduler.cc",
...@@ -31,6 +55,7 @@ static_library("ukm") { ...@@ -31,6 +55,7 @@ static_library("ukm") {
] ]
public_deps = [ public_deps = [
":ukm_recorder",
"//services/metrics/public/cpp:metrics_cpp", "//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/cpp:ukm_builders", "//services/metrics/public/cpp:ukm_builders",
"//services/metrics/public/mojom", "//services/metrics/public/mojom",
......
...@@ -5,15 +5,20 @@ ...@@ -5,15 +5,20 @@
#ifndef COMPONENTS_UKM_SCHEME_CONSTANTS_H_ #ifndef COMPONENTS_UKM_SCHEME_CONSTANTS_H_
#define COMPONENTS_UKM_SCHEME_CONSTANTS_H_ #define COMPONENTS_UKM_SCHEME_CONSTANTS_H_
#include "base/component_export.h"
namespace ukm { namespace ukm {
// Defines several URL scheme constants to avoid dependencies. // Defines several URL scheme constants to avoid dependencies.
// kAppScheme will be defined in code that isn't available here. // kAppScheme will be defined in code that isn't available here.
COMPONENT_EXPORT(UKM_RECORDER)
extern const char kAppScheme[]; extern const char kAppScheme[];
// kChromeUIScheme is defined in content, which this code can't depend on // kChromeUIScheme is defined in content, which this code can't depend on
// since it's used by iOS too. // since it's used by iOS too.
COMPONENT_EXPORT(UKM_RECORDER)
extern const char kChromeUIScheme[]; extern const char kChromeUIScheme[];
// kExtensionScheme is defined in extensions which also isn't available here. // kExtensionScheme is defined in extensions which also isn't available here.
COMPONENT_EXPORT(UKM_RECORDER)
extern const char kExtensionScheme[]; extern const char kExtensionScheme[];
} // namespace ukm } // namespace ukm
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include "base/component_export.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/metrics/crc32.h" #include "base/metrics/crc32.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
...@@ -33,11 +34,12 @@ ...@@ -33,11 +34,12 @@
namespace ukm { namespace ukm {
namespace { COMPONENT_EXPORT(UKM_RECORDER)
const base::Feature kUkmSamplingRateFeature{"UkmSamplingRate", const base::Feature kUkmSamplingRateFeature{"UkmSamplingRate",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
namespace {
// Gets the list of whitelisted Entries as string. Format is a comma separated // Gets the list of whitelisted Entries as string. Format is a comma separated
// list of Entry names (as strings). // list of Entry names (as strings).
std::string GetWhitelistEntries() { std::string GetWhitelistEntries() {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <vector> #include <vector>
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/component_export.h"
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
...@@ -39,7 +40,7 @@ namespace debug { ...@@ -39,7 +40,7 @@ namespace debug {
class UkmDebugDataExtractor; class UkmDebugDataExtractor;
} }
class UkmRecorderImpl : public UkmRecorder { class COMPONENT_EXPORT(UKM_RECORDER) UkmRecorderImpl : public UkmRecorder {
using IsWebstoreExtensionCallback = using IsWebstoreExtensionCallback =
base::RepeatingCallback<bool(base::StringPiece id)>; base::RepeatingCallback<bool(base::StringPiece id)>;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/ukm/scheme_constants.h" #include "components/ukm/scheme_constants.h"
#include "components/ukm/ukm_pref_names.h" #include "components/ukm/ukm_pref_names.h"
#include "components/ukm/ukm_recorder_impl.h"
#include "components/ukm/ukm_rotation_scheduler.h" #include "components/ukm/ukm_rotation_scheduler.h"
#include "services/metrics/public/cpp/delegating_ukm_recorder.h" #include "services/metrics/public/cpp/delegating_ukm_recorder.h"
#include "third_party/metrics_proto/ukm/report.pb.h" #include "third_party/metrics_proto/ukm/report.pb.h"
......
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