Adding synthetic field trial for the trial name DataReductionProxyEnabled and...

Adding synthetic field trial for the trial name DataReductionProxyEnabled and groups |true| and |false| that indicate whether the data reduction proxy proxy is turned on or not. The field trial was added so we can see if the data reduction proxy is turned on or not for PLT.PT_*_DataReductionProxy histograms, but can be viewed on any histogram.

BUG=394125

Review URL: https://codereview.chromium.org/421653005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287133 0039d316-1c4b-4281-b951-d872f2087c98
parent 35d8d55e
......@@ -46,3 +46,12 @@ bool ChromeMetricsServiceAccessor::IsCrashReportingEnabled() {
return false;
#endif
}
// static
bool ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
const std::string& trial, const std::string& group) {
return MetricsServiceAccessor::RegisterSyntheticFieldTrial(
g_browser_process->metrics_service(),
trial,
group);
}
......@@ -40,6 +40,7 @@ class ChromeMetricsServiceAccessor : public MetricsServiceAccessor {
friend class ::ChromeBrowserMetricsServiceObserver;
friend class ChromeRenderMessageFilter;
friend class ::CrashesDOMHandler;
friend class DataReductionProxyChromeSettings;
friend class extensions::ExtensionDownloader;
friend class extensions::ManifestFetchData;
friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction;
......@@ -62,6 +63,16 @@ class ChromeMetricsServiceAccessor : public MetricsServiceAccessor {
// IsMetricsReportingEnabled for desktop Chrome.
static bool IsCrashReportingEnabled();
// Registers a field trial name and group to be used to annotate a UMA report
// with a particular Chrome configuration state. A UMA report will be
// annotated with this trial group if and only if all events in the report
// were created after the trial is registered. Only one group name may be
// registered at a time for a given trial name. Only the last group name that
// is registered for a given trial name will be recorded. The values passed
// in must not correspond to any real field trial in the code.
static bool RegisterSyntheticFieldTrial(const std::string& trial,
const std::string& group);
DISALLOW_IMPLICIT_CONSTRUCTORS(ChromeMetricsServiceAccessor);
};
......
......@@ -7,6 +7,7 @@
#include "chrome/browser/browser_process.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics/metrics_service_observer.h"
#include "components/variations/metrics_util.h"
// static
void MetricsServiceAccessor::AddMetricsServiceObserver(
......@@ -22,3 +23,17 @@ void MetricsServiceAccessor::RemoveMetricsServiceObserver(
if (metrics_service)
metrics_service->RemoveObserver(observer);
}
// static
bool MetricsServiceAccessor::RegisterSyntheticFieldTrial(
MetricsService* metrics_service,
const std::string& trial,
const std::string& group) {
if (!metrics_service)
return false;
SyntheticTrialGroup trial_group(metrics::HashName(trial),
metrics::HashName(group));
metrics_service->RegisterSyntheticFieldTrial(trial_group);
return true;
}
......@@ -5,8 +5,11 @@
#ifndef CHROME_BROWSER_METRICS_METRICS_SERVICE_ACCESSOR_H_
#define CHROME_BROWSER_METRICS_METRICS_SERVICE_ACCESSOR_H_
#include <string>
#include "base/macros.h"
class MetricsService;
class MetricsServiceObserver;
// This class limits and documents access to metrics service helper methods.
......@@ -23,6 +26,17 @@ class MetricsServiceAccessor {
static void AddMetricsServiceObserver(MetricsServiceObserver* observer);
static void RemoveMetricsServiceObserver(MetricsServiceObserver* observer);
// Registers a field trial name and group to be used to annotate a UMA report
// with a particular Chrome configuration state. A UMA report will be
// annotated with this trial group if and only if all events in the report
// were created after the trial is registered. Only one group name may be
// registered at a time for a given trial name. Only the last group name that
// is registered for a given trial name will be recorded. The values passed
// in must not correspond to any real field trial in the code.
static bool RegisterSyntheticFieldTrial(MetricsService* metrics_service,
const std::string& trial,
const std::string& group);
private:
DISALLOW_COPY_AND_ASSIGN(MetricsServiceAccessor);
};
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -34,7 +35,17 @@ void DataReductionProxyChromeSettings::InitDataReductionProxySettings(
prefs,
g_browser_process->local_state(),
ProfileManager::GetActiveUserProfile()->GetRequestContext());
DataReductionProxySettings::SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial,
base::Unretained(this)));
SetDataReductionProxyAlternativeEnabled(
DataReductionProxyParams::IsIncludedInAlternativeFieldTrial());
}
void DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial(
bool data_reduction_proxy_enabled) {
ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
"DataReductionProxyEnabled",
data_reduction_proxy_enabled ? "true" : "false");
}
......@@ -33,6 +33,10 @@ class DataReductionProxyChromeSettings
virtual void InitDataReductionProxySettings(Profile* profile);
private:
// Registers the DataReductionProxyEnabled synthetic field trial with
// the group |data_reduction_proxy_enabled|.
void RegisterSyntheticFieldTrial(bool data_reduction_proxy_enabled);
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyChromeSettings);
};
......
......@@ -131,6 +131,7 @@ void DataReductionProxySettings::InitDataReductionProxySettings(
url_request_context_getter_ = url_request_context_getter;
InitPrefMembers();
RecordDataReductionInit();
// Disable the proxy if it is not allowed to be used.
if (!params_->allowed())
return;
......@@ -153,6 +154,12 @@ void DataReductionProxySettings::InitDataReductionProxySettings(
SetProxyConfigurator(configurator.Pass());
}
void DataReductionProxySettings::SetOnDataReductionEnabledCallback(
const base::Callback<void(bool)>& on_data_reduction_proxy_enabled) {
on_data_reduction_proxy_enabled_ = on_data_reduction_proxy_enabled;
on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled());
}
void DataReductionProxySettings::SetProxyConfigurator(
scoped_ptr<DataReductionProxyConfigurator> configurator) {
DCHECK(configurator);
......@@ -348,6 +355,8 @@ void DataReductionProxySettings::OnIPAddressChanged() {
void DataReductionProxySettings::OnProxyEnabledPrefChange() {
DCHECK(thread_checker_.CalledOnValidThread());
if (!on_data_reduction_proxy_enabled_.is_null())
on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled());
if (!params_->allowed())
return;
MaybeActivateDataReductionProxy(false);
......
......@@ -8,6 +8,7 @@
#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
......@@ -121,6 +122,11 @@ class DataReductionProxySettings
net::URLRequestContextGetter* url_request_context_getter,
scoped_ptr<DataReductionProxyConfigurator> configurator);
// Sets the |on_data_reduction_proxy_enabled_| callback and runs to register
// the DataReductionProxyEnabled synthetic field trial.
void SetOnDataReductionEnabledCallback(
const base::Callback<void(bool)>& on_data_reduction_proxy_enabled);
// Sets the logic the embedder uses to set the networking configuration that
// causes traffic to be proxied.
void SetProxyConfigurator(
......@@ -310,6 +316,8 @@ class DataReductionProxySettings
net::URLRequestContextGetter* url_request_context_getter_;
base::Callback<void(bool)> on_data_reduction_proxy_enabled_;
scoped_ptr<DataReductionProxyConfigurator> configurator_;
base::ThreadChecker thread_checker_;
......
......@@ -4,6 +4,7 @@
#include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/prefs/pref_registry_simple.h"
......@@ -299,12 +300,19 @@ void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
settings_->SetProxyConfigurator(configurator.Pass());
scoped_refptr<net::TestURLRequestContextGetter> request_context =
new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
settings_->InitDataReductionProxySettings(&pref_service_,
&pref_service_,
request_context.get());
settings_->InitDataReductionProxySettings(
&pref_service_,
&pref_service_,
request_context.get());
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
RegisterSyntheticFieldTrialCallback,
base::Unretained(this)));
base::MessageLoop::current()->RunUntilIdle();
CheckProxyConfigs(enabled_at_startup, false, false);
EXPECT_EQ(enabled_at_startup, proxy_enabled_);
}
} // namespace data_reduction_proxy
......@@ -157,11 +157,15 @@ class DataReductionProxySettingsTestBase : public testing::Test {
bool expected_fallback_restricted);
void CheckOnPrefChange(bool enabled, bool expected_enabled, bool managed);
void CheckInitDataReductionProxy(bool enabled_at_startup);
void RegisterSyntheticFieldTrialCallback(bool proxy_enabled) {
proxy_enabled_ = proxy_enabled;
}
TestingPrefServiceSimple pref_service_;
scoped_ptr<DataReductionProxySettings> settings_;
scoped_ptr<TestDataReductionProxyParams> expected_params_;
base::Time last_update_time_;
bool proxy_enabled_;
};
// Test implementations should be subclasses of an instantiation of this
......
......@@ -420,9 +420,14 @@ TEST_F(DataReductionProxySettingsTest, CheckInitMetricsWhenNotAllowed) {
settings_->SetProxyConfigurator(configurator.Pass());
scoped_refptr<net::TestURLRequestContextGetter> request_context =
new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
settings_->InitDataReductionProxySettings(&pref_service_,
&pref_service_,
request_context.get());
settings_->InitDataReductionProxySettings(
&pref_service_,
&pref_service_,
request_context.get());
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
RegisterSyntheticFieldTrialCallback,
base::Unretained(this)));
base::MessageLoop::current()->RunUntilIdle();
}
......
......@@ -67,6 +67,8 @@ struct SyntheticTrialGroup {
base::TimeTicks start_time;
private:
// Synthetic field trial users:
friend class MetricsServiceAccessor;
friend class MetricsService;
FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, RegisterSyntheticTrial);
......
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