0
Files
src/content/browser/field_trial_synchronizer.h
Dan Harrington 42d5c83e1a Revert^2 "Add code supporting new field-trial-internals page"
This reverts commit 269aa9d493.

Reason for revert: including fix for test

Original change's description:
> Revert "Add code supporting new field-trial-internals page"
>
> This reverts commit b8e462bc4b.
>
> Reason for revert: This CL is likely the cause of test failure CfmBrowserServiceTest.GetVariationsData on https://ci.chromium.org/ui/p/chromium/builders/ci/linux-cfm-rel starting from https://ci.chromium.org/ui/b/8763776059209925809. Error message: Expected equality of these values:
>   field_trial_states
>     Which is: "*Baz/Qux/Foo/Bar/"
>   states
>     Which is: "*Baz/Qux/Foo/Bar"
>
> Original change's description:
> > Add code supporting new field-trial-internals page
> >
> > This CL lays the groundwork for a future
> > field-trial-internals page, with the following changes:
> >
> > * Update base::FieldTrial to include an 'overridden' flag,
> >   which is used to change variation group hashes so
> >   overridden trial hashes are distinct.
> > * I pulled out code to build field trial strings
> >   into AppendFieldTrialGroupToString, to be reused. In some places, we
> >   were adding a trailing '/', and other places we weren't. Now we omit
> >   the trailing slash everywhere. We can still parse the string
> >   with or without the trailing slash.
> >
> > See go/field-trial-internals-dd for more information.
> >
> > Bug: b:284986126
> > Change-Id: I58b86c558cd7973bb6a493322353b52ebf9f619f
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4620752
> > Reviewed-by: Richard (Torne) Coles <torne@chromium.org>
> > Reviewed-by: Matt Menke <mmenke@chromium.org>
> > Reviewed-by: Mike Dougherty <michaeldo@chromium.org>
> > Reviewed-by: Robert Kaplow <rkaplow@chromium.org>
> > Commit-Queue: Dan H <harringtond@chromium.org>
> > Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
> > Reviewed-by: Erik Chen <erikchen@chromium.org>
> > Reviewed-by: Luc Nguyen <lucnguyen@google.com>
> > Cr-Commit-Position: refs/heads/main@{#1227624}
>
> Bug: b:284986126
> Change-Id: I18f84ccf307f6265da24b3603b82344e1bf42c20
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5052200
> Owners-Override: Maggie Cai <mxcai@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: Maggie Cai <mxcai@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1227726}

Bug: b:284986126
Change-Id: Id00f514233c08aa439caaa7f4d6bdaa6c5fc38d5
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5055166
Reviewed-by: Luc Nguyen <lucnguyen@google.com>
Reviewed-by: Erik Chen <erikchen@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: Paul Moy <pmoy@chromium.org>
Reviewed-by: Richard (Torne) Coles <torne@chromium.org>
Reviewed-by: Matt Menke <mmenke@chromium.org>
Reviewed-by: Robert Kaplow <rkaplow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1229416}
2023-11-27 18:10:16 +00:00

69 lines
2.7 KiB
C++

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_
#define CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_
#include <string>
#include <vector>
#include "base/metrics/field_trial.h"
#include "components/variations/variations_ids_provider.h"
namespace content {
class RenderProcessHost;
// This class is used by the browser process to communicate FieldTrial setting
// (field trial name and group) and Variation header to any previously started
// renderers.
//
// This class registers itself as an observer of FieldTrialList. FieldTrialList
// notifies this class by calling its OnFieldTrialGroupFinalized method when a
// group is selected (finalized) for a FieldTrial and OnFieldTrialGroupFinalized
// method sends the FieldTrial's name and the group to all renderer processes.
// Each renderer process creates the FieldTrial, and by using a 100% probability
// for the FieldTrial, forces the FieldTrial to have the same group string. This
// is mostly an optimization so that renderers don't send anything to the
// browser when they know that a trial is already active.
//
// This class also registers itself as a VariationsIdsProvider Observer and
// updates the renderers if the variations header changes.
class FieldTrialSynchronizer
: public base::FieldTrialList::Observer,
public variations::VariationsIdsProvider::Observer {
public:
// Creates the global FieldTrialSynchronizer instance for this process. After
// this is invoked, renderers are notified whenever a field trial group is
// finalized.
static void CreateInstance();
FieldTrialSynchronizer(const FieldTrialSynchronizer&) = delete;
FieldTrialSynchronizer& operator=(const FieldTrialSynchronizer&) = delete;
// FieldTrialList::Observer methods:
// This method is called by the FieldTrialList singleton when a trial's group
// is finalized. This method contacts all renderers (by calling
// NotifyAllRenderers) to create a FieldTrial that carries the randomly
// selected state from the browser process into all the renderer processes.
void OnFieldTrialGroupFinalized(const base::FieldTrial& trial,
const std::string& group_name) override;
// VariationsIdsProvider::Observer methods:
void VariationIdsHeaderUpdated() override;
// Sends the current variations header to |host|'s renderer.
static void UpdateRendererVariationsHeader(RenderProcessHost* host);
private:
FieldTrialSynchronizer();
~FieldTrialSynchronizer() override;
static void NotifyAllRenderersOfVariationsHeader();
};
} // namespace content
#endif // CONTENT_BROWSER_FIELD_TRIAL_SYNCHRONIZER_H_