<commit_before>// Copyright (c) 2011 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 "chrome/browser/instant/instant_field_trial.h"

#include "base/metrics/field_trial.h"
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"

namespace {

// Field trial IDs of the control and experiment groups. Though they are not
// literally "const", they are set only once, in Activate() below.
int g_control_group_id_1 = 0;
int g_control_group_id_2 = 0;
int g_experiment_group_id_1 = 0;
int g_experiment_group_id_2 = 0;

}

// static
void InstantFieldTrial::Activate() {
  scoped_refptr<base::FieldTrial> trial(
      new base::FieldTrial("Instant", 1000, "InstantInactive", 2012, 1, 1));

  // One-time randomization is disabled if the user hasn't opted-in to UMA.
  if (!base::FieldTrialList::IsOneTimeRandomizationEnabled())
    return;
  trial->UseOneTimeRandomization();

  g_control_group_id_1 = trial->AppendGroup("InstantControl1", 495);
  g_control_group_id_2 = trial->AppendGroup("InstantControl2", 495);
  g_experiment_group_id_1 = trial->AppendGroup("InstantExperiment1", 5);
  g_experiment_group_id_2 = trial->AppendGroup("InstantExperiment2", 5);
}

// static
InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) {
  if (!profile || profile->IsOffTheRecord())
    return INACTIVE;

  const PrefService* prefs = profile->GetPrefs();
  if (!prefs ||
      !MetricsServiceHelper::IsMetricsReportingEnabled() ||
      !prefs->GetBoolean(prefs::kSearchSuggestEnabled) ||
      prefs->GetBoolean(prefs::kInstantEnabledOnce) ||
      prefs->IsManagedPreference(prefs::kInstantEnabled)) {
    return INACTIVE;
  }

  const int group = base::FieldTrialList::FindValue("Instant");

  if (group == base::FieldTrial::kNotFinalized ||
      group == base::FieldTrial::kDefaultGroupNumber) {
    return INACTIVE;
  }

  return group == g_control_group_id_1    ? CONTROL1 :<commit_msg>Revert 99335 - Lower Instant field trial percentage.<commit_after>// Copyright (c) 2011 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 "chrome/browser/instant/instant_field_trial.h"

#include "base/metrics/field_trial.h"
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"

namespace {

// Field trial IDs of the control and experiment groups. Though they are not
// literally "const", they are set only once, in Activate() below.
int g_control_group_id_1 = 0;
int g_control_group_id_2 = 0;
int g_experiment_group_id_1 = 0;
int g_experiment_group_id_2 = 0;

}

// static
void InstantFieldTrial::Activate() {
  scoped_refptr<base::FieldTrial> trial(
      new base::FieldTrial("Instant", 1000, "InstantInactive", 2012, 1, 1));

  // One-time randomization is disabled if the user hasn't opted-in to UMA.
  if (!base::FieldTrialList::IsOneTimeRandomizationEnabled())
    return;
  trial->UseOneTimeRandomization();

  g_control_group_id_1 = trial->AppendGroup("InstantControl1", 450);  // 45%
  g_control_group_id_2 = trial->AppendGroup("InstantControl2", 450);  // 45%
  g_experiment_group_id_1 = trial->AppendGroup("InstantExperiment1", 50);  // 5%
  g_experiment_group_id_2 = trial->AppendGroup("InstantExperiment2", 50);  // 5%
}

// static
InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) {
  if (!profile || profile->IsOffTheRecord())
    return INACTIVE;

  const PrefService* prefs = profile->GetPrefs();
  if (!prefs ||
      !MetricsServiceHelper::IsMetricsReportingEnabled() ||
      !prefs->GetBoolean(prefs::kSearchSuggestEnabled) ||
      prefs->GetBoolean(prefs::kInstantEnabledOnce) ||
      prefs->IsManagedPreference(prefs::kInstantEnabled)) {
    return INACTIVE;
  }

  const int group = base::FieldTrialList::FindValue("Instant");

  if (group == base::FieldTrial::kNotFinalized ||
      group == base::FieldTrial::kDefaultGroupNumber) {
    return INACTIVE;
  }

  return group == g_control_group_id_1    ? CONTROL1 :
{'fraction_non_alphanumeric': 0.12341113935752253, 'fraction_numerical': 0.021492951236422465, 'mean_word_length': 5.011111111111111, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2131054', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1384, 'n_words': 314}