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_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_number_conversions.h" | |
| 13 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
| 14 #include "base/task_runner_util.h" | 15 #include "base/task_runner_util.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 16 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "chrome/browser/browser_process.h" | |
| 18 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h" | |
| 16 #include "chrome/browser/profile_resetter/jtl_interpreter.h" | 19 #include "chrome/browser/profile_resetter/jtl_interpreter.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 18 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 19 #include "grit/browser_resources.h" | 22 #include "grit/browser_resources.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 // Number of bits, and maximum value (exclusive) for the mask whose bits | |
| 25 // indicate which of reset criteria were satisfied. | |
| 26 const size_t kSatisfiedCriteriaMaskBits = 2; | |
| 27 const uint32 kSatisfiedCriteriaMaskMaximumValue = | |
| 28 (1 << kSatisfiedCriteriaMaskBits); | |
| 29 | |
| 30 // Number of bits, and maximum value (exclusive) for the mask whose bits | |
| 31 // indicate if any of reset criteria were satisfied, and which of the mementos | |
| 32 // were already present. | |
| 33 const size_t kCombinedStatusMaskBits = 4; | |
| 34 const uint32 kCombinedStatusMaskMaximumValue = (1 << kCombinedStatusMaskBits); | |
| 35 | |
| 36 // Name constants for the field trial behind which we enable this feature. | 27 // Name constants for the field trial behind which we enable this feature. |
| 37 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; | 28 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; |
| 38 const char kAutomaticProfileResetStudyDryRunGroupName[] = "DryRun"; | 29 const char kAutomaticProfileResetStudyDryRunGroupName[] = "DryRun"; |
| 39 const char kAutomaticProfileResetStudyEnabledGroupName[] = "Enabled"; | 30 const char kAutomaticProfileResetStudyEnabledGroupName[] = "Enabled"; |
| 40 | 31 |
| 41 // Keys used in the input dictionary of the program. | 32 // Keys used in the input dictionary of the program. |
| 42 // TODO(engedy): Add these here on an as-needed basis. | 33 const char kUserPreferencesKey[] = "preferences"; |
| 34 const char kUserPreferencesIsUserControlledKey[] = "preferences_iuc"; | |
| 35 const char kLocalStateKey[] = "local_state"; | |
| 36 const char kLocalStateIsUserControlledKey[] = "local_state_iuc"; | |
| 37 const char kSearchProvidersKey[] = "search_providers"; | |
| 38 const char kDefaultSearchProviderKey[] = "default_search_provider"; | |
| 39 const char kDefaultSearchProviderIsUserControlledKey[] = | |
| 40 "default_search_provider_iuc"; | |
| 41 const char kLoadedModuleDigestsKey[] = "loaded_modules"; | |
| 43 | 42 |
| 44 // Keys used in the output dictionary of the program. | 43 // Keys used in the output dictionary of the program. |
| 45 const char kHadPromptedAlreadyKey[] = "had_prompted_already"; | 44 const char kHadPromptedAlreadyKey[] = "had_prompted_already"; |
| 46 const char kSatisfiedCriteriaMaskKeys[][29] = {"satisfied_criteria_mask_bit1", | 45 const char kSatisfiedCriteriaMaskKeys[][29] = {"satisfied_criteria_mask_bit1", |
|
vasilii
2013/10/14 16:43:33
Do we need these magic numbers here and below?
engedy
2013/10/14 19:35:50
I believe so, yes. The alternative is:
const char
vasilii
2013/10/16 13:39:48
Then leave it.
engedy
2013/10/16 15:12:17
Done.
| |
| 47 "satisfied_criteria_mask_bit2"}; | 46 "satisfied_criteria_mask_bit2"}; |
| 48 const char kCombinedStatusMaskKeys[][26] = { | 47 const char kCombinedStatusMaskKeys[][26] = { |
| 49 "combined_status_mask_bit1", "combined_status_mask_bit2", | 48 "combined_status_mask_bit1", "combined_status_mask_bit2", |
| 50 "combined_status_mask_bit3", "combined_status_mask_bit4"}; | 49 "combined_status_mask_bit3", "combined_status_mask_bit4"}; |
| 51 | 50 |
| 52 // Keys used in both the input and output dictionary of the program. | 51 // Keys used in both the input and output dictionary of the program. |
| 53 const char kMementoValueInPrefsKey[] = "memento_value_in_prefs"; | 52 const char kMementoValueInPrefsKey[] = "memento_value_in_prefs"; |
| 54 const char kMementoValueInLocalStateKey[] = "memento_value_in_local_state"; | 53 const char kMementoValueInLocalStateKey[] = "memento_value_in_local_state"; |
| 55 const char kMementoValueInFileKey[] = "memento_value_in_file"; | 54 const char kMementoValueInFileKey[] = "memento_value_in_file"; |
| 56 | 55 |
| 57 COMPILE_ASSERT( | 56 // Implementation details ------------------------------------------------------ |
| 58 arraysize(kSatisfiedCriteriaMaskKeys) == kSatisfiedCriteriaMaskBits, | |
| 59 satisfied_criteria_mask_bits_mismatch); | |
| 60 COMPILE_ASSERT(arraysize(kCombinedStatusMaskKeys) == kCombinedStatusMaskBits, | |
| 61 combined_status_mask_bits_mismatch); | |
| 62 | |
| 63 // Implementation detail classes --------------------------------------------- | |
| 64 | |
| 65 class AutomaticProfileResetterDelegateImpl | |
| 66 : public AutomaticProfileResetterDelegate { | |
| 67 public: | |
| 68 AutomaticProfileResetterDelegateImpl() {} | |
| 69 virtual ~AutomaticProfileResetterDelegateImpl() {} | |
| 70 | |
| 71 // AutomaticProfileResetterDelegate overrides: | |
| 72 | |
| 73 virtual void ShowPrompt() OVERRIDE { | |
| 74 // TODO(engedy): Call the UI from here once we have it. | |
| 75 } | |
| 76 | |
| 77 virtual void ReportStatistics(uint32 satisfied_criteria_mask, | |
| 78 uint32 combined_status_mask) OVERRIDE { | |
| 79 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.SatisfiedCriteriaMask", | |
| 80 satisfied_criteria_mask, | |
| 81 kSatisfiedCriteriaMaskMaximumValue); | |
| 82 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.CombinedStatusMask", | |
| 83 combined_status_mask, | |
| 84 kCombinedStatusMaskMaximumValue); | |
| 85 } | |
| 86 | |
| 87 private: | |
| 88 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterDelegateImpl); | |
| 89 }; | |
| 90 | 57 |
| 91 // Enumeration of the possible outcomes of showing the profile reset prompt. | 58 // Enumeration of the possible outcomes of showing the profile reset prompt. |
| 92 enum PromptResult { | 59 enum PromptResult { |
| 93 // Prompt was not shown because only a dry-run was performed. | 60 // Prompt was not shown because only a dry-run was performed. |
| 94 PROMPT_NOT_SHOWN, | 61 PROMPT_NOT_SHOWN, |
| 95 PROMPT_ACTION_RESET, | 62 PROMPT_ACTION_RESET, |
| 96 PROMPT_ACTION_NO_RESET, | 63 PROMPT_ACTION_NO_RESET, |
| 97 PROMPT_DISMISSED, | 64 PROMPT_DISMISSED, |
| 98 // Prompt was still shown (not dismissed by the user) when Chrome was closed. | 65 // Prompt was still shown (not dismissed by the user) when Chrome was closed. |
| 99 PROMPT_IGNORED, | 66 PROMPT_IGNORED, |
| 100 PROMPT_RESULT_MAX | 67 PROMPT_RESULT_MAX |
| 101 }; | 68 }; |
| 102 | 69 |
| 70 // Deep-copies all preferences in |source| to a sub-tree named |value_tree_key| | |
| 71 // in |target_dictionary|, with path expansion, and also creates an isomorphic | |
| 72 // sub-tree under the key |is_user_controlled_tree_key| that contains only | |
| 73 // Boolean values, indicating whether or not the corresponding preferences are | |
| 74 // coming from the 'user' PrefStore. | |
| 75 void BuildSubTreesFromPreferences(const PrefService* source, | |
| 76 base::DictionaryValue* target_dictionary, | |
|
vasilii
2013/10/14 16:43:33
It's the only output parameter. Therefore it shoul
engedy
2013/10/14 19:35:50
Done.
| |
| 77 const char* value_tree_key, | |
| 78 const char* is_user_controlled_tree_key) { | |
| 79 scoped_ptr<base::DictionaryValue> pref_name_to_value_map( | |
| 80 source->GetPreferenceValuesWithoutPathExpansion()); | |
| 81 std::vector<std::string> pref_names; | |
| 82 pref_names.reserve(pref_name_to_value_map->size()); | |
| 83 for (base::DictionaryValue::Iterator it(*pref_name_to_value_map); | |
| 84 !it.IsAtEnd(); | |
| 85 it.Advance()) { | |
| 86 pref_names.push_back(it.key()); | |
| 87 } | |
| 88 base::DictionaryValue* value_tree = new base::DictionaryValue; | |
| 89 base::DictionaryValue* is_user_controlled_tree = new base::DictionaryValue; | |
| 90 for (std::vector<std::string>::const_iterator it = pref_names.begin(); | |
| 91 it != pref_names.end(); | |
| 92 ++it) { | |
| 93 scoped_ptr<Value> pref_value_owned; | |
| 94 if (pref_name_to_value_map->RemoveWithoutPathExpansion(*it, | |
| 95 &pref_value_owned)) { | |
| 96 value_tree->Set(*it, pref_value_owned.release()); | |
| 97 const PrefService::Preference* pref = source->FindPreference(it->c_str()); | |
| 98 is_user_controlled_tree->Set( | |
| 99 *it, new base::FundamentalValue(pref->IsUserControlled())); | |
| 100 } | |
| 101 } | |
| 102 target_dictionary->Set(value_tree_key, value_tree); | |
|
vasilii
2013/10/14 16:43:33
Why can't we use pref_name_to_value_map here direc
engedy
2013/10/14 19:35:50
That one does not yet have path expansion (splitti
| |
| 103 target_dictionary->Set(is_user_controlled_tree_key, is_user_controlled_tree); | |
| 104 } | |
| 105 | |
| 103 } // namespace | 106 } // namespace |
| 104 | 107 |
| 105 // AutomaticProfileResetter::EvaluationResults ------------------------------- | 108 // AutomaticProfileResetter::EvaluationResults ------------------------------- |
| 106 | 109 |
| 107 // Encapsulates the output values extracted from the evaluator program. | 110 // Encapsulates the output values extracted from the evaluator program. |
| 108 struct AutomaticProfileResetter::EvaluationResults { | 111 struct AutomaticProfileResetter::EvaluationResults { |
| 109 EvaluationResults() | 112 EvaluationResults() |
| 110 : had_prompted_already(false), | 113 : had_prompted_already(false), |
| 111 satisfied_criteria_mask(0), | 114 satisfied_criteria_mask(0), |
| 112 combined_status_mask(0) {} | 115 combined_status_mask(0) {} |
| 113 | 116 |
| 114 std::string memento_value_in_prefs; | 117 std::string memento_value_in_prefs; |
| 115 std::string memento_value_in_local_state; | 118 std::string memento_value_in_local_state; |
| 116 std::string memento_value_in_file; | 119 std::string memento_value_in_file; |
| 117 | 120 |
| 118 bool had_prompted_already; | 121 bool had_prompted_already; |
| 119 uint32 satisfied_criteria_mask; | 122 uint32 satisfied_criteria_mask; |
| 120 uint32 combined_status_mask; | 123 uint32 combined_status_mask; |
| 121 }; | 124 }; |
| 122 | 125 |
| 123 // AutomaticProfileResetter -------------------------------------------------- | 126 // AutomaticProfileResetter -------------------------------------------------- |
| 124 | 127 |
| 128 const size_t AutomaticProfileResetter::kSatisfiedCriteriaMaskBits = 2; | |
| 129 const uint32 AutomaticProfileResetter::kSatisfiedCriteriaMaskMaximumValue = | |
| 130 (1 << AutomaticProfileResetter::kSatisfiedCriteriaMaskBits); | |
|
vasilii
2013/10/14 16:43:33
Here and below "1u << ..."
engedy
2013/10/14 19:35:50
Done.
| |
| 131 | |
| 132 const size_t AutomaticProfileResetter::kCombinedStatusMaskBits = 4; | |
| 133 const uint32 AutomaticProfileResetter::kCombinedStatusMaskMaximumValue = | |
| 134 (1 << AutomaticProfileResetter::kCombinedStatusMaskBits); | |
| 135 | |
| 136 COMPILE_ASSERT(arraysize(kSatisfiedCriteriaMaskKeys) == | |
| 137 ::AutomaticProfileResetter::kSatisfiedCriteriaMaskBits, | |
|
vasilii
2013/10/14 16:43:33
What is the reason to specify "::AutomaticProfileR
engedy
2013/10/14 19:35:50
Nice catch, it just left there from times when thi
| |
| 138 satisfied_criteria_mask_bits_mismatch); | |
| 139 COMPILE_ASSERT(arraysize(kCombinedStatusMaskKeys) == | |
| 140 ::AutomaticProfileResetter::kCombinedStatusMaskBits, | |
| 141 combined_status_mask_bits_mismatch); | |
| 142 | |
| 125 AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile) | 143 AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile) |
| 126 : profile_(profile), | 144 : profile_(profile), |
| 127 state_(STATE_UNINITIALIZED), | 145 state_(STATE_UNINITIALIZED), |
| 146 enumeration_of_loaded_modules_ready_(false), | |
| 147 template_url_service_ready_(false), | |
| 128 memento_in_prefs_(profile_), | 148 memento_in_prefs_(profile_), |
| 129 memento_in_local_state_(profile_), | 149 memento_in_local_state_(profile_), |
| 130 memento_in_file_(profile_), | 150 memento_in_file_(profile_), |
| 131 weak_ptr_factory_(this) { | 151 weak_ptr_factory_(this) { |
| 132 DCHECK(profile_); | 152 DCHECK(profile_); |
| 153 Initialize(); | |
| 133 } | 154 } |
| 134 | 155 |
| 135 AutomaticProfileResetter::~AutomaticProfileResetter() {} | 156 AutomaticProfileResetter::~AutomaticProfileResetter() {} |
| 136 | 157 |
| 137 void AutomaticProfileResetter::Initialize() { | 158 void AutomaticProfileResetter::Initialize() { |
| 138 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 159 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 139 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 160 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
| 140 | 161 |
| 141 if (ShouldPerformDryRun() || ShouldPerformLiveRun()) { | 162 if (ShouldPerformDryRun() || ShouldPerformLiveRun()) { |
| 142 ui::ResourceBundle& resources(ui::ResourceBundle::GetSharedInstance()); | 163 ui::ResourceBundle& resources(ui::ResourceBundle::GetSharedInstance()); |
| 143 if (ShouldPerformLiveRun()) { | 164 if (ShouldPerformLiveRun()) { |
| 144 program_ = | 165 program_ = |
| 145 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_RULES); | 166 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_RULES); |
| 146 hash_seed_ = | 167 hash_seed_ = |
| 147 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED); | 168 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED); |
| 148 } else { // ShouldPerformDryRun() | 169 } else { // ShouldPerformDryRun() |
| 149 program_ = | 170 program_ = |
| 150 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY); | 171 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY); |
| 151 hash_seed_ = resources.GetRawDataResource( | 172 hash_seed_ = resources.GetRawDataResource( |
| 152 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY); | 173 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY); |
| 153 } | 174 } |
| 154 delegate_.reset(new AutomaticProfileResetterDelegateImpl()); | 175 delegate_.reset(new AutomaticProfileResetterDelegateImpl(profile_)); |
| 155 | 176 state_ = STATE_INITIALIZED; |
| 156 state_ = STATE_READY; | |
| 157 | |
| 158 content::BrowserThread::PostTask( | |
| 159 content::BrowserThread::UI, | |
| 160 FROM_HERE, | |
| 161 base::Bind(&AutomaticProfileResetter::BeginEvaluationFlow, | |
| 162 weak_ptr_factory_.GetWeakPtr())); | |
| 163 } else { | 177 } else { |
| 164 state_ = STATE_DISABLED; | 178 state_ = STATE_DISABLED; |
| 165 } | 179 } |
| 166 } | 180 } |
| 167 | 181 |
| 182 void AutomaticProfileResetter::Activate() { | |
| 183 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 184 DCHECK(state_ == STATE_INITIALIZED || state_ == STATE_DISABLED); | |
| 185 | |
| 186 if (state_ == STATE_INITIALIZED) { | |
| 187 if (!program_.empty()) { | |
| 188 state_ = STATE_WAITING_ON_SERVICES; | |
| 189 delegate_->WaitOnTemplateURLService( | |
| 190 base::Bind(&AutomaticProfileResetter::OnTemplateURLServiceBecameReady, | |
| 191 weak_ptr_factory_.GetWeakPtr())); | |
| 192 delegate_->LoadTemplateURLServiceIfNeeded(); | |
| 193 delegate_->WaitOnEnumerationOfLoadedModules(base::Bind( | |
| 194 &AutomaticProfileResetter::OnEnumerationOfLoadedModulesReady, | |
| 195 weak_ptr_factory_.GetWeakPtr())); | |
| 196 delegate_->EnumerateLoadedModulesIfNeeded(); | |
| 197 } else { | |
| 198 // Terminate early if there is no program included (nor set by tests). | |
| 199 state_ = STATE_DISABLED; | |
| 200 } | |
| 201 } | |
| 202 } | |
| 203 | |
| 168 bool AutomaticProfileResetter::ShouldPerformDryRun() const { | 204 bool AutomaticProfileResetter::ShouldPerformDryRun() const { |
| 169 return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) == | 205 return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) == |
| 170 kAutomaticProfileResetStudyDryRunGroupName; | 206 kAutomaticProfileResetStudyDryRunGroupName; |
| 171 } | 207 } |
| 172 | 208 |
| 173 bool AutomaticProfileResetter::ShouldPerformLiveRun() const { | 209 bool AutomaticProfileResetter::ShouldPerformLiveRun() const { |
| 174 return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) == | 210 return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) == |
| 175 kAutomaticProfileResetStudyEnabledGroupName; | 211 kAutomaticProfileResetStudyEnabledGroupName; |
| 176 } | 212 } |
| 177 | 213 |
| 214 void AutomaticProfileResetter::OnTemplateURLServiceBecameReady() { | |
| 215 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 216 DCHECK_EQ(state_, STATE_WAITING_ON_SERVICES); | |
| 217 | |
| 218 template_url_service_ready_ = true; | |
|
vasilii
2013/10/14 16:43:33
OnTemplateURLServiceBecameReady() and OnEnumeratio
engedy
2013/10/14 19:35:50
Done.
| |
| 219 if (template_url_service_ready_ && enumeration_of_loaded_modules_ready_) { | |
| 220 state_ = STATE_READY; | |
| 221 content::BrowserThread::PostTask( | |
| 222 content::BrowserThread::UI, | |
| 223 FROM_HERE, | |
| 224 base::Bind(&AutomaticProfileResetter::BeginEvaluationFlow, | |
| 225 weak_ptr_factory_.GetWeakPtr())); | |
| 226 } | |
| 227 } | |
| 228 | |
| 229 void AutomaticProfileResetter::OnEnumerationOfLoadedModulesReady() { | |
| 230 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 231 DCHECK_EQ(state_, STATE_WAITING_ON_SERVICES); | |
| 232 | |
| 233 enumeration_of_loaded_modules_ready_ = true; | |
| 234 if (template_url_service_ready_ && enumeration_of_loaded_modules_ready_) { | |
| 235 state_ = STATE_READY; | |
| 236 content::BrowserThread::PostTask( | |
| 237 content::BrowserThread::UI, | |
| 238 FROM_HERE, | |
| 239 base::Bind(&AutomaticProfileResetter::BeginEvaluationFlow, | |
| 240 weak_ptr_factory_.GetWeakPtr())); | |
| 241 } | |
| 242 } | |
| 243 | |
| 178 void AutomaticProfileResetter::BeginEvaluationFlow() { | 244 void AutomaticProfileResetter::BeginEvaluationFlow() { |
| 179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 245 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 180 DCHECK_EQ(state_, STATE_READY); | 246 DCHECK_EQ(state_, STATE_READY); |
| 247 DCHECK(!program_.empty()); | |
| 181 | 248 |
| 182 if (!program_.empty()) { | 249 state_ = STATE_WORKING; |
| 183 state_ = STATE_WORKING; | 250 memento_in_file_.ReadValue( |
| 184 memento_in_file_.ReadValue( | 251 base::Bind(&AutomaticProfileResetter::ContinueWithEvaluationFlow, |
| 185 base::Bind(&AutomaticProfileResetter::ContinueWithEvaluationFlow, | 252 weak_ptr_factory_.GetWeakPtr())); |
| 186 weak_ptr_factory_.GetWeakPtr())); | |
| 187 } else { | |
| 188 // Terminate early if there is no program included (nor set by tests). | |
| 189 state_ = STATE_DISABLED; | |
| 190 } | |
| 191 } | 253 } |
| 192 | 254 |
| 193 scoped_ptr<base::DictionaryValue> | 255 scoped_ptr<base::DictionaryValue> |
| 194 AutomaticProfileResetter::BuildEvaluatorProgramInput( | 256 AutomaticProfileResetter::BuildEvaluatorProgramInput( |
| 195 const std::string& memento_value_in_file) { | 257 const std::string& memento_value_in_file) { |
| 196 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 258 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 197 // TODO(engedy): Add any additional state here that is needed by the program. | 259 |
| 198 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue); | 260 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue); |
| 261 | |
| 262 // Include memento values (or empty strings in case mementos are not there). | |
| 199 input->SetString(kMementoValueInPrefsKey, memento_in_prefs_.ReadValue()); | 263 input->SetString(kMementoValueInPrefsKey, memento_in_prefs_.ReadValue()); |
| 200 input->SetString(kMementoValueInLocalStateKey, | 264 input->SetString(kMementoValueInLocalStateKey, |
| 201 memento_in_local_state_.ReadValue()); | 265 memento_in_local_state_.ReadValue()); |
| 202 input->SetString(kMementoValueInFileKey, memento_value_in_file); | 266 input->SetString(kMementoValueInFileKey, memento_value_in_file); |
| 267 | |
| 268 // Include all user (i.e. profile-specific) preferences, along with | |
| 269 // information about whether the value is coming from the 'user' PrefStore. | |
| 270 PrefService* prefs = profile_->GetPrefs(); | |
| 271 DCHECK(prefs); | |
| 272 BuildSubTreesFromPreferences(prefs, | |
| 273 input.get(), | |
| 274 kUserPreferencesKey, | |
| 275 kUserPreferencesIsUserControlledKey); | |
| 276 | |
| 277 // Include all local state (i.e. shared) preferences, along with information | |
| 278 // about whether the value is coming from the 'user' PrefStore. | |
| 279 PrefService* local_state = g_browser_process->local_state(); | |
| 280 DCHECK(local_state); | |
| 281 BuildSubTreesFromPreferences( | |
| 282 local_state, input.get(), kLocalStateKey, kLocalStateIsUserControlledKey); | |
| 283 | |
| 284 // Include all information related to search engines. | |
| 285 base::DictionaryValue* default_search_provider_details = | |
| 286 delegate_->GetDefaultSearchProviderDetails(); | |
| 287 if (default_search_provider_details) | |
| 288 input->Set(kDefaultSearchProviderKey, default_search_provider_details); | |
| 289 | |
| 290 base::ListValue* search_providers_details = | |
| 291 delegate_->GetPrepopulatedSearchProvidersDetails(); | |
| 292 if (search_providers_details) | |
| 293 input->Set(kSearchProvidersKey, search_providers_details); | |
| 294 | |
| 295 input->SetBoolean(kDefaultSearchProviderIsUserControlledKey, | |
| 296 !delegate_->IsDefaultSearchProviderManaged()); | |
| 297 | |
| 298 // Include information about loaded modules. | |
| 299 base::ListValue* loaded_module_digests = | |
| 300 delegate_->GetLoadedModuleNameDigests(); | |
| 301 if (loaded_module_digests) | |
| 302 input->Set(kLoadedModuleDigestsKey, loaded_module_digests); | |
| 303 | |
| 203 return input.Pass(); | 304 return input.Pass(); |
| 204 } | 305 } |
| 205 | 306 |
| 206 void AutomaticProfileResetter::ContinueWithEvaluationFlow( | 307 void AutomaticProfileResetter::ContinueWithEvaluationFlow( |
| 207 const std::string& memento_value_in_file) { | 308 const std::string& memento_value_in_file) { |
| 208 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 309 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 209 DCHECK_EQ(state_, STATE_WORKING); | 310 DCHECK_EQ(state_, STATE_WORKING); |
| 210 PrefService* prefs = profile_->GetPrefs(); | 311 PrefService* prefs = profile_->GetPrefs(); |
| 211 DCHECK(prefs); | 312 DCHECK(prefs); |
| 212 | 313 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 239 std::string hash_seed_str(hash_seed.as_string()); | 340 std::string hash_seed_str(hash_seed.as_string()); |
| 240 std::string program_str(program.as_string()); | 341 std::string program_str(program.as_string()); |
| 241 JtlInterpreter interpreter(hash_seed_str, program_str, program_input.get()); | 342 JtlInterpreter interpreter(hash_seed_str, program_str, program_input.get()); |
| 242 interpreter.Execute(); | 343 interpreter.Execute(); |
| 243 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.InterpreterResult", | 344 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.InterpreterResult", |
| 244 interpreter.result(), | 345 interpreter.result(), |
| 245 JtlInterpreter::RESULT_MAX); | 346 JtlInterpreter::RESULT_MAX); |
| 246 | 347 |
| 247 // In each case below, the respective field in result originally contains the | 348 // In each case below, the respective field in result originally contains the |
| 248 // default, so if the getter fails, we still have the correct value there. | 349 // default, so if the getter fails, we still have the correct value there. |
| 249 scoped_ptr<EvaluationResults> results(new EvaluationResults()); | 350 scoped_ptr<EvaluationResults> results(new EvaluationResults()); |
|
vasilii
2013/10/14 16:43:33
scoped_ptr<EvaluationResults> results(new Evaluati
engedy
2013/10/14 19:35:50
Done.
| |
| 250 interpreter.GetOutputBoolean(kHadPromptedAlreadyKey, | 351 interpreter.GetOutputBoolean(kHadPromptedAlreadyKey, |
| 251 &results->had_prompted_already); | 352 &results->had_prompted_already); |
| 252 interpreter.GetOutputString(kMementoValueInPrefsKey, | 353 interpreter.GetOutputString(kMementoValueInPrefsKey, |
| 253 &results->memento_value_in_prefs); | 354 &results->memento_value_in_prefs); |
| 254 interpreter.GetOutputString(kMementoValueInLocalStateKey, | 355 interpreter.GetOutputString(kMementoValueInLocalStateKey, |
| 255 &results->memento_value_in_local_state); | 356 &results->memento_value_in_local_state); |
| 256 interpreter.GetOutputString(kMementoValueInFileKey, | 357 interpreter.GetOutputString(kMementoValueInFileKey, |
| 257 &results->memento_value_in_file); | 358 &results->memento_value_in_file); |
| 258 for (size_t i = 0; i < arraysize(kCombinedStatusMaskKeys); ++i) { | 359 for (size_t i = 0; i < arraysize(kCombinedStatusMaskKeys); ++i) { |
| 259 bool flag = false; | 360 bool flag = false; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 delegate_.reset(delegate); | 410 delegate_.reset(delegate); |
| 310 } | 411 } |
| 311 | 412 |
| 312 void AutomaticProfileResetter::Shutdown() { | 413 void AutomaticProfileResetter::Shutdown() { |
| 313 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 414 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 314 | 415 |
| 315 state_ = STATE_DISABLED; | 416 state_ = STATE_DISABLED; |
| 316 delegate_.reset(); | 417 delegate_.reset(); |
| 317 weak_ptr_factory_.InvalidateWeakPtrs(); | 418 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 318 } | 419 } |
| OLD | NEW |