Commit 84e845ae authored by Daniil Lunev's avatar Daniil Lunev Committed by Commit Bot

Move kUmaStorageDimension check to provider registration site.

Bug: b:151176984
Change-Id: Ie9a8b76dffba24f464e058406bc95afe4359d31c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2386946
Commit-Queue: Daniil Lunev <dlunev@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarOleh Lamzin <lamzin@google.com>
Cr-Commit-Position: refs/heads/master@{#804498}
parent 517e76b7
...@@ -60,6 +60,7 @@ ...@@ -60,6 +60,7 @@
#include "chrome/browser/translate/translate_ranker_metrics_provider.h" #include "chrome/browser/translate/translate_ranker_metrics_provider.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_paths_internal.h" #include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -712,8 +713,10 @@ void ChromeMetricsServiceClient::RegisterMetricsServiceProviders() { ...@@ -712,8 +713,10 @@ void ChromeMetricsServiceClient::RegisterMetricsServiceProviders() {
std::make_unique<ChromeOSMetricsProvider>( std::make_unique<ChromeOSMetricsProvider>(
metrics::MetricsLogUploader::UMA)); metrics::MetricsLogUploader::UMA));
metrics_service_->RegisterMetricsProvider( if (base::FeatureList::IsEnabled(::features::kUmaStorageDimensions)) {
std::make_unique<CrosHealthdMetricsProvider>()); metrics_service_->RegisterMetricsProvider(
std::make_unique<CrosHealthdMetricsProvider>());
}
metrics_service_->RegisterMetricsProvider( metrics_service_->RegisterMetricsProvider(
std::make_unique<SigninStatusMetricsProviderChromeOS>()); std::make_unique<SigninStatusMetricsProviderChromeOS>());
......
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
#include "base/metrics/persistent_histogram_allocator.h" #include "base/metrics/persistent_histogram_allocator.h"
#include "base/process/process_handle.h" #include "base/process/process_handle.h"
#include "base/test/metrics/user_action_tester.h" #include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/common/buildflags.h" #include "chrome/common/buildflags.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "components/metrics/client_info.h" #include "components/metrics/client_info.h"
...@@ -54,6 +56,7 @@ class ChromeMetricsServiceClientTest : public testing::Test { ...@@ -54,6 +56,7 @@ class ChromeMetricsServiceClientTest : public testing::Test {
base::Unretained(this))); base::Unretained(this)));
ASSERT_TRUE(profile_manager_.SetUp()); ASSERT_TRUE(profile_manager_.SetUp());
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
scoped_feature_list_.InitAndEnableFeature(features::kUmaStorageDimensions);
// ChromeOs Metrics Provider require g_login_state and power manager client // ChromeOs Metrics Provider require g_login_state and power manager client
// initialized before they can be instantiated. // initialized before they can be instantiated.
chromeos::PowerManagerClient::InitializeFake(); chromeos::PowerManagerClient::InitializeFake();
...@@ -85,6 +88,7 @@ class ChromeMetricsServiceClientTest : public testing::Test { ...@@ -85,6 +88,7 @@ class ChromeMetricsServiceClientTest : public testing::Test {
base::UserActionTester user_action_runner_; base::UserActionTester user_action_runner_;
std::unique_ptr<metrics::MetricsStateManager> metrics_state_manager_; std::unique_ptr<metrics::MetricsStateManager> metrics_state_manager_;
metrics::TestEnabledStateProvider enabled_state_provider_; metrics::TestEnabledStateProvider enabled_state_provider_;
base::test::ScopedFeatureList scoped_feature_list_;
private: private:
DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClientTest); DISALLOW_COPY_AND_ASSIGN(ChromeMetricsServiceClientTest);
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/common/chrome_features.h"
#include "chromeos/services/cros_healthd/public/cpp/service_connection.h" #include "chromeos/services/cros_healthd/public/cpp/service_connection.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd.mojom.h"
#include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h" #include "chromeos/services/cros_healthd/public/mojom/cros_healthd_probe.mojom.h"
...@@ -44,12 +43,6 @@ void CrosHealthdMetricsProvider::AsyncInit(base::OnceClosure done_callback) { ...@@ -44,12 +43,6 @@ void CrosHealthdMetricsProvider::AsyncInit(base::OnceClosure done_callback) {
init_callback_ = std::move(done_callback); init_callback_ = std::move(done_callback);
initialized_ = false; initialized_ = false;
if (!base::FeatureList::IsEnabled(::features::kUmaStorageDimensions)) {
DVLOG(1) << "cros_healthd metrics provider is not enabled";
std::move(init_callback_).Run();
return;
}
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&CrosHealthdMetricsProvider::OnProbeTimeout, base::BindOnce(&CrosHealthdMetricsProvider::OnProbeTimeout,
......
...@@ -10,10 +10,8 @@ ...@@ -10,10 +10,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/common/chrome_features.h"
#include "chromeos/dbus/cros_healthd/cros_healthd_client.h" #include "chromeos/dbus/cros_healthd/cros_healthd_client.h"
#include "chromeos/dbus/cros_healthd/fake_cros_healthd_client.h" #include "chromeos/dbus/cros_healthd/fake_cros_healthd_client.h"
#include "chromeos/services/cros_healthd/public/cpp/service_connection.h" #include "chromeos/services/cros_healthd/public/cpp/service_connection.h"
...@@ -42,7 +40,6 @@ constexpr auto kUmaPurpose = ...@@ -42,7 +40,6 @@ constexpr auto kUmaPurpose =
class CrosHealthdMetricsProviderTest : public testing::Test { class CrosHealthdMetricsProviderTest : public testing::Test {
public: public:
CrosHealthdMetricsProviderTest() { CrosHealthdMetricsProviderTest() {
scoped_feature_list_.InitAndEnableFeature(features::kUmaStorageDimensions);
chromeos::CrosHealthdClient::InitializeFake(); chromeos::CrosHealthdClient::InitializeFake();
chromeos::cros_healthd::mojom::NonRemovableBlockDeviceInfo storage_info; chromeos::cros_healthd::mojom::NonRemovableBlockDeviceInfo storage_info;
...@@ -82,7 +79,6 @@ class CrosHealthdMetricsProviderTest : public testing::Test { ...@@ -82,7 +79,6 @@ class CrosHealthdMetricsProviderTest : public testing::Test {
protected: protected:
base::test::TaskEnvironment task_environment_{ base::test::TaskEnvironment task_environment_{
base::test::TaskEnvironment::TimeSource::MOCK_TIME}; base::test::TaskEnvironment::TimeSource::MOCK_TIME};
base::test::ScopedFeatureList scoped_feature_list_;
}; };
TEST_F(CrosHealthdMetricsProviderTest, EndToEnd) { TEST_F(CrosHealthdMetricsProviderTest, EndToEnd) {
...@@ -135,24 +131,3 @@ TEST_F(CrosHealthdMetricsProviderTest, EndToEndTimeout) { ...@@ -135,24 +131,3 @@ TEST_F(CrosHealthdMetricsProviderTest, EndToEndTimeout) {
const auto& hardware = profile.hardware(); const auto& hardware = profile.hardware();
EXPECT_EQ(0, hardware.internal_storage_devices_size()); EXPECT_EQ(0, hardware.internal_storage_devices_size());
} }
TEST_F(CrosHealthdMetricsProviderTest, EndToEndNoFeature) {
scoped_feature_list_.Reset();
scoped_feature_list_.Init();
base::RunLoop run_loop;
CrosHealthdMetricsProvider provider;
provider.AsyncInit(base::BindOnce(
[](base::OnceClosure callback) { std::move(callback).Run(); },
run_loop.QuitClosure()));
run_loop.Run();
EXPECT_FALSE(provider.IsInitialized());
metrics::SystemProfileProto profile;
provider.ProvideSystemProfileMetrics(&profile);
const auto& hardware = profile.hardware();
EXPECT_EQ(0, hardware.internal_storage_devices_size());
}
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