Chromium Code Reviews| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 kAutomaticProfileResetStudyDryRunGroupName, true); | 126 kAutomaticProfileResetStudyDryRunGroupName, true); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Returns whether or not a live-run shall be performed. | 129 // Returns whether or not a live-run shall be performed. |
| 130 bool ShouldPerformLiveRun() { | 130 bool ShouldPerformLiveRun() { |
| 131 return StartsWithASCII( | 131 return StartsWithASCII( |
| 132 base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName), | 132 base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName), |
| 133 kAutomaticProfileResetStudyEnabledGroupName, true); | 133 kAutomaticProfileResetStudyEnabledGroupName, true); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Returns whether or not the currently active experiment group prescribes the | 136 // If the currently active experiment group prescribes a |program| and |
| 137 // program and hash seed to use instead of the baked-in ones. | 137 // |ħash_seed| to use instead of the baked-in ones, retrieves those and returns |
|
Alexei Svitkine (slow)
2013/11/06 17:30:29
Nit: Is the 'h' in hash_seed some accented one her
engedy
2013/11/06 18:14:28
Wow, I have no idea how that happened. Thanks for
| |
| 138 bool DoesExperimentOverrideProgramAndHashSeed() { | 138 // true. Otherwise, returns false. |
| 139 bool GetProgramAndHashSeedOverridesFromExperiment(std::string* program, | |
| 140 std::string* hash_seed) { | |
| 141 DCHECK(program); | |
| 142 DCHECK(hash_seed); | |
| 139 #if defined(GOOGLE_CHROME_BUILD) | 143 #if defined(GOOGLE_CHROME_BUILD) |
| 140 std::map<std::string, std::string> params; | 144 std::map<std::string, std::string> params; |
| 141 chrome_variations::GetVariationParams(kAutomaticProfileResetStudyName, | 145 chrome_variations::GetVariationParams(kAutomaticProfileResetStudyName, |
| 142 ¶ms); | 146 ¶ms); |
| 143 return params.count(kAutomaticProfileResetStudyProgramParameterName) && | 147 if (params.count(kAutomaticProfileResetStudyProgramParameterName) && |
| 144 params.count(kAutomaticProfileResetStudyHashSeedParameterName); | 148 params.count(kAutomaticProfileResetStudyHashSeedParameterName)) { |
| 145 #else | 149 program->swap(params[kAutomaticProfileResetStudyProgramParameterName]); |
| 150 hash_seed->swap(params[kAutomaticProfileResetStudyHashSeedParameterName]); | |
| 151 return true; | |
| 152 } | |
| 153 #endif | |
| 146 return false; | 154 return false; |
| 147 #endif | |
| 148 } | 155 } |
| 149 | 156 |
| 150 // Deep-copies all preferences in |source| to a sub-tree named |value_tree_key| | 157 // 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 | 158 // 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 | 159 // sub-tree under the key |is_user_controlled_tree_key| that contains only |
| 153 // Boolean values, indicating whether or not the corresponding preferences are | 160 // Boolean values, indicating whether or not the corresponding preferences are |
| 154 // coming from the 'user' PrefStore. | 161 // coming from the 'user' PrefStore. |
| 155 void BuildSubTreesFromPreferences(const PrefService* source, | 162 void BuildSubTreesFromPreferences(const PrefService* source, |
| 156 const char* value_tree_key, | 163 const char* value_tree_key, |
| 157 const char* is_user_controlled_tree_key, | 164 const char* is_user_controlled_tree_key, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 | 209 |
| 203 void AutomaticProfileResetter::Initialize() { | 210 void AutomaticProfileResetter::Initialize() { |
| 204 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 211 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 205 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 212 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
| 206 | 213 |
| 207 if (!ShouldPerformDryRun() && !ShouldPerformLiveRun()) { | 214 if (!ShouldPerformDryRun() && !ShouldPerformLiveRun()) { |
| 208 state_ = STATE_DISABLED; | 215 state_ = STATE_DISABLED; |
| 209 return; | 216 return; |
| 210 } | 217 } |
| 211 | 218 |
| 212 ui::ResourceBundle& resources(ui::ResourceBundle::GetSharedInstance()); | 219 if (!GetProgramAndHashSeedOverridesFromExperiment(&program_, &hash_seed_)) { |
| 213 if (DoesExperimentOverrideProgramAndHashSeed()) { | 220 ui::ResourceBundle& resources(ui::ResourceBundle::GetSharedInstance()); |
| 214 program_ = chrome_variations::GetVariationParamValue( | 221 if (ShouldPerformLiveRun()) { |
| 215 kAutomaticProfileResetStudyName, | 222 program_ = resources.GetRawDataResource( |
| 216 kAutomaticProfileResetStudyProgramParameterName); | 223 IDR_AUTOMATIC_PROFILE_RESET_RULES).as_string(); |
| 217 hash_seed_ = chrome_variations::GetVariationParamValue( | 224 hash_seed_ = resources.GetRawDataResource( |
| 218 kAutomaticProfileResetStudyName, | 225 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED).as_string(); |
| 219 kAutomaticProfileResetStudyHashSeedParameterName); | 226 } else { // ShouldPerformDryRun() |
| 220 } else if (ShouldPerformLiveRun()) { | 227 program_ = resources.GetRawDataResource( |
| 221 program_ = resources.GetRawDataResource( | 228 IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY).as_string(); |
| 222 IDR_AUTOMATIC_PROFILE_RESET_RULES).as_string(); | 229 hash_seed_ = resources.GetRawDataResource( |
| 223 hash_seed_ = resources.GetRawDataResource( | 230 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY).as_string(); |
| 224 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED).as_string(); | 231 } |
| 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 } | 232 } |
| 231 | 233 |
| 232 delegate_.reset(new AutomaticProfileResetterDelegateImpl( | 234 delegate_.reset(new AutomaticProfileResetterDelegateImpl( |
| 233 TemplateURLServiceFactory::GetForProfile(profile_))); | 235 TemplateURLServiceFactory::GetForProfile(profile_))); |
| 234 task_runner_for_waiting_ = | 236 task_runner_for_waiting_ = |
| 235 content::BrowserThread::GetMessageLoopProxyForThread( | 237 content::BrowserThread::GetMessageLoopProxyForThread( |
| 236 content::BrowserThread::UI); | 238 content::BrowserThread::UI); |
| 237 | 239 |
| 238 state_ = STATE_INITIALIZED; | 240 state_ = STATE_INITIALIZED; |
| 239 } | 241 } |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 478 kCombinedStatusMaskMaximumValue); | 480 kCombinedStatusMaskMaximumValue); |
| 479 } | 481 } |
| 480 | 482 |
| 481 void AutomaticProfileResetter::Shutdown() { | 483 void AutomaticProfileResetter::Shutdown() { |
| 482 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 484 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 483 | 485 |
| 484 state_ = STATE_DISABLED; | 486 state_ = STATE_DISABLED; |
| 485 delegate_.reset(); | 487 delegate_.reset(); |
| 486 weak_ptr_factory_.InvalidateWeakPtrs(); | 488 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 487 } | 489 } |
| OLD | NEW |