Commit 76cb81a0 authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Add synthetic field trial for Optimization Guide-enabled users

Bug: 1115698
Change-Id: I03e7514d22c7a4f8592793de1e69202b0356565a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352038Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarMichael Crouse <mcrouse@chromium.org>
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797487}
parent 4b853182
...@@ -120,6 +120,7 @@ class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor { ...@@ -120,6 +120,7 @@ class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor {
friend class NavigationMetricsRecorder; friend class NavigationMetricsRecorder;
friend class ChromeBrowserMainExtraPartsGpu; friend class ChromeBrowserMainExtraPartsGpu;
friend class Browser; friend class Browser;
friend class OptimizationGuideKeyedService;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
friend class ChromeCameraAppUIDelegate; friend class ChromeCameraAppUIDelegate;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/optimization_guide/optimization_guide_hints_manager.h" #include "chrome/browser/optimization_guide/optimization_guide_hints_manager.h"
#include "chrome/browser/optimization_guide/optimization_guide_navigation_data.h" #include "chrome/browser/optimization_guide/optimization_guide_navigation_data.h"
#include "chrome/browser/optimization_guide/optimization_guide_session_statistic.h" #include "chrome/browser/optimization_guide/optimization_guide_session_statistic.h"
...@@ -111,8 +112,12 @@ void OptimizationGuideKeyedService::Initialize( ...@@ -111,8 +112,12 @@ void OptimizationGuideKeyedService::Initialize(
Profile* profile = Profile::FromBrowserContext(browser_context_); Profile* profile = Profile::FromBrowserContext(browser_context_);
top_host_provider_ = GetTopHostProviderIfUserPermitted(browser_context_); top_host_provider_ = GetTopHostProviderIfUserPermitted(browser_context_);
bool optimization_guide_fetching_enabled = top_host_provider_ != nullptr;
UMA_HISTOGRAM_BOOLEAN("OptimizationGuide.RemoteFetchingEnabled", UMA_HISTOGRAM_BOOLEAN("OptimizationGuide.RemoteFetchingEnabled",
top_host_provider_ != nullptr); optimization_guide_fetching_enabled);
ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
"SyntheticOptimizationGuideRemoteFetching",
optimization_guide_fetching_enabled ? "Enabled" : "Disabled");
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory = scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory =
content::BrowserContext::GetDefaultStoragePartition(profile) content::BrowserContext::GetDefaultStoragePartition(profile)
->GetURLLoaderFactoryForBrowserProcess(); ->GetURLLoaderFactoryForBrowserProcess();
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/previews/core/previews_switches.h" #include "components/previews/core/previews_switches.h"
#include "components/ukm/test_ukm_recorder.h" #include "components/ukm/test_ukm_recorder.h"
#include "components/variations/active_field_trials.h"
#include "components/variations/hashing.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.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"
...@@ -242,6 +244,19 @@ class OptimizationGuideKeyedServiceBrowserTest ...@@ -242,6 +244,19 @@ class OptimizationGuideKeyedServiceBrowserTest
consumer_->set_callback(std::move(callback)); consumer_->set_callback(std::move(callback));
} }
// Returns whether the synthetic trial |trial_name| has been logged and is in
// the |trial_group| for the trial.
bool IsInSyntheticTrialGroup(const std::string& trial_name,
const std::string& trial_group) {
std::vector<std::string> synthetic_trials;
variations::GetSyntheticTrialGroupIdsAsString(&synthetic_trials);
std::string expected_entry =
base::StringPrintf("%x-%x", variations::HashName(trial_name),
variations::HashName(trial_group));
return std::find(synthetic_trials.begin(), synthetic_trials.end(),
expected_entry) != synthetic_trials.end();
}
// Returns the last decision from the CanApplyOptimization() method seen by // Returns the last decision from the CanApplyOptimization() method seen by
// the consumer of the OptimizationGuideKeyedService. // the consumer of the OptimizationGuideKeyedService.
optimization_guide::OptimizationGuideDecision optimization_guide::OptimizationGuideDecision
...@@ -301,6 +316,8 @@ IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceBrowserTest, ...@@ -301,6 +316,8 @@ IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceBrowserTest,
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
histogram_tester()->ExpectUniqueSample( histogram_tester()->ExpectUniqueSample(
"OptimizationGuide.RemoteFetchingEnabled", false, 1); "OptimizationGuide.RemoteFetchingEnabled", false, 1);
EXPECT_TRUE(IsInSyntheticTrialGroup(
"SyntheticOptimizationGuideRemoteFetching", "Disabled"));
#endif #endif
} }
...@@ -595,6 +612,8 @@ IN_PROC_BROWSER_TEST_F( ...@@ -595,6 +612,8 @@ IN_PROC_BROWSER_TEST_F(
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
histogram_tester()->ExpectUniqueSample( histogram_tester()->ExpectUniqueSample(
"OptimizationGuide.RemoteFetchingEnabled", true, 1); "OptimizationGuide.RemoteFetchingEnabled", true, 1);
EXPECT_TRUE(IsInSyntheticTrialGroup(
"SyntheticOptimizationGuideRemoteFetching", "Enabled"));
#endif #endif
} }
...@@ -627,5 +646,7 @@ IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceCommandLineOverridesTest, ...@@ -627,5 +646,7 @@ IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceCommandLineOverridesTest,
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
histogram_tester()->ExpectUniqueSample( histogram_tester()->ExpectUniqueSample(
"OptimizationGuide.RemoteFetchingEnabled", true, 1); "OptimizationGuide.RemoteFetchingEnabled", true, 1);
EXPECT_TRUE(IsInSyntheticTrialGroup(
"SyntheticOptimizationGuideRemoteFetching", "Enabled"));
#endif #endif
} }
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