| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/instant/instant_field_trial.h" | 5 #include "chrome/browser/instant/instant_field_trial.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 8 #include "chrome/browser/metrics/metrics_service.h" | 9 #include "chrome/browser/metrics/metrics_service.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 // Field trial IDs of the control and experiment groups. Though they are not | 17 // Field trial IDs of the control and experiment groups. Though they are not |
| 16 // literally "const", they are set only once, in Activate() below. | 18 // literally "const", they are set only once, in Activate() below. |
| 17 int g_control_group_id_1 = 0; | 19 int g_control_group_id_1 = 0; |
| 18 int g_control_group_id_2 = 0; | 20 int g_control_group_id_2 = 0; |
| 19 int g_experiment_group_id_1 = 0; | 21 int g_experiment_group_id_1 = 0; |
| 20 int g_experiment_group_id_2 = 0; | 22 int g_experiment_group_id_2 = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 trial->UseOneTimeRandomization(); | 34 trial->UseOneTimeRandomization(); |
| 33 | 35 |
| 34 g_control_group_id_1 = trial->AppendGroup("InstantControl1", 450); // 45% | 36 g_control_group_id_1 = trial->AppendGroup("InstantControl1", 450); // 45% |
| 35 g_control_group_id_2 = trial->AppendGroup("InstantControl2", 450); // 45% | 37 g_control_group_id_2 = trial->AppendGroup("InstantControl2", 450); // 45% |
| 36 g_experiment_group_id_1 = trial->AppendGroup("InstantExperiment1", 50); // 5% | 38 g_experiment_group_id_1 = trial->AppendGroup("InstantExperiment1", 50); // 5% |
| 37 g_experiment_group_id_2 = trial->AppendGroup("InstantExperiment2", 50); // 5% | 39 g_experiment_group_id_2 = trial->AppendGroup("InstantExperiment2", 50); // 5% |
| 38 } | 40 } |
| 39 | 41 |
| 40 // static | 42 // static |
| 41 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { | 43 InstantFieldTrial::Group InstantFieldTrial::GetGroup(Profile* profile) { |
| 44 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 45 if (command_line->HasSwitch(switches::kInstantFieldTrial)) { |
| 46 std::string switch_value = |
| 47 command_line->GetSwitchValueASCII(switches::kInstantFieldTrial); |
| 48 if (switch_value == switches::kInstantFieldTrialInstant) |
| 49 return EXPERIMENT1; |
| 50 else |
| 51 return INACTIVE; |
| 52 } |
| 53 |
| 42 if (!profile || profile->IsOffTheRecord()) | 54 if (!profile || profile->IsOffTheRecord()) |
| 43 return INACTIVE; | 55 return INACTIVE; |
| 44 | 56 |
| 45 const PrefService* prefs = profile->GetPrefs(); | 57 const PrefService* prefs = profile->GetPrefs(); |
| 46 if (!prefs || | 58 if (!prefs || |
| 47 !MetricsServiceHelper::IsMetricsReportingEnabled() || | 59 !MetricsServiceHelper::IsMetricsReportingEnabled() || |
| 48 !prefs->GetBoolean(prefs::kSearchSuggestEnabled) || | 60 !prefs->GetBoolean(prefs::kSearchSuggestEnabled) || |
| 49 prefs->GetBoolean(prefs::kInstantEnabledOnce) || | 61 prefs->GetBoolean(prefs::kInstantEnabledOnce) || |
| 50 prefs->IsManagedPreference(prefs::kInstantEnabled)) { | 62 prefs->IsManagedPreference(prefs::kInstantEnabled)) { |
| 51 return INACTIVE; | 63 return INACTIVE; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 switch (GetGroup(profile)) { | 101 switch (GetGroup(profile)) { |
| 90 case INACTIVE: return std::string(); | 102 case INACTIVE: return std::string(); |
| 91 case CONTROL1: return "ix=c1&"; | 103 case CONTROL1: return "ix=c1&"; |
| 92 case CONTROL2: return "ix=c2&"; | 104 case CONTROL2: return "ix=c2&"; |
| 93 case EXPERIMENT1: return "ix=e1&"; | 105 case EXPERIMENT1: return "ix=e1&"; |
| 94 case EXPERIMENT2: return "ix=e2&"; | 106 case EXPERIMENT2: return "ix=e2&"; |
| 95 } | 107 } |
| 96 NOTREACHED(); | 108 NOTREACHED(); |
| 97 return std::string(); | 109 return std::string(); |
| 98 } | 110 } |
| OLD | NEW |