OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "chrome/browser/metrics/metrics_service.h" | 9 #include "chrome/browser/metrics/metrics_service.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // 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 |
18 // literally "const", they are set only once, in Activate() below. See the .h | 18 // literally "const", they are set only once, in Activate() below. See the .h |
19 // file for what these groups represent. | 19 // file for what these groups represent. |
| 20 int g_inactive = -1; |
20 int g_instant = 0; | 21 int g_instant = 0; |
21 int g_suggest = 0; | 22 int g_suggest = 0; |
22 int g_hidden = 0; | 23 int g_hidden = 0; |
23 int g_silent = 0; | 24 int g_silent = 0; |
24 int g_control = 0; | 25 int g_control = 0; |
25 | 26 |
26 } | 27 } |
27 | 28 |
28 // static | 29 // static |
29 void InstantFieldTrial::Activate() { | 30 void InstantFieldTrial::Activate() { |
30 scoped_refptr<base::FieldTrial> trial( | 31 scoped_refptr<base::FieldTrial> trial( |
31 new base::FieldTrial("Instant", 1000, "Inactive", 2013, 7, 1)); | 32 base::FieldTrialList::GetFieldTrialInstance( |
| 33 "Instant", 1000, "Inactive", &g_inactive, 2013, 7, 1)); |
32 | 34 |
33 // Try to give the user a consistent experience, if possible. | 35 // Try to give the user a consistent experience, if possible. |
34 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) | 36 if (base::FieldTrialList::IsOneTimeRandomizationEnabled()) |
35 trial->UseOneTimeRandomization(); | 37 trial->UseOneTimeRandomization(); |
36 | 38 |
37 g_instant = trial->AppendGroup("Instant", 10); // 1% | 39 g_instant = trial->AppendGroup("Instant", 10); // 1% |
38 g_suggest = trial->AppendGroup("Suggest", 10); // 1% | 40 g_suggest = trial->AppendGroup("Suggest", 10); // 1% |
39 g_hidden = trial->AppendGroup("Hidden", 960); // 96% | 41 g_hidden = trial->AppendGroup("Hidden", 960); // 96% |
40 g_silent = trial->AppendGroup("Silent", 10); // 1% | 42 g_silent = trial->AppendGroup("Silent", 10); // 1% |
41 g_control = trial->AppendGroup("Control", 10); // 1% | 43 g_control = trial->AppendGroup("Control", 10); // 1% |
(...skipping 13 matching lines...) Expand all Loading... |
55 return HIDDEN; | 57 return HIDDEN; |
56 if (switch_value == switches::kInstantFieldTrialSilent) | 58 if (switch_value == switches::kInstantFieldTrialSilent) |
57 return SILENT; | 59 return SILENT; |
58 if (switch_value == switches::kInstantFieldTrialControl) | 60 if (switch_value == switches::kInstantFieldTrialControl) |
59 return CONTROL; | 61 return CONTROL; |
60 return INACTIVE; | 62 return INACTIVE; |
61 } | 63 } |
62 | 64 |
63 const int group = base::FieldTrialList::FindValue("Instant"); | 65 const int group = base::FieldTrialList::FindValue("Instant"); |
64 if (group == base::FieldTrial::kNotFinalized || | 66 if (group == base::FieldTrial::kNotFinalized || |
65 group == base::FieldTrial::kDefaultGroupNumber) { | 67 group == g_inactive) { |
66 return INACTIVE; | 68 return INACTIVE; |
67 } | 69 } |
68 | 70 |
69 const PrefService* prefs = profile ? profile->GetPrefs() : NULL; | 71 const PrefService* prefs = profile ? profile->GetPrefs() : NULL; |
70 if (!prefs || profile->IsOffTheRecord() || | 72 if (!prefs || profile->IsOffTheRecord() || |
71 prefs->GetBoolean(prefs::kInstantEnabledOnce) || | 73 prefs->GetBoolean(prefs::kInstantEnabledOnce) || |
72 !prefs->GetBoolean(prefs::kSearchSuggestEnabled) || | 74 !prefs->GetBoolean(prefs::kSearchSuggestEnabled) || |
73 prefs->IsManagedPreference(prefs::kInstantEnabled)) { | 75 prefs->IsManagedPreference(prefs::kInstantEnabled)) { |
74 return INACTIVE; | 76 return INACTIVE; |
75 } | 77 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 144 |
143 NOTREACHED(); | 145 NOTREACHED(); |
144 return std::string(); | 146 return std::string(); |
145 } | 147 } |
146 | 148 |
147 // static | 149 // static |
148 bool InstantFieldTrial::ShouldSetSuggestedText(Profile* profile) { | 150 bool InstantFieldTrial::ShouldSetSuggestedText(Profile* profile) { |
149 Group group = GetGroup(profile); | 151 Group group = GetGroup(profile); |
150 return group != HIDDEN && group != SILENT; | 152 return group != HIDDEN && group != SILENT; |
151 } | 153 } |
OLD | NEW |