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 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
6 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 6 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 // triggering the prompt. To ensure that the prompt only appears at most once | 29 // triggering the prompt. To ensure that the prompt only appears at most once |
30 // for any given profile, a "memento" that the prompt has appeared is written to | 30 // for any given profile, a "memento" that the prompt has appeared is written to |
31 // the profile on disk; see automatic_profile_resetter_mementos.h for details. | 31 // the profile on disk; see automatic_profile_resetter_mementos.h for details. |
32 // The service is created automatically with the Profile and is activated right | 32 // The service is created automatically with the Profile and is activated right |
33 // away by its factory. To avoid delaying start-up, however, it will only start | 33 // away by its factory. To avoid delaying start-up, however, it will only start |
34 // working after a short delay. | 34 // working after a short delay. |
35 // All methods in this class shall be called on the UI thread, except when noted | 35 // All methods in this class shall be called on the UI thread, except when noted |
36 // otherwise. | 36 // otherwise. |
37 class AutomaticProfileResetter : public BrowserContextKeyedService { | 37 class AutomaticProfileResetter : public BrowserContextKeyedService { |
38 public: | 38 public: |
39 // Enumeration of the possible outcomes of showing the profile reset prompt. | |
40 enum PromptResult { | |
41 // Prompt was not shown because only a dry-run was performed, or because it | |
42 // was not supported on the current platform. | |
43 PROMPT_NOT_SHOWN, | |
44 PROMPT_ACTION_RESET, | |
45 PROMPT_ACTION_NO_RESET, | |
46 // The prompt was shown, but the user dismissed the reset bubble without | |
47 // taking definitive action (selecting either "Reset" or "No, thanks"). | |
48 // Note: deprecated in favor of the following three items. | |
49 PROMPT_DISMISSED, | |
50 // The reset bubble was still shown; or dismissed without taking definitive | |
51 // action when Chrome was closed. | |
52 PROMPT_IGNORED, | |
53 // The reset bubble was shown, then dismissed without taking definitive | |
54 // action. Then, however, the user initiated or refrained from (resp.) doing | |
55 // a reset from the conventional, WebUI-based reset dialog. | |
56 PROMPT_FOLLOWED_BY_WEBUI_RESET, | |
57 PROMPT_FOLLOWED_BY_WEBUI_NO_RESET, | |
58 // The reset bubble was suppressed (not shown) because another bubble was | |
59 // already being shown at the time. Regardless, however, the user initiated | |
MAD
2013/11/11 16:38:32
Is another bubble (will always be) the only reason
engedy
2013/11/13 00:40:44
For the foreseeable future, yes. Regarding later,
| |
60 // or refrained from (resp.) doing a reset from the conventional, WebUI- | |
61 // based reset dialog. | |
62 PROMPT_SUPPRESSED_BUT_HAD_WEBUI_RESET, | |
63 PROMPT_SUPPRESSED_BUT_HAD_WEBUI_NO_RESET, | |
64 PROMPT_RESULT_MAX | |
65 }; | |
66 | |
39 explicit AutomaticProfileResetter(Profile* profile); | 67 explicit AutomaticProfileResetter(Profile* profile); |
40 virtual ~AutomaticProfileResetter(); | 68 virtual ~AutomaticProfileResetter(); |
41 | 69 |
42 // Initializes the service if it is enabled in the field trial. Otherwise, | 70 // Initializes the service if it is enabled in the field trial. Otherwise, |
43 // skips the initialization steps, and also permanently disables the service. | 71 // skips the initialization steps, and also permanently disables the service. |
44 // Called by AutomaticProfileResetterFactory. | 72 // Called by AutomaticProfileResetterFactory. |
45 void Initialize(); | 73 void Initialize(); |
46 | 74 |
47 // Fires up the service by unleashing the asynchronous evaluation flow, unless | 75 // Fires up the service by unleashing the asynchronous evaluation flow, unless |
48 // the service has been already disabled in Initialize() or there is no | 76 // the service has been already disabled in Initialize() or there is no |
49 // |program_| to run (in which case the service also gets disabled). | 77 // |program_| to run (in which case the service also gets disabled). |
50 // Called by the AutomaticProfileResetterFactory. | 78 // Called by the AutomaticProfileResetterFactory. |
51 void Activate(); | 79 void Activate(); |
52 | 80 |
81 // Called synchronously by ProfileResetGlobalError in case the user chooses to | |
82 // reset their profile settings from inside the reset bubble. Will trigger the | |
83 // reset, optionally |send_feedback|, and conclude the reset prompt flow. | |
84 void TriggerProfileReset(bool send_feedback); | |
85 | |
86 // Called synchronously by ProfileResetGlobalError in case the user chooses | |
87 // from inside the reset bubble that they do not want to reset their profile | |
88 // settings. Will conclude the reset prompt flow without setting off a reset. | |
89 void SkipProfileReset(); | |
90 | |
91 // Returns whether or not the profile reset prompt flow is currently active. | |
92 // See BeginResetPromptFlow() for a description of what this means. | |
93 bool IsResetPromptActive() const; | |
94 | |
95 // Called synchronously by ProfileResetGlobalError to give notice that the | |
96 // reset bubble has actually been shown. | |
97 void NotifyDidShowResetBubble(); | |
98 | |
99 // Called by ResetProfileSettingsHandler to give notice that the conventional, | |
100 // WebUI-based settings reset dialog has been opened. This will already | |
101 // dismiss the menu item in the wrench menu. This should be always followed by | |
102 // a corresponding NotifyDidCloseWebUIResetDialog() call. | |
103 void NotifyDidOpenWebUIResetDialog(); | |
104 | |
105 // Called by ResetProfileSettingsHandler to give notice that the conventional, | |
106 // WebUI-based settings reset dialog has been closed, with |performed_reset| | |
107 // indicating whether or not a reset was requested. This is required so that | |
108 // we can record the appropriate PromptResult, and conclude the reset prompt | |
109 // flow early without setting off any more resets in the future. | |
110 void NotifyDidCloseWebUIResetDialog(bool performed_reset); | |
111 | |
112 base::WeakPtr<AutomaticProfileResetter> AsWeakPtr() { | |
113 return weak_ptr_factory_.GetWeakPtr(); | |
114 } | |
115 | |
116 // BrowserContextKeyedService: | |
117 virtual void Shutdown() OVERRIDE; | |
118 | |
53 // Should be called before Activate(). | 119 // Should be called before Activate(). |
54 void SetProgramForTesting(const std::string& program); | 120 void SetProgramForTesting(const std::string& program); |
55 | 121 |
56 // Should be called before Activate(). | 122 // Should be called before Activate(). |
57 void SetHashSeedForTesting(const std::string& hash_seed); | 123 void SetHashSeedForTesting(const std::string& hash_seed); |
58 | 124 |
59 // Should be called before Activate(). | 125 // Should be called before Activate(). |
60 void SetDelegateForTesting( | 126 void SetDelegateForTesting( |
61 scoped_ptr<AutomaticProfileResetterDelegate> delegate); | 127 scoped_ptr<AutomaticProfileResetterDelegate> delegate); |
62 | 128 |
63 // Should be called before Activate(). Sets the task runner to be used to post | 129 // Should be called before Activate(). Sets the task runner to be used to post |
64 // task |PrepareEvaluationFlow| in a delayed manner. | 130 // task |PrepareEvaluationFlow| in a delayed manner. |
65 void SetTaskRunnerForWaitingForTesting( | 131 void SetTaskRunnerForWaitingForTesting( |
66 const scoped_refptr<base::TaskRunner>& task_runner); | 132 const scoped_refptr<base::TaskRunner>& task_runner); |
67 | 133 |
68 private: | 134 private: |
69 struct EvaluationResults; | 135 struct EvaluationResults; |
70 | 136 |
71 enum State { | 137 enum State { |
72 STATE_UNINITIALIZED, | 138 STATE_UNINITIALIZED, |
73 STATE_INITIALIZED, | 139 STATE_INITIALIZED, |
74 STATE_DISABLED, | 140 STATE_DISABLED, |
75 STATE_WAITING_ON_DEPENDENCIES, | 141 STATE_WAITING_ON_DEPENDENCIES, |
76 STATE_READY, | 142 STATE_READY, |
77 STATE_WORKING, | 143 STATE_EVALUATING_CONDITIONS, |
144 // The reset prompt can always be active in the next two states. | |
145 // can only possible received (synchronous) call-backs from it here. | |
MAD
2013/11/11 16:38:32
"can only possible received"?
please rephrase...
engedy
2013/11/13 00:40:44
Reworked this part.
| |
146 STATE_AWAITING_USER_CHOICE, | |
147 STATE_PERFORMING_RESET, | |
78 STATE_DONE | 148 STATE_DONE |
79 }; | 149 }; |
80 | 150 |
81 // Prepares the asynchronous evaluation flow by requesting services that it | 151 // Prepares the asynchronous evaluation flow by requesting services that it |
82 // depends on to make themselves ready. | 152 // depends on to make themselves ready. |
83 void PrepareEvaluationFlow(); | 153 void PrepareEvaluationFlow(); |
84 | 154 |
85 // Called back by |resetter_delegate_| when the template URL service is ready. | 155 // Called back by |resetter_delegate_| when the template URL service is ready. |
86 void OnTemplateURLServiceIsLoaded(); | 156 void OnTemplateURLServiceIsLoaded(); |
87 | 157 |
(...skipping 24 matching lines...) Expand all Loading... | |
112 // |program| that will evaluate whether the conditions are met for showing the | 182 // |program| that will evaluate whether the conditions are met for showing the |
113 // reset prompt. The program will make this decision based on the state | 183 // reset prompt. The program will make this decision based on the state |
114 // information contained in |input| in the form of key-value pairs. The | 184 // information contained in |input| in the form of key-value pairs. The |
115 // program will only see hashed keys and values that are produced using | 185 // program will only see hashed keys and values that are produced using |
116 // |hash_seed| as a key. | 186 // |hash_seed| as a key. |
117 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( | 187 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( |
118 const std::string& hash_seed, | 188 const std::string& hash_seed, |
119 const std::string& program, | 189 const std::string& program, |
120 scoped_ptr<base::DictionaryValue> program_input); | 190 scoped_ptr<base::DictionaryValue> program_input); |
121 | 191 |
122 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing | |
123 // the program with |results|. Finishes the evaluation flow, and, based on the | |
124 // result, will potentially show the reset prompt. | |
125 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); | |
126 | |
127 // Reports the given metrics through UMA. Virtual, so it can be mocked out in | 192 // Reports the given metrics through UMA. Virtual, so it can be mocked out in |
128 // tests to verify that the correct value are being reported. | 193 // tests to verify that the correct value are being reported. |
129 virtual void ReportStatistics(uint32 satisfied_criteria_mask, | 194 virtual void ReportStatistics(uint32 satisfied_criteria_mask, |
130 uint32 combined_status_mask); | 195 uint32 combined_status_mask); |
131 | 196 |
132 // BrowserContextKeyedService: | 197 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing |
133 virtual void Shutdown() OVERRIDE; | 198 // the program with |results|. Finishes the evaluation flow, and, based on the |
199 // result, potentially initiates the reset prompt flow. | |
200 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); | |
201 | |
202 // Begins the reset prompt flow by triggering the reset prompt, which consists | |
203 // of two parts: (1.) the profile reset (pop-up) bubble, and (2.) a menu item | |
204 // in the wrench menu. | |
205 // The flow is considered to be "active" until we receive a clear indication | |
206 // from the user about whether or not they wish to reset their settings. This | |
207 // indication can come in a variety of flavors: | |
208 // * taking definitive action (i.e. selecting either "Reset" or "No, thanks") | |
209 // in the pop-up reset bubble itself, | |
210 // * dismissing the bubble, but then selecting the wrench menu item, which | |
211 // takes them to the WebUI reset dialog in chrome://settings, and then | |
212 // making their choice there, | |
213 // * going to the WebUI reset dialog by themselves. | |
214 void BeginResetPromptFlow(); | |
215 | |
216 // Called back by the ProfileResetter once resetting the profile settings has | |
217 // been completed, when requested by the user from inside the reset bubble. | |
218 // Will conclude the reset prompt flow. | |
219 void OnProfileSettingsResetCompleted(); | |
220 | |
221 // Reports the result of showing the prompt through UMA. Virtual, so it can be | |
222 // mocked out in tests to verify that the correct value is being reported. | |
223 virtual void ReportPromptResult(PromptResult result); | |
224 | |
225 // Dismisses the reset prompt and concludes the reset prompt flow with | |
226 // |prompt_result|, then persists the memento values returned by the evaluator | |
227 // program to disk. | |
228 void FinishResetPromptFlow(PromptResult prompt_result); | |
134 | 229 |
135 Profile* profile_; | 230 Profile* profile_; |
136 | 231 |
137 State state_; | 232 State state_; |
138 bool enumeration_of_loaded_modules_ready_; | 233 bool enumeration_of_loaded_modules_ready_; |
139 bool template_url_service_ready_; | 234 bool template_url_service_ready_; |
235 bool has_shown_bubble_; | |
140 | 236 |
141 std::string hash_seed_; | 237 std::string hash_seed_; |
142 std::string program_; | 238 std::string program_; |
143 | 239 |
240 scoped_ptr<EvaluationResults> evaluation_results_; | |
241 | |
144 PreferenceHostedPromptMemento memento_in_prefs_; | 242 PreferenceHostedPromptMemento memento_in_prefs_; |
145 LocalStateHostedPromptMemento memento_in_local_state_; | 243 LocalStateHostedPromptMemento memento_in_local_state_; |
146 FileHostedPromptMemento memento_in_file_; | 244 FileHostedPromptMemento memento_in_file_; |
147 | 245 |
148 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; | 246 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; |
149 scoped_refptr<base::TaskRunner> task_runner_for_waiting_; | 247 scoped_refptr<base::TaskRunner> task_runner_for_waiting_; |
150 | 248 |
151 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; | 249 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; |
152 | 250 |
153 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); | 251 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); |
154 }; | 252 }; |
155 | 253 |
156 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 254 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
OLD | NEW |