OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/profile_resetter/automatic_profile_resetter.h" | 5 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 | 51 |
52 // Helpers ------------------------------------------------------------------- | 52 // Helpers ------------------------------------------------------------------- |
53 | 53 |
54 namespace { | 54 namespace { |
55 | 55 |
56 // Name constants for the field trial behind which we enable this feature. | 56 // Name constants for the field trial behind which we enable this feature. |
57 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; | 57 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; |
58 const char kAutomaticProfileResetStudyDryRunGroupName[] = "DryRun"; | 58 const char kAutomaticProfileResetStudyDryRunGroupName[] = "DryRun"; |
59 const char kAutomaticProfileResetStudyEnabledGroupName[] = "Enabled"; | 59 const char kAutomaticProfileResetStudyEnabledGroupName[] = "Enabled"; |
| 60 #if defined(GOOGLE_CHROME_BUILD) |
60 const char kAutomaticProfileResetStudyProgramParameterName[] = "program"; | 61 const char kAutomaticProfileResetStudyProgramParameterName[] = "program"; |
61 const char kAutomaticProfileResetStudyHashSeedParameterName[] = "hash_seed"; | 62 const char kAutomaticProfileResetStudyHashSeedParameterName[] = "hash_seed"; |
| 63 #endif |
62 | 64 |
63 // How long to wait after start-up before unleashing the evaluation flow. | 65 // How long to wait after start-up before unleashing the evaluation flow. |
64 const int64 kEvaluationFlowDelayInSeconds = 55; | 66 const int64 kEvaluationFlowDelayInSeconds = 55; |
65 | 67 |
66 // Keys used in the input dictionary of the program. | 68 // Keys used in the input dictionary of the program. |
67 const char kDefaultSearchProviderKey[] = "default_search_provider"; | 69 const char kDefaultSearchProviderKey[] = "default_search_provider"; |
68 const char kDefaultSearchProviderIsUserControlledKey[] = | 70 const char kDefaultSearchProviderIsUserControlledKey[] = |
69 "default_search_provider_iuc"; | 71 "default_search_provider_iuc"; |
70 const char kLoadedModuleDigestsKey[] = "loaded_modules"; | 72 const char kLoadedModuleDigestsKey[] = "loaded_modules"; |
71 const char kLocalStateKey[] = "local_state"; | 73 const char kLocalStateKey[] = "local_state"; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 kAutomaticProfileResetStudyDryRunGroupName, true); | 128 kAutomaticProfileResetStudyDryRunGroupName, true); |
127 } | 129 } |
128 | 130 |
129 // Returns whether or not a live-run shall be performed. | 131 // Returns whether or not a live-run shall be performed. |
130 bool ShouldPerformLiveRun() { | 132 bool ShouldPerformLiveRun() { |
131 return StartsWithASCII( | 133 return StartsWithASCII( |
132 base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName), | 134 base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName), |
133 kAutomaticProfileResetStudyEnabledGroupName, true); | 135 kAutomaticProfileResetStudyEnabledGroupName, true); |
134 } | 136 } |
135 | 137 |
136 // Returns whether or not the currently active experiment group prescribes the | 138 // If the currently active experiment group prescribes a |program| and |
137 // program and hash seed to use instead of the baked-in ones. | 139 // |hash_seed| to use instead of the baked-in ones, retrieves those and returns |
138 bool DoesExperimentOverrideProgramAndHashSeed() { | 140 // true. Otherwise, returns false. |
| 141 bool GetProgramAndHashSeedOverridesFromExperiment(std::string* program, |
| 142 std::string* hash_seed) { |
| 143 DCHECK(program); |
| 144 DCHECK(hash_seed); |
139 #if defined(GOOGLE_CHROME_BUILD) | 145 #if defined(GOOGLE_CHROME_BUILD) |
140 std::map<std::string, std::string> params; | 146 std::map<std::string, std::string> params; |
141 chrome_variations::GetVariationParams(kAutomaticProfileResetStudyName, | 147 chrome_variations::GetVariationParams(kAutomaticProfileResetStudyName, |
142 ¶ms); | 148 ¶ms); |
143 return params.count(kAutomaticProfileResetStudyProgramParameterName) && | 149 if (params.count(kAutomaticProfileResetStudyProgramParameterName) && |
144 params.count(kAutomaticProfileResetStudyHashSeedParameterName); | 150 params.count(kAutomaticProfileResetStudyHashSeedParameterName)) { |
145 #else | 151 program->swap(params[kAutomaticProfileResetStudyProgramParameterName]); |
| 152 hash_seed->swap(params[kAutomaticProfileResetStudyHashSeedParameterName]); |
| 153 return true; |
| 154 } |
| 155 #endif |
146 return false; | 156 return false; |
147 #endif | |
148 } | 157 } |
149 | 158 |
150 // Deep-copies all preferences in |source| to a sub-tree named |value_tree_key| | 159 // Deep-copies all preferences in |source| to a sub-tree named |value_tree_key| |
151 // in |target_dictionary|, with path expansion, and also creates an isomorphic | 160 // in |target_dictionary|, with path expansion, and also creates an isomorphic |
152 // sub-tree under the key |is_user_controlled_tree_key| that contains only | 161 // sub-tree under the key |is_user_controlled_tree_key| that contains only |
153 // Boolean values, indicating whether or not the corresponding preferences are | 162 // Boolean values, indicating whether or not the corresponding preferences are |
154 // coming from the 'user' PrefStore. | 163 // coming from the 'user' PrefStore. |
155 void BuildSubTreesFromPreferences(const PrefService* source, | 164 void BuildSubTreesFromPreferences(const PrefService* source, |
156 const char* value_tree_key, | 165 const char* value_tree_key, |
157 const char* is_user_controlled_tree_key, | 166 const char* is_user_controlled_tree_key, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 211 |
203 void AutomaticProfileResetter::Initialize() { | 212 void AutomaticProfileResetter::Initialize() { |
204 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 213 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
205 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 214 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
206 | 215 |
207 if (!ShouldPerformDryRun() && !ShouldPerformLiveRun()) { | 216 if (!ShouldPerformDryRun() && !ShouldPerformLiveRun()) { |
208 state_ = STATE_DISABLED; | 217 state_ = STATE_DISABLED; |
209 return; | 218 return; |
210 } | 219 } |
211 | 220 |
212 ui::ResourceBundle& resources(ui::ResourceBundle::GetSharedInstance()); | 221 if (!GetProgramAndHashSeedOverridesFromExperiment(&program_, &hash_seed_)) { |
213 if (DoesExperimentOverrideProgramAndHashSeed()) { | 222 ui::ResourceBundle& resources(ui::ResourceBundle::GetSharedInstance()); |
214 program_ = chrome_variations::GetVariationParamValue( | 223 if (ShouldPerformLiveRun()) { |
215 kAutomaticProfileResetStudyName, | 224 program_ = resources.GetRawDataResource( |
216 kAutomaticProfileResetStudyProgramParameterName); | 225 IDR_AUTOMATIC_PROFILE_RESET_RULES).as_string(); |
217 hash_seed_ = chrome_variations::GetVariationParamValue( | 226 hash_seed_ = resources.GetRawDataResource( |
218 kAutomaticProfileResetStudyName, | 227 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED).as_string(); |
219 kAutomaticProfileResetStudyHashSeedParameterName); | 228 } else { // ShouldPerformDryRun() |
220 } else if (ShouldPerformLiveRun()) { | 229 program_ = resources.GetRawDataResource( |
221 program_ = resources.GetRawDataResource( | 230 IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY).as_string(); |
222 IDR_AUTOMATIC_PROFILE_RESET_RULES).as_string(); | 231 hash_seed_ = resources.GetRawDataResource( |
223 hash_seed_ = resources.GetRawDataResource( | 232 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY).as_string(); |
224 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED).as_string(); | 233 } |
225 } else { // ShouldPerformDryRun() | |
226 program_ = resources.GetRawDataResource( | |
227 IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY).as_string(); | |
228 hash_seed_ = resources.GetRawDataResource( | |
229 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY).as_string(); | |
230 } | 234 } |
231 | 235 |
232 delegate_.reset(new AutomaticProfileResetterDelegateImpl( | 236 delegate_.reset(new AutomaticProfileResetterDelegateImpl( |
233 TemplateURLServiceFactory::GetForProfile(profile_))); | 237 TemplateURLServiceFactory::GetForProfile(profile_))); |
234 task_runner_for_waiting_ = | 238 task_runner_for_waiting_ = |
235 content::BrowserThread::GetMessageLoopProxyForThread( | 239 content::BrowserThread::GetMessageLoopProxyForThread( |
236 content::BrowserThread::UI); | 240 content::BrowserThread::UI); |
237 | 241 |
238 state_ = STATE_INITIALIZED; | 242 state_ = STATE_INITIALIZED; |
239 } | 243 } |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 kCombinedStatusMaskMaximumValue); | 482 kCombinedStatusMaskMaximumValue); |
479 } | 483 } |
480 | 484 |
481 void AutomaticProfileResetter::Shutdown() { | 485 void AutomaticProfileResetter::Shutdown() { |
482 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 486 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
483 | 487 |
484 state_ = STATE_DISABLED; | 488 state_ = STATE_DISABLED; |
485 delegate_.reset(); | 489 delegate_.reset(); |
486 weak_ptr_factory_.InvalidateWeakPtrs(); | 490 weak_ptr_factory_.InvalidateWeakPtrs(); |
487 } | 491 } |
OLD | NEW |