Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: chrome/browser/profile_resetter/automatic_profile_resetter.cc

Issue 27030002: Added collecting of data to be fed to the JTL interpreter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by vasilii@. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/time/time.h"
18 #include "base/values.h"
19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/profile_resetter/automatic_profile_resetter_delegate.h"
16 #include "chrome/browser/profile_resetter/jtl_interpreter.h" 21 #include "chrome/browser/profile_resetter/jtl_interpreter.h"
17 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
18 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
19 #include "grit/browser_resources.h" 24 #include "grit/browser_resources.h"
20 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
21 26
22 namespace { 27 namespace {
23 28
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. 29 // Name constants for the field trial behind which we enable this feature.
37 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset"; 30 const char kAutomaticProfileResetStudyName[] = "AutomaticProfileReset";
38 const char kAutomaticProfileResetStudyDryRunGroupName[] = "DryRun"; 31 const char kAutomaticProfileResetStudyDryRunGroupName[] = "DryRun";
39 const char kAutomaticProfileResetStudyEnabledGroupName[] = "Enabled"; 32 const char kAutomaticProfileResetStudyEnabledGroupName[] = "Enabled";
40 33
34 // How long to wait after start-up before unleashing the evaluation flow.
35 const int64 kEvaluationFlowDelayInSeconds = 55;
36
41 // Keys used in the input dictionary of the program. 37 // Keys used in the input dictionary of the program.
42 // TODO(engedy): Add these here on an as-needed basis. 38 const char kUserPreferencesKey[] = "preferences";
39 const char kUserPreferencesIsUserControlledKey[] = "preferences_iuc";
40 const char kLocalStateKey[] = "local_state";
41 const char kLocalStateIsUserControlledKey[] = "local_state_iuc";
42 const char kSearchProvidersKey[] = "search_providers";
43 const char kDefaultSearchProviderKey[] = "default_search_provider";
44 const char kDefaultSearchProviderIsUserControlledKey[] =
45 "default_search_provider_iuc";
46 const char kLoadedModuleDigestsKey[] = "loaded_modules";
43 47
44 // Keys used in the output dictionary of the program. 48 // Keys used in the output dictionary of the program.
45 const char kHadPromptedAlreadyKey[] = "had_prompted_already"; 49 const char kHadPromptedAlreadyKey[] = "had_prompted_already";
46 const char kSatisfiedCriteriaMaskKeys[][29] = {"satisfied_criteria_mask_bit1", 50 const char kSatisfiedCriteriaMaskKeys[][29] = {"satisfied_criteria_mask_bit1",
47 "satisfied_criteria_mask_bit2"}; 51 "satisfied_criteria_mask_bit2"};
48 const char kCombinedStatusMaskKeys[][26] = { 52 const char kCombinedStatusMaskKeys[][26] = {
49 "combined_status_mask_bit1", "combined_status_mask_bit2", 53 "combined_status_mask_bit1", "combined_status_mask_bit2",
50 "combined_status_mask_bit3", "combined_status_mask_bit4"}; 54 "combined_status_mask_bit3", "combined_status_mask_bit4"};
51 55
52 // Keys used in both the input and output dictionary of the program. 56 // Keys used in both the input and output dictionary of the program.
53 const char kMementoValueInPrefsKey[] = "memento_value_in_prefs"; 57 const char kMementoValueInPrefsKey[] = "memento_value_in_prefs";
54 const char kMementoValueInLocalStateKey[] = "memento_value_in_local_state"; 58 const char kMementoValueInLocalStateKey[] = "memento_value_in_local_state";
55 const char kMementoValueInFileKey[] = "memento_value_in_file"; 59 const char kMementoValueInFileKey[] = "memento_value_in_file";
56 60
57 COMPILE_ASSERT( 61 // 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 62
91 // Enumeration of the possible outcomes of showing the profile reset prompt. 63 // Enumeration of the possible outcomes of showing the profile reset prompt.
92 enum PromptResult { 64 enum PromptResult {
93 // Prompt was not shown because only a dry-run was performed. 65 // Prompt was not shown because only a dry-run was performed.
94 PROMPT_NOT_SHOWN, 66 PROMPT_NOT_SHOWN,
95 PROMPT_ACTION_RESET, 67 PROMPT_ACTION_RESET,
96 PROMPT_ACTION_NO_RESET, 68 PROMPT_ACTION_NO_RESET,
97 PROMPT_DISMISSED, 69 PROMPT_DISMISSED,
98 // Prompt was still shown (not dismissed by the user) when Chrome was closed. 70 // Prompt was still shown (not dismissed by the user) when Chrome was closed.
99 PROMPT_IGNORED, 71 PROMPT_IGNORED,
100 PROMPT_RESULT_MAX 72 PROMPT_RESULT_MAX
101 }; 73 };
102 74
75 // Returns whether or not a dry-run shall be performed.
76 bool ShouldPerformDryRun() {
77 return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) ==
78 kAutomaticProfileResetStudyDryRunGroupName;
79 }
80
81 // Returns whether or not a live-run shall be performed.
82 bool ShouldPerformLiveRun() {
83 return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) ==
84 kAutomaticProfileResetStudyEnabledGroupName;
85 }
86
87 // Deep-copies all preferences in |source| to a sub-tree named |value_tree_key|
88 // in |target_dictionary|, with path expansion, and also creates an isomorphic
89 // sub-tree under the key |is_user_controlled_tree_key| that contains only
90 // Boolean values, indicating whether or not the corresponding preferences are
91 // coming from the 'user' PrefStore.
92 void BuildSubTreesFromPreferences(const PrefService* source,
93 const char* value_tree_key,
94 const char* is_user_controlled_tree_key,
95 base::DictionaryValue* target_dictionary) {
96 scoped_ptr<base::DictionaryValue> pref_name_to_value_map(
97 source->GetPreferenceValuesWithoutPathExpansion());
98 std::vector<std::string> pref_names;
99 pref_names.reserve(pref_name_to_value_map->size());
100 for (base::DictionaryValue::Iterator it(*pref_name_to_value_map);
101 !it.IsAtEnd();
102 it.Advance()) {
103 pref_names.push_back(it.key());
104 }
105 base::DictionaryValue* value_tree = new base::DictionaryValue;
106 base::DictionaryValue* is_user_controlled_tree = new base::DictionaryValue;
107 for (std::vector<std::string>::const_iterator it = pref_names.begin();
108 it != pref_names.end();
109 ++it) {
110 scoped_ptr<Value> pref_value_owned;
111 if (pref_name_to_value_map->RemoveWithoutPathExpansion(*it,
112 &pref_value_owned)) {
113 value_tree->Set(*it, pref_value_owned.release());
114 const PrefService::Preference* pref = source->FindPreference(it->c_str());
115 is_user_controlled_tree->Set(
116 *it, new base::FundamentalValue(pref->IsUserControlled()));
117 }
118 }
119 target_dictionary->Set(value_tree_key, value_tree);
120 target_dictionary->Set(is_user_controlled_tree_key, is_user_controlled_tree);
121 }
122
103 } // namespace 123 } // namespace
104 124
105 // AutomaticProfileResetter::EvaluationResults ------------------------------- 125 // AutomaticProfileResetter::EvaluationResults -------------------------------
106 126
107 // Encapsulates the output values extracted from the evaluator program. 127 // Encapsulates the output values extracted from the evaluator program.
108 struct AutomaticProfileResetter::EvaluationResults { 128 struct AutomaticProfileResetter::EvaluationResults {
109 EvaluationResults() 129 EvaluationResults()
110 : had_prompted_already(false), 130 : had_prompted_already(false),
111 satisfied_criteria_mask(0), 131 satisfied_criteria_mask(0),
112 combined_status_mask(0) {} 132 combined_status_mask(0) {}
113 133
114 std::string memento_value_in_prefs; 134 std::string memento_value_in_prefs;
115 std::string memento_value_in_local_state; 135 std::string memento_value_in_local_state;
116 std::string memento_value_in_file; 136 std::string memento_value_in_file;
117 137
118 bool had_prompted_already; 138 bool had_prompted_already;
119 uint32 satisfied_criteria_mask; 139 uint32 satisfied_criteria_mask;
120 uint32 combined_status_mask; 140 uint32 combined_status_mask;
121 }; 141 };
122 142
123 // AutomaticProfileResetter -------------------------------------------------- 143 // AutomaticProfileResetter --------------------------------------------------
124 144
145 const size_t AutomaticProfileResetter::kSatisfiedCriteriaMaskNumberOfBits = 2u;
146 const uint32 AutomaticProfileResetter::kSatisfiedCriteriaMaskMaximumValue =
147 (1u << AutomaticProfileResetter::kSatisfiedCriteriaMaskNumberOfBits);
148
149 const size_t AutomaticProfileResetter::kCombinedStatusMaskNumberOfBits = 4u;
150 const uint32 AutomaticProfileResetter::kCombinedStatusMaskMaximumValue =
151 (1u << AutomaticProfileResetter::kCombinedStatusMaskNumberOfBits);
152
153 COMPILE_ASSERT(arraysize(kSatisfiedCriteriaMaskKeys) ==
154 AutomaticProfileResetter::kSatisfiedCriteriaMaskNumberOfBits,
155 satisfied_criteria_mask_bits_mismatch);
156 COMPILE_ASSERT(arraysize(kCombinedStatusMaskKeys) ==
157 AutomaticProfileResetter::kCombinedStatusMaskNumberOfBits,
158 combined_status_mask_bits_mismatch);
159
125 AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile) 160 AutomaticProfileResetter::AutomaticProfileResetter(Profile* profile)
126 : profile_(profile), 161 : profile_(profile),
127 state_(STATE_UNINITIALIZED), 162 state_(STATE_UNINITIALIZED),
163 enumeration_of_loaded_modules_ready_(false),
164 template_url_service_ready_(false),
128 memento_in_prefs_(profile_), 165 memento_in_prefs_(profile_),
129 memento_in_local_state_(profile_), 166 memento_in_local_state_(profile_),
130 memento_in_file_(profile_), 167 memento_in_file_(profile_),
131 weak_ptr_factory_(this) { 168 weak_ptr_factory_(this) {
132 DCHECK(profile_); 169 DCHECK(profile_);
170 Initialize();
133 } 171 }
134 172
135 AutomaticProfileResetter::~AutomaticProfileResetter() {} 173 AutomaticProfileResetter::~AutomaticProfileResetter() {}
136 174
137 void AutomaticProfileResetter::Initialize() { 175 void AutomaticProfileResetter::Initialize() {
138 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
139 DCHECK_EQ(state_, STATE_UNINITIALIZED); 177 DCHECK_EQ(state_, STATE_UNINITIALIZED);
140 178
141 if (ShouldPerformDryRun() || ShouldPerformLiveRun()) { 179 if (ShouldPerformDryRun() || ShouldPerformLiveRun()) {
142 ui::ResourceBundle& resources(ui::ResourceBundle::GetSharedInstance()); 180 ui::ResourceBundle& resources(ui::ResourceBundle::GetSharedInstance());
143 if (ShouldPerformLiveRun()) { 181 if (ShouldPerformLiveRun()) {
144 program_ = 182 program_ =
145 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_RULES); 183 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_RULES);
146 hash_seed_ = 184 hash_seed_ =
147 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED); 185 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED);
148 } else { // ShouldPerformDryRun() 186 } else { // ShouldPerformDryRun()
149 program_ = 187 program_ =
150 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY); 188 resources.GetRawDataResource(IDR_AUTOMATIC_PROFILE_RESET_RULES_DRY);
151 hash_seed_ = resources.GetRawDataResource( 189 hash_seed_ = resources.GetRawDataResource(
152 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY); 190 IDR_AUTOMATIC_PROFILE_RESET_HASH_SEED_DRY);
153 } 191 }
154 delegate_.reset(new AutomaticProfileResetterDelegateImpl()); 192 delegate_.reset(new AutomaticProfileResetterDelegateImpl(profile_));
193 task_runner_for_waiting_ =
194 content::BrowserThread::GetMessageLoopProxyForThread(
195 content::BrowserThread::UI);
196 state_ = STATE_INITIALIZED;
197 } else {
198 state_ = STATE_DISABLED;
199 }
200 }
155 201
202 void AutomaticProfileResetter::Activate() {
203 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
204 DCHECK(state_ == STATE_INITIALIZED || state_ == STATE_DISABLED);
205
206 if (state_ == STATE_INITIALIZED) {
207 if (!program_.empty()) {
208 // Some steps in the flow (e.g. loaded modules, file-based memento) are
209 // IO-intensive, so defer execution until some time later.
210 task_runner_for_waiting_->PostDelayedTask(
211 FROM_HERE,
212 base::Bind(&AutomaticProfileResetter::PrepareEvaluationFlow,
213 weak_ptr_factory_.GetWeakPtr()),
214 base::TimeDelta::FromSeconds(kEvaluationFlowDelayInSeconds));
215 } else {
216 // Terminate early if there is no program included (nor set by tests).
217 state_ = STATE_DISABLED;
218 }
219 }
220 }
221
222 void AutomaticProfileResetter::PrepareEvaluationFlow() {
223 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
224 DCHECK_EQ(state_, STATE_INITIALIZED);
225
226 state_ = STATE_WAITING_ON_DEPENDENCIES;
227
228 delegate_->RequestCallbackWhenTemplateURLServiceIsLoaded(
229 base::Bind(&AutomaticProfileResetter::OnTemplateURLServiceIsLoaded,
230 weak_ptr_factory_.GetWeakPtr()));
231 delegate_->RequestCallbackWhenLoadedModulesAreEnumerated(
232 base::Bind(&AutomaticProfileResetter::OnLoadedModulesAreEnumerated,
233 weak_ptr_factory_.GetWeakPtr()));
234 delegate_->LoadTemplateURLServiceIfNeeded();
235 delegate_->EnumerateLoadedModulesIfNeeded();
236 }
237
238 void AutomaticProfileResetter::OnTemplateURLServiceIsLoaded() {
239 template_url_service_ready_ = true;
240 OnDependencyIsReady();
241 }
242
243 void AutomaticProfileResetter::OnLoadedModulesAreEnumerated() {
244 enumeration_of_loaded_modules_ready_ = true;
245 OnDependencyIsReady();
246 }
247
248 void AutomaticProfileResetter::OnDependencyIsReady() {
249 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
250 DCHECK_EQ(state_, STATE_WAITING_ON_DEPENDENCIES);
251
252 if (template_url_service_ready_ && enumeration_of_loaded_modules_ready_) {
156 state_ = STATE_READY; 253 state_ = STATE_READY;
157
158 content::BrowserThread::PostTask( 254 content::BrowserThread::PostTask(
159 content::BrowserThread::UI, 255 content::BrowserThread::UI,
160 FROM_HERE, 256 FROM_HERE,
161 base::Bind(&AutomaticProfileResetter::BeginEvaluationFlow, 257 base::Bind(&AutomaticProfileResetter::BeginEvaluationFlow,
162 weak_ptr_factory_.GetWeakPtr())); 258 weak_ptr_factory_.GetWeakPtr()));
163 } else {
164 state_ = STATE_DISABLED;
165 } 259 }
166 } 260 }
167 261
168 bool AutomaticProfileResetter::ShouldPerformDryRun() const {
169 return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) ==
170 kAutomaticProfileResetStudyDryRunGroupName;
171 }
172
173 bool AutomaticProfileResetter::ShouldPerformLiveRun() const {
174 return base::FieldTrialList::FindFullName(kAutomaticProfileResetStudyName) ==
175 kAutomaticProfileResetStudyEnabledGroupName;
176 }
177
178 void AutomaticProfileResetter::BeginEvaluationFlow() { 262 void AutomaticProfileResetter::BeginEvaluationFlow() {
179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 263 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
180 DCHECK_EQ(state_, STATE_READY); 264 DCHECK_EQ(state_, STATE_READY);
265 DCHECK(!program_.empty());
181 266
182 if (!program_.empty()) { 267 state_ = STATE_WORKING;
183 state_ = STATE_WORKING; 268 memento_in_file_.ReadValue(
184 memento_in_file_.ReadValue( 269 base::Bind(&AutomaticProfileResetter::ContinueWithEvaluationFlow,
185 base::Bind(&AutomaticProfileResetter::ContinueWithEvaluationFlow, 270 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 } 271 }
192 272
193 scoped_ptr<base::DictionaryValue> 273 scoped_ptr<base::DictionaryValue>
194 AutomaticProfileResetter::BuildEvaluatorProgramInput( 274 AutomaticProfileResetter::BuildEvaluatorProgramInput(
195 const std::string& memento_value_in_file) { 275 const std::string& memento_value_in_file) {
196 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 276 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
197 // TODO(engedy): Add any additional state here that is needed by the program. 277
198 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue); 278 scoped_ptr<base::DictionaryValue> input(new base::DictionaryValue);
279
280 // Include memento values (or empty strings in case mementos are not there).
199 input->SetString(kMementoValueInPrefsKey, memento_in_prefs_.ReadValue()); 281 input->SetString(kMementoValueInPrefsKey, memento_in_prefs_.ReadValue());
200 input->SetString(kMementoValueInLocalStateKey, 282 input->SetString(kMementoValueInLocalStateKey,
201 memento_in_local_state_.ReadValue()); 283 memento_in_local_state_.ReadValue());
202 input->SetString(kMementoValueInFileKey, memento_value_in_file); 284 input->SetString(kMementoValueInFileKey, memento_value_in_file);
285
286 // Include all user (i.e. profile-specific) preferences, along with
287 // information about whether the value is coming from the 'user' PrefStore.
288 PrefService* prefs = profile_->GetPrefs();
289 DCHECK(prefs);
290 BuildSubTreesFromPreferences(prefs,
291 kUserPreferencesKey,
292 kUserPreferencesIsUserControlledKey,
293 input.get());
294
295 // Include all local state (i.e. shared) preferences, along with information
296 // about whether the value is coming from the 'user' PrefStore.
297 PrefService* local_state = g_browser_process->local_state();
298 DCHECK(local_state);
299 BuildSubTreesFromPreferences(
300 local_state, kLocalStateKey, kLocalStateIsUserControlledKey, input.get());
301
302 // Include all information related to search engines.
303 base::DictionaryValue* default_search_provider_details =
304 delegate_->GetDefaultSearchProviderDetails();
305 if (default_search_provider_details)
306 input->Set(kDefaultSearchProviderKey, default_search_provider_details);
307
308 base::ListValue* search_providers_details =
309 delegate_->GetPrepopulatedSearchProvidersDetails();
310 if (search_providers_details)
311 input->Set(kSearchProvidersKey, search_providers_details);
312
313 input->SetBoolean(kDefaultSearchProviderIsUserControlledKey,
314 !delegate_->IsDefaultSearchProviderManaged());
315
316 // Include information about loaded modules.
317 base::ListValue* loaded_module_digests =
318 delegate_->GetLoadedModuleNameDigests();
319 if (loaded_module_digests)
320 input->Set(kLoadedModuleDigestsKey, loaded_module_digests);
321
203 return input.Pass(); 322 return input.Pass();
204 } 323 }
205 324
206 void AutomaticProfileResetter::ContinueWithEvaluationFlow( 325 void AutomaticProfileResetter::ContinueWithEvaluationFlow(
207 const std::string& memento_value_in_file) { 326 const std::string& memento_value_in_file) {
208 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 327 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
209 DCHECK_EQ(state_, STATE_WORKING); 328 DCHECK_EQ(state_, STATE_WORKING);
210 PrefService* prefs = profile_->GetPrefs(); 329 PrefService* prefs = profile_->GetPrefs();
211 DCHECK(prefs); 330 DCHECK(prefs);
212 331
(...skipping 26 matching lines...) Expand all
239 std::string hash_seed_str(hash_seed.as_string()); 358 std::string hash_seed_str(hash_seed.as_string());
240 std::string program_str(program.as_string()); 359 std::string program_str(program.as_string());
241 JtlInterpreter interpreter(hash_seed_str, program_str, program_input.get()); 360 JtlInterpreter interpreter(hash_seed_str, program_str, program_input.get());
242 interpreter.Execute(); 361 interpreter.Execute();
243 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.InterpreterResult", 362 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.InterpreterResult",
244 interpreter.result(), 363 interpreter.result(),
245 JtlInterpreter::RESULT_MAX); 364 JtlInterpreter::RESULT_MAX);
246 365
247 // In each case below, the respective field in result originally contains the 366 // 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. 367 // default, so if the getter fails, we still have the correct value there.
249 scoped_ptr<EvaluationResults> results(new EvaluationResults()); 368 scoped_ptr<EvaluationResults> results(new EvaluationResults);
250 interpreter.GetOutputBoolean(kHadPromptedAlreadyKey, 369 interpreter.GetOutputBoolean(kHadPromptedAlreadyKey,
251 &results->had_prompted_already); 370 &results->had_prompted_already);
252 interpreter.GetOutputString(kMementoValueInPrefsKey, 371 interpreter.GetOutputString(kMementoValueInPrefsKey,
253 &results->memento_value_in_prefs); 372 &results->memento_value_in_prefs);
254 interpreter.GetOutputString(kMementoValueInLocalStateKey, 373 interpreter.GetOutputString(kMementoValueInLocalStateKey,
255 &results->memento_value_in_local_state); 374 &results->memento_value_in_local_state);
256 interpreter.GetOutputString(kMementoValueInFileKey, 375 interpreter.GetOutputString(kMementoValueInFileKey,
257 &results->memento_value_in_file); 376 &results->memento_value_in_file);
258 for (size_t i = 0; i < arraysize(kCombinedStatusMaskKeys); ++i) { 377 for (size_t i = 0; i < arraysize(kCombinedStatusMaskKeys); ++i) {
259 bool flag = false; 378 bool flag = false;
260 if (interpreter.GetOutputBoolean(kCombinedStatusMaskKeys[i], &flag) && flag) 379 if (interpreter.GetOutputBoolean(kCombinedStatusMaskKeys[i], &flag) && flag)
261 results->combined_status_mask |= (1 << i); 380 results->combined_status_mask |= (1 << i);
262 } 381 }
263 for (size_t i = 0; i < arraysize(kSatisfiedCriteriaMaskKeys); ++i) { 382 for (size_t i = 0; i < arraysize(kSatisfiedCriteriaMaskKeys); ++i) {
264 bool flag = false; 383 bool flag = false;
265 if (interpreter.GetOutputBoolean(kSatisfiedCriteriaMaskKeys[i], &flag) && 384 if (interpreter.GetOutputBoolean(kSatisfiedCriteriaMaskKeys[i], &flag) &&
266 flag) 385 flag)
267 results->satisfied_criteria_mask |= (1 << i); 386 results->satisfied_criteria_mask |= (1 << i);
268 } 387 }
269 return results.Pass(); 388 return results.Pass();
270 } 389 }
271 390
272 void AutomaticProfileResetter::FinishEvaluationFlow( 391 void AutomaticProfileResetter::FinishEvaluationFlow(
273 scoped_ptr<EvaluationResults> results) { 392 scoped_ptr<EvaluationResults> results) {
274 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 393 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
275 DCHECK_EQ(state_, STATE_WORKING); 394 DCHECK_EQ(state_, STATE_WORKING);
276 395
277 delegate_->ReportStatistics(results->satisfied_criteria_mask, 396 ReportStatistics(results->satisfied_criteria_mask,
278 results->combined_status_mask); 397 results->combined_status_mask);
279 398
280 if (results->satisfied_criteria_mask != 0 && !results->had_prompted_already) { 399 if (results->satisfied_criteria_mask != 0 && !results->had_prompted_already) {
281 memento_in_prefs_.StoreValue(results->memento_value_in_prefs); 400 memento_in_prefs_.StoreValue(results->memento_value_in_prefs);
282 memento_in_local_state_.StoreValue(results->memento_value_in_local_state); 401 memento_in_local_state_.StoreValue(results->memento_value_in_local_state);
283 memento_in_file_.StoreValue(results->memento_value_in_file); 402 memento_in_file_.StoreValue(results->memento_value_in_file);
284 403
285 if (ShouldPerformLiveRun()) { 404 if (ShouldPerformLiveRun()) {
286 delegate_->ShowPrompt(); 405 delegate_->ShowPrompt();
287 } else { 406 } else {
288 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.PromptResult", 407 UMA_HISTOGRAM_ENUMERATION("AutomaticProfileReset.PromptResult",
289 PROMPT_NOT_SHOWN, 408 PROMPT_NOT_SHOWN,
290 PROMPT_RESULT_MAX); 409 PROMPT_RESULT_MAX);
291 } 410 }
292 } 411 }
293 412
294 state_ = STATE_DONE; 413 state_ = STATE_DONE;
295 } 414 }
296 415
416 void AutomaticProfileResetter::ReportStatistics(uint32 satisfied_criteria_mask,
417 uint32 combined_status_mask) {
418 UMA_HISTOGRAM_ENUMERATION(
419 "AutomaticProfileReset.SatisfiedCriteriaMask",
420 satisfied_criteria_mask,
421 AutomaticProfileResetter::kSatisfiedCriteriaMaskMaximumValue);
422 UMA_HISTOGRAM_ENUMERATION(
423 "AutomaticProfileReset.CombinedStatusMask",
424 combined_status_mask,
425 AutomaticProfileResetter::kCombinedStatusMaskMaximumValue);
426 }
427
297 void AutomaticProfileResetter::SetHashSeedForTesting( 428 void AutomaticProfileResetter::SetHashSeedForTesting(
298 const base::StringPiece& hash_key) { 429 const base::StringPiece& hash_key) {
299 hash_seed_ = hash_key; 430 hash_seed_ = hash_key;
300 } 431 }
301 432
302 void AutomaticProfileResetter::SetProgramForTesting( 433 void AutomaticProfileResetter::SetProgramForTesting(
303 const base::StringPiece& program) { 434 const base::StringPiece& program) {
304 program_ = program; 435 program_ = program;
305 } 436 }
306 437
307 void AutomaticProfileResetter::SetDelegateForTesting( 438 void AutomaticProfileResetter::SetDelegateForTesting(
308 AutomaticProfileResetterDelegate* delegate) { 439 AutomaticProfileResetterDelegate* delegate) {
309 delegate_.reset(delegate); 440 delegate_.reset(delegate);
310 } 441 }
311 442
443 void AutomaticProfileResetter::SetTaskRunnerForWaitingForTesting(
444 const scoped_refptr<base::TaskRunner>& task_runner) {
445 task_runner_for_waiting_ = task_runner;
446 }
447
312 void AutomaticProfileResetter::Shutdown() { 448 void AutomaticProfileResetter::Shutdown() {
313 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 449 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
314 450
315 state_ = STATE_DISABLED; 451 state_ = STATE_DISABLED;
316 delegate_.reset(); 452 delegate_.reset();
317 weak_ptr_factory_.InvalidateWeakPtrs(); 453 weak_ptr_factory_.InvalidateWeakPtrs();
318 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698