summaryrefslogtreecommitdiffstats
path: root/components/metrics
diff options
context:
space:
mode:
authorasvitkine <asvitkine@chromium.org>2014-10-31 14:59:57 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-31 22:00:18 +0000
commite0dbdbe3aa7dce4dda9e9acb20325d8476003fa8 (patch)
tree538bbae51dc2dd71e8a8c50755cbeb7d0da67c43 /components/metrics
parent403be2a2a9f71ef7be26dd083d058732577a7ad3 (diff)
downloadchromium_src-e0dbdbe3aa7dce4dda9e9acb20325d8476003fa8.zip
chromium_src-e0dbdbe3aa7dce4dda9e9acb20325d8476003fa8.tar.gz
chromium_src-e0dbdbe3aa7dce4dda9e9acb20325d8476003fa8.tar.bz2
Plumbing for variations headers from synthetic field trials.
BUG=428055 Review URL: https://codereview.chromium.org/688973004 Cr-Commit-Position: refs/heads/master@{#302331}
Diffstat (limited to 'components/metrics')
-rw-r--r--components/metrics/metrics_service.cc19
-rw-r--r--components/metrics/metrics_service.h24
2 files changed, 43 insertions, 0 deletions
diff --git a/components/metrics/metrics_service.cc b/components/metrics/metrics_service.cc
index 4db3bb5..4fa2e75 100644
--- a/components/metrics/metrics_service.cc
+++ b/components/metrics/metrics_service.cc
@@ -1138,6 +1138,18 @@ bool MetricsService::UmaMetricsProperlyShutdown() {
return clean_shutdown_status_ == CLEANLY_SHUTDOWN;
}
+void MetricsService::AddSyntheticTrialObserver(
+ SyntheticTrialObserver* observer) {
+ synthetic_trial_observer_list_.AddObserver(observer);
+ if (!synthetic_trial_groups_.empty())
+ observer->OnSyntheticTrialsChanged(synthetic_trial_groups_);
+}
+
+void MetricsService::RemoveSyntheticTrialObserver(
+ SyntheticTrialObserver* observer) {
+ synthetic_trial_observer_list_.RemoveObserver(observer);
+}
+
void MetricsService::RegisterSyntheticFieldTrial(
const SyntheticTrialGroup& trial) {
for (size_t i = 0; i < synthetic_trial_groups_.size(); ++i) {
@@ -1145,6 +1157,7 @@ void MetricsService::RegisterSyntheticFieldTrial(
if (synthetic_trial_groups_[i].id.group != trial.id.group) {
synthetic_trial_groups_[i].id.group = trial.id.group;
synthetic_trial_groups_[i].start_time = base::TimeTicks::Now();
+ NotifySyntheticTrialObservers();
}
return;
}
@@ -1153,6 +1166,7 @@ void MetricsService::RegisterSyntheticFieldTrial(
SyntheticTrialGroup trial_group = trial;
trial_group.start_time = base::TimeTicks::Now();
synthetic_trial_groups_.push_back(trial_group);
+ NotifySyntheticTrialObservers();
}
void MetricsService::RegisterMetricsProvider(
@@ -1166,6 +1180,11 @@ void MetricsService::CheckForClonedInstall(
state_manager_->CheckForClonedInstall(task_runner);
}
+void MetricsService::NotifySyntheticTrialObservers() {
+ FOR_EACH_OBSERVER(SyntheticTrialObserver, synthetic_trial_observer_list_,
+ OnSyntheticTrialsChanged(synthetic_trial_groups_));
+}
+
void MetricsService::GetCurrentSyntheticFieldTrials(
std::vector<variations::ActiveGroupId>* synthetic_trials) {
DCHECK(synthetic_trials);
diff --git a/components/metrics/metrics_service.h b/components/metrics/metrics_service.h
index eae44f3..19794ea 100644
--- a/components/metrics/metrics_service.h
+++ b/components/metrics/metrics_service.h
@@ -21,6 +21,7 @@
#include "base/metrics/histogram_flattener.h"
#include "base/metrics/histogram_snapshot_manager.h"
#include "base/metrics/user_metrics.h"
+#include "base/observer_list.h"
#include "base/time/time.h"
#include "components/metrics/clean_exit_beacon.h"
#include "components/metrics/metrics_log.h"
@@ -76,6 +77,17 @@ struct SyntheticTrialGroup {
SyntheticTrialGroup(uint32 trial, uint32 group);
};
+// Interface class to observe changes to synthetic trials in MetricsService.
+class SyntheticTrialObserver {
+ public:
+ // Called when the list of synthetic field trial groups has changed.
+ virtual void OnSyntheticTrialsChanged(
+ const std::vector<SyntheticTrialGroup>& groups) = 0;
+
+ protected:
+ virtual ~SyntheticTrialObserver() {}
+};
+
// See metrics_service.cc for a detailed description.
class MetricsService : public base::HistogramFlattener {
public:
@@ -211,6 +223,12 @@ class MetricsService : public base::HistogramFlattener {
// To use this method, SyntheticTrialGroup should friend your class.
void RegisterSyntheticFieldTrial(const SyntheticTrialGroup& trial_group);
+ // Adds an observer to be notified when the synthetic trials list changes.
+ void AddSyntheticTrialObserver(SyntheticTrialObserver* observer);
+
+ // Removes an existing observer of synthetic trials list changes.
+ void RemoveSyntheticTrialObserver(SyntheticTrialObserver* observer);
+
// Register the specified |provider| to provide additional metrics into the
// UMA log. Should be called during MetricsService initialization only.
void RegisterMetricsProvider(scoped_ptr<MetricsProvider> provider);
@@ -358,6 +376,9 @@ class MetricsService : public base::HistogramFlattener {
// Sets the value of the specified path in prefs and schedules a save.
void RecordBooleanPrefValue(const char* path, bool value);
+ // Notifies observers on a synthetic trial list change.
+ void NotifySyntheticTrialObservers();
+
// Returns a list of synthetic field trials that were active for the entire
// duration of the current log.
void GetCurrentSyntheticFieldTrials(
@@ -447,6 +468,9 @@ class MetricsService : public base::HistogramFlattener {
// Field trial groups that map to Chrome configuration states.
SyntheticTrialGroups synthetic_trial_groups_;
+ // List of observers of |synthetic_trial_groups_| changes.
+ ObserverList<SyntheticTrialObserver> synthetic_trial_observer_list_;
+
// Execution phase the browser is in.
static ExecutionPhase execution_phase_;