Commit 9fc39b9b authored by Alex Clarke's avatar Alex Clarke Committed by Commit Bot

Move FieldTrialSynchronizer into content so it can be used by WebLayer

and other embedders.

There doesn't appear to be any existing tests for this functionality
and I'm not sure how to easily test it.

Bug: 1025612
Change-Id: I81354ff16a6bb9c9bc3a9ada99018ad1e2c82031
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1959034Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Alex Clarke <alexclarke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737363}
parent 7f4af748
......@@ -819,8 +819,6 @@ jumbo_static_library("browser") {
"metrics/chrome_metrics_services_manager_client.h",
"metrics/chrome_stability_metrics_provider.cc",
"metrics/chrome_stability_metrics_provider.h",
"metrics/field_trial_synchronizer.cc",
"metrics/field_trial_synchronizer.h",
"metrics/google_update_metrics_provider_win.cc",
"metrics/google_update_metrics_provider_win.h",
"metrics/https_engagement_metrics_provider.cc",
......
......@@ -77,7 +77,6 @@
#include "chrome/browser/metrics/chrome_feature_list_creator.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/metrics/expired_histograms_array.h"
#include "chrome/browser/metrics/field_trial_synchronizer.h"
#include "chrome/browser/metrics/renderer_uptime_tracker.h"
#include "chrome/browser/metrics/thread_watcher.h"
#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
......
......@@ -193,10 +193,6 @@ void ChromeFeatureListCreator::SetupFieldTrials() {
*base::CommandLine::ForCurrentProcess()),
std::move(feature_list), browser_field_trials_.get());
variations::InitCrashKeys();
// Initialize FieldTrialSynchronizer system, which is used to synchronize
// field trial state with child process.
field_trial_synchronizer_ = base::MakeRefCounted<FieldTrialSynchronizer>();
}
void ChromeFeatureListCreator::CreateMetricsServices() {
......
......@@ -12,7 +12,6 @@
#include "build/build_config.h"
#include "chrome/browser/chrome_browser_field_trials.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/metrics/field_trial_synchronizer.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/installer/util/master_preferences.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
......@@ -97,8 +96,6 @@ class ChromeFeatureListCreator {
std::unique_ptr<metrics_services_manager::MetricsServicesManager>
metrics_services_manager_;
scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
std::unique_ptr<ChromeBrowserFieldTrials> browser_field_trials_;
std::unique_ptr<policy::ChromeBrowserPolicyConnector>
......
......@@ -37,10 +37,4 @@ interface RendererConfiguration {
// Set the content setting rules stored by the renderer.
SetContentSettingRules(
content_settings.mojom.RendererContentSettingRules rules);
// Tells the renderer to create a FieldTrial, and by using a 100% probability
// for the FieldTrial, forces the FieldTrial to have assigned group name.
//
// See base/metrics/field_trial.h for more information.
SetFieldTrialGroup(string trial_name, string group_name);
};
......@@ -243,12 +243,6 @@ void ChromeRenderThreadObserver::SetContentSettingRules(
content_setting_rules_ = rules;
}
void ChromeRenderThreadObserver::SetFieldTrialGroup(
const std::string& trial_name,
const std::string& group_name) {
RenderThread::Get()->SetFieldTrialGroup(trial_name, group_name);
}
void ChromeRenderThreadObserver::OnRendererConfigurationAssociatedRequest(
mojo::PendingAssociatedReceiver<chrome::mojom::RendererConfiguration>
receiver) {
......
......@@ -115,9 +115,6 @@ class ChromeRenderThreadObserver : public content::RenderThreadObserver,
void SetConfiguration(chrome::mojom::DynamicParamsPtr params) override;
void SetContentSettingRules(
const RendererContentSettingRules& rules) override;
void SetFieldTrialGroup(const std::string& trial_name,
const std::string& group_name) override;
void OnRendererConfigurationAssociatedRequest(
mojo::PendingAssociatedReceiver<chrome::mojom::RendererConfiguration>
receiver);
......
......@@ -833,6 +833,8 @@ jumbo_source_set("browser") {
"download/save_types.h",
"field_trial_recorder.cc",
"field_trial_recorder.h",
"field_trial_synchronizer.cc",
"field_trial_synchronizer.h",
"file_system/browser_file_system_helper.cc",
"file_system/browser_file_system_helper.h",
"file_system/file_system_manager_impl.cc",
......
......@@ -42,3 +42,6 @@ per-file back_forward_cache_browsertest.cc=altimin@chromium.org
# Storage API dependencies.
per-file storage_partition*=file://storage/OWNERS
per-file quota_dispatcher_host*=file://storage/OWNERS
# Variations.
per-file field_trial_synchronizer.*=file://base/metrics/OWNERS
......@@ -65,6 +65,7 @@
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/compositor/viz_process_transport_factory.h"
#include "content/browser/download/save_file_manager.h"
#include "content/browser/field_trial_synchronizer.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
#include "content/browser/gpu/browser_gpu_client_delegate.h"
#include "content/browser/gpu/compositor_util.h"
......@@ -1248,6 +1249,8 @@ int BrowserMainLoop::BrowserThreadsStarted() {
HistogramSynchronizer::GetInstance();
field_trial_synchronizer_ = base::MakeRefCounted<FieldTrialSynchronizer>();
// cc assumes a single client name for metrics in a process, which is
// is inconsistent with single process mode where both the renderer and
// browser compositor run in the same process. In this case, avoid
......
......@@ -82,6 +82,7 @@ namespace content {
class BrowserMainParts;
class BrowserOnlineStateObserver;
class BrowserThreadImpl;
class FieldTrialSynchronizer;
class MediaKeysListenerManagerImpl;
class MediaStreamManager;
class SaveFileManager;
......@@ -340,6 +341,12 @@ class CONTENT_EXPORT BrowserMainLoop {
std::unique_ptr<mojo::core::ScopedIPCSupport> mojo_ipc_support_;
std::unique_ptr<MediaKeysListenerManagerImpl> media_keys_listener_manager_;
// The FieldTrialSynchronizer tells child processes when a trial gets
// activated. This is mostly an optimization, as a consequence if renderers
// know a trial is already active they don't need to send anything to the
// browser.
scoped_refptr<FieldTrialSynchronizer> field_trial_synchronizer_;
// |user_input_monitor_| has to outlive |audio_manager_|, so declared first.
std::unique_ptr<media::UserInputMonitor> user_input_monitor_;
......
......@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/field_trial_synchronizer.h"
#include "content/browser/field_trial_synchronizer.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/task/post_task.h"
#include "base/threading/thread.h"
#include "chrome/common/renderer_configuration.mojom.h"
#include "components/metrics/persistent_system_profile.h"
#include "content/common/renderer_variations_configuration.mojom.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
using content::BrowserThread;
namespace content {
namespace {
......@@ -44,17 +44,17 @@ void FieldTrialSynchronizer::NotifyAllRenderers(
AddFieldTrialToPersistentSystemProfile(field_trial_name, group_name);
for (content::RenderProcessHost::iterator it(
content::RenderProcessHost::AllHostsIterator());
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
auto* host = it.GetCurrentValue();
IPC::ChannelProxy* channel = host->GetChannel();
// channel might be null in tests.
if (host->IsInitializedAndNotDead() && channel) {
mojo::AssociatedRemote<chrome::mojom::RendererConfiguration>
renderer_configuration;
channel->GetRemoteAssociatedInterface(&renderer_configuration);
renderer_configuration->SetFieldTrialGroup(field_trial_name, group_name);
mojo::AssociatedRemote<mojom::RendererVariationsConfiguration>
renderer_variations_configuration;
channel->GetRemoteAssociatedInterface(&renderer_variations_configuration);
renderer_variations_configuration->SetFieldTrialGroup(field_trial_name,
group_name);
}
}
}
......@@ -67,7 +67,7 @@ void FieldTrialSynchronizer::OnFieldTrialGroupFinalized(
// case there are no child processes to notify yet. But we want to update the
// persistent system profile, thus the histogram data recorded in the reduced
// mode will be tagged to its corresponding field trial experiment.
if (!content::BrowserThread::IsThreadInitialized(BrowserThread::UI)) {
if (!BrowserThread::IsThreadInitialized(BrowserThread::UI)) {
AddFieldTrialToPersistentSystemProfile(field_trial_name, group_name);
return;
}
......@@ -81,3 +81,5 @@ void FieldTrialSynchronizer::OnFieldTrialGroupFinalized(
FieldTrialSynchronizer::~FieldTrialSynchronizer() {
base::FieldTrialList::RemoveObserver(this);
}
} // namespace content
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_METRICS_FIELD_TRIAL_SYNCHRONIZER_H_
#define CHROME_BROWSER_METRICS_FIELD_TRIAL_SYNCHRONIZER_H_
#ifndef CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_
#define CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_
#include <string>
#include <vector>
......@@ -12,6 +12,8 @@
#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial.h"
namespace content {
// This class is used by the browser process to communicate FieldTrial setting
// (field trial name and group) to any previously started renderers.
//
......@@ -55,4 +57,6 @@ class FieldTrialSynchronizer
DISALLOW_COPY_AND_ASSIGN(FieldTrialSynchronizer);
};
#endif // CHROME_BROWSER_METRICS_FIELD_TRIAL_SYNCHRONIZER_H_
} // namespace content
#endif // CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_
......@@ -474,6 +474,7 @@ mojom("mojo_bindings") {
"render_message_filter.mojom",
"renderer.mojom",
"renderer_host.mojom",
"renderer_variations_configuration.mojom",
"widget.mojom",
]
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module content.mojom;
// Configures the renderer.
interface RendererVariationsConfiguration {
// Tells the renderer to create a FieldTrial, and by using a 100% probability
// for the FieldTrial, forces the FieldTrial to have assigned group name.
//
// See base/metrics/field_trial.h for more information.
SetFieldTrialGroup(string trial_name, string group_name);
};
......@@ -291,6 +291,8 @@ target(link_target_type, "renderer") {
"top_level_blame_context.h",
"v8_value_converter_impl.cc",
"v8_value_converter_impl.h",
"variations_render_thread_observer.cc",
"variations_render_thread_observer.h",
"web_ui_extension.cc",
"web_ui_extension.h",
"web_ui_extension_data.cc",
......
......@@ -90,6 +90,7 @@
#include "content/renderer/render_view_impl.h"
#include "content/renderer/renderer_blink_platform_impl.h"
#include "content/renderer/service_worker/service_worker_context_client.h"
#include "content/renderer/variations_render_thread_observer.h"
#include "content/renderer/worker/embedded_shared_worker_stub.h"
#include "content/renderer/worker/worker_thread_registry.h"
#include "device/gamepad/public/cpp/gamepads.h"
......@@ -774,6 +775,9 @@ void RenderThreadImpl::Init() {
compositing_mode_reporter_->AddCompositingModeWatcher(
compositing_mode_watcher_receiver_.BindNewPipeAndPassRemote());
}
variations_observer_ = std::make_unique<VariationsRenderThreadObserver>();
AddObserver(variations_observer_.get());
}
RenderThreadImpl::~RenderThreadImpl() {
......
......@@ -105,6 +105,7 @@ class LowMemoryModeController;
class RenderThreadObserver;
class RendererBlinkPlatformImpl;
class ResourceDispatcher;
class VariationsRenderThreadObserver;
#if defined(OS_ANDROID)
class StreamTextureFactory;
......@@ -612,6 +613,8 @@ class CONTENT_EXPORT RenderThreadImpl
std::unique_ptr<viz::Gpu> gpu_;
std::unique_ptr<VariationsRenderThreadObserver> variations_observer_;
scoped_refptr<base::SingleThreadTaskRunner>
main_thread_compositor_task_runner_;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/variations_render_thread_observer.h"
#include "content/public/renderer/render_thread.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
namespace content {
VariationsRenderThreadObserver::VariationsRenderThreadObserver() = default;
VariationsRenderThreadObserver::~VariationsRenderThreadObserver() = default;
void VariationsRenderThreadObserver::RegisterMojoInterfaces(
blink::AssociatedInterfaceRegistry* associated_interfaces) {
associated_interfaces->AddInterface(base::BindRepeating(
&VariationsRenderThreadObserver::OnRendererConfigurationAssociatedRequest,
base::Unretained(this)));
}
void VariationsRenderThreadObserver::UnregisterMojoInterfaces(
blink::AssociatedInterfaceRegistry* associated_interfaces) {
associated_interfaces->RemoveInterface(
mojom::RendererVariationsConfiguration::Name_);
}
void VariationsRenderThreadObserver::SetFieldTrialGroup(
const std::string& trial_name,
const std::string& group_name) {
content::RenderThread::Get()->SetFieldTrialGroup(trial_name, group_name);
}
void VariationsRenderThreadObserver::OnRendererConfigurationAssociatedRequest(
mojo::PendingAssociatedReceiver<mojom::RendererVariationsConfiguration>
receiver) {
renderer_configuration_receiver_.reset();
renderer_configuration_receiver_.Bind(std::move(receiver));
}
} // namespace content
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_VARIATIONS_RENDER_THREAD_OBSERVER_H_
#define CONTENT_RENDERER_VARIATIONS_RENDER_THREAD_OBSERVER_H_
#include "base/macros.h"
#include "content/common/renderer_variations_configuration.mojom.h"
#include "content/public/renderer/render_thread_observer.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace content {
// This is the renderer side of the FieldTrialSynchronizer which applies
// field trial group settings.
class VariationsRenderThreadObserver
: public content::RenderThreadObserver,
public mojom::RendererVariationsConfiguration {
public:
VariationsRenderThreadObserver();
~VariationsRenderThreadObserver() override;
// content::RenderThreadObserver:
void RegisterMojoInterfaces(
blink::AssociatedInterfaceRegistry* associated_interfaces) override;
void UnregisterMojoInterfaces(
blink::AssociatedInterfaceRegistry* associated_interfaces) override;
// content::mojom::RendererConfiguration:
void SetFieldTrialGroup(const std::string& trial_name,
const std::string& group_name) override;
private:
mojo::AssociatedReceiver<mojom::RendererVariationsConfiguration>
renderer_configuration_receiver_{this};
void OnRendererConfigurationAssociatedRequest(
mojo::PendingAssociatedReceiver<mojom::RendererVariationsConfiguration>
receiver);
DISALLOW_COPY_AND_ASSIGN(VariationsRenderThreadObserver);
};
} // namespace content
#endif // CONTENT_RENDERER_VARIATIONS_RENDER_THREAD_OBSERVER_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