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 listing the possible outcomes of triggering the profile reset | |
40 // prompt. | |
41 enum PromptResult { | |
42 // The reset prompt was not triggered because only a dry-run was performed, | |
43 // or because it was not supported on the current platform. | |
44 PROMPT_NOT_TRIGGERED, | |
45 // The reset bubble actually got shown. In contrast to the wrench menu item | |
46 // that can always be shown, the bubble might be delayed or might never be | |
47 // shown if another bubble was shown at the time of triggering the prompt. | |
48 // This enumeration value is usually recorded in conjunction with another | |
49 // PromptResult, the absence of which indicates that the prompt was ignored. | |
50 PROMPT_SHOWN_BUBBLE, | |
51 // The user selected "Reset" or "No, thanks" (respectively) directly from | |
52 // within the bubble. | |
53 PROMPT_ACTION_RESET, | |
54 PROMPT_ACTION_NO_RESET, | |
55 // The reset bubble was shown, then dismissed without taking definitive | |
56 // action. Then, however, the user initiated or refrained from doing a reset | |
57 // (respectively) from the conventional, WebUI-based reset dialog. | |
58 PROMPT_FOLLOWED_BY_WEBUI_RESET, | |
59 PROMPT_FOLLOWED_BY_WEBUI_NO_RESET, | |
60 // The reset bubble was suppressed (not shown) because another bubble was | |
61 // already being shown at the time. Regardless, however, the user initiated | |
62 // or refrained from doing a reset (respectively) from the conventional, | |
63 // WebUI-based reset dialog. | |
64 PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_RESET, | |
65 PROMPT_NOT_SHOWN_BUBBLE_BUT_HAD_WEBUI_NO_RESET, | |
66 PROMPT_RESULT_MAX | |
67 }; | |
68 | |
39 explicit AutomaticProfileResetter(Profile* profile); | 69 explicit AutomaticProfileResetter(Profile* profile); |
40 virtual ~AutomaticProfileResetter(); | 70 virtual ~AutomaticProfileResetter(); |
41 | 71 |
42 // Initializes the service if it is enabled in the field trial. Otherwise, | 72 // Initializes the service if it is enabled in the field trial. Otherwise, |
43 // skips the initialization steps, and also permanently disables the service. | 73 // skips the initialization steps, and also permanently disables the service. |
44 // Called by AutomaticProfileResetterFactory. | 74 // Called by AutomaticProfileResetterFactory. |
45 void Initialize(); | 75 void Initialize(); |
46 | 76 |
47 // Fires up the service by unleashing the asynchronous evaluation flow, unless | 77 // Fires up the service by unleashing the asynchronous evaluation flow, unless |
48 // the service has been already disabled in Initialize() or there is no | 78 // the service has been already disabled in Initialize() or there is no |
49 // |program_| to run (in which case the service also gets disabled). | 79 // |program_| to run (in which case the service also gets disabled). |
50 // Called by the AutomaticProfileResetterFactory. | 80 // Called by the AutomaticProfileResetterFactory. |
51 void Activate(); | 81 void Activate(); |
52 | 82 |
83 // Called in case the user chooses to reset their profile settings from inside | |
84 // the reset bubble. Will trigger the reset, optionally |send_feedback|, and | |
85 // conclude the reset prompt flow. | |
86 void TriggerProfileReset(bool send_feedback); | |
87 | |
88 // Called in case the user chooses from inside the reset bubble that they do | |
89 // not want to reset their profile settings. Will conclude the reset prompt | |
90 // flow without setting off a reset. | |
91 void SkipProfileReset(); | |
92 | |
93 // Returns whether or not the profile reset prompt flow is currently active, | |
94 // that is, we have triggered the prompt and are waiting for the user to take | |
95 // definitive action (and we are not yet performing a reset). | |
96 bool IsResetPromptFlowActive() const; | |
97 | |
98 // Called to give notice that the reset bubble has actually been shown. | |
99 void NotifyDidShowResetBubble(); | |
100 | |
101 // Called to give notice that the conventional, WebUI-based settings reset | |
102 // dialog has been opened. This will dismiss the menu item in the wrench menu. | |
103 // This should always be followed by a corresponding call to | |
104 // NotifyDidCloseWebUIResetDialog(). | |
105 void NotifyDidOpenWebUIResetDialog(); | |
106 | |
107 // Called to give notice that the conventional, WebUI-based settings reset | |
108 // dialog has been closed, with |performed_reset| indicating whether or not a | |
109 // reset was requested. This is required so that we can record the appropriate | |
110 // PromptResult, dismiss the prompt, and conclude the reset prompt flow early | |
111 // without setting off any resets in the future. | |
112 void NotifyDidCloseWebUIResetDialog(bool performed_reset); | |
113 | |
114 base::WeakPtr<AutomaticProfileResetter> AsWeakPtr() { | |
115 return weak_ptr_factory_.GetWeakPtr(); | |
116 } | |
117 | |
53 // Should be called before Activate(). | 118 // Should be called before Activate(). |
54 void SetProgramForTesting(const std::string& program); | 119 void SetProgramForTesting(const std::string& program); |
55 | 120 |
56 // Should be called before Activate(). | 121 // Should be called before Activate(). |
57 void SetHashSeedForTesting(const std::string& hash_seed); | 122 void SetHashSeedForTesting(const std::string& hash_seed); |
58 | 123 |
59 // Should be called before Activate(). | 124 // Should be called before Activate(). |
60 void SetDelegateForTesting( | 125 void SetDelegateForTesting( |
61 scoped_ptr<AutomaticProfileResetterDelegate> delegate); | 126 scoped_ptr<AutomaticProfileResetterDelegate> delegate); |
62 | 127 |
63 // Should be called before Activate(). Sets the task runner to be used to post | 128 // Should be called before Activate(). Sets the task runner to be used to post |
64 // task |PrepareEvaluationFlow| in a delayed manner. | 129 // task |PrepareEvaluationFlow| in a delayed manner. |
65 void SetTaskRunnerForWaitingForTesting( | 130 void SetTaskRunnerForWaitingForTesting( |
66 const scoped_refptr<base::TaskRunner>& task_runner); | 131 const scoped_refptr<base::TaskRunner>& task_runner); |
67 | 132 |
133 // BrowserContextKeyedService: | |
134 virtual void Shutdown() OVERRIDE; | |
135 | |
68 private: | 136 private: |
69 class InputBuilder; | 137 class InputBuilder; |
70 struct EvaluationResults; | 138 struct EvaluationResults; |
71 | 139 |
72 enum State { | 140 enum State { |
73 STATE_UNINITIALIZED, | 141 STATE_UNINITIALIZED, |
74 STATE_INITIALIZED, | 142 STATE_INITIALIZED, |
75 STATE_DISABLED, | 143 STATE_DISABLED, |
76 STATE_WAITING_ON_DEPENDENCIES, | 144 STATE_WAITING_ON_DEPENDENCIES, |
77 STATE_READY, | 145 STATE_READY, |
78 STATE_WORKING, | 146 STATE_EVALUATING_CONDITIONS, |
147 STATE_HAS_TRIGGERED_PROMPT, | |
148 STATE_HAS_SHOWN_BUBBLE, | |
battre
2013/11/13 06:17:11
These two names are not 100% clear to me. what is
engedy
2013/11/13 13:24:30
Done.
| |
149 STATE_PERFORMING_RESET, | |
79 STATE_DONE | 150 STATE_DONE |
80 }; | 151 }; |
81 | 152 |
82 // Prepares the asynchronous evaluation flow by requesting services that it | 153 // Prepares the asynchronous evaluation flow by requesting services that it |
83 // depends on to make themselves ready. | 154 // depends on to make themselves ready. |
84 void PrepareEvaluationFlow(); | 155 void PrepareEvaluationFlow(); |
85 | 156 |
86 // Called back by |resetter_delegate_| when the template URL service is ready. | 157 // Called back by |resetter_delegate_| when the template URL service is ready. |
87 void OnTemplateURLServiceIsLoaded(); | 158 void OnTemplateURLServiceIsLoaded(); |
88 | 159 |
(...skipping 19 matching lines...) Expand all Loading... | |
108 // |program| that will evaluate whether the conditions are met for showing the | 179 // |program| that will evaluate whether the conditions are met for showing the |
109 // reset prompt. The program will make this decision based on the state | 180 // reset prompt. The program will make this decision based on the state |
110 // information contained in |input| in the form of key-value pairs. The | 181 // information contained in |input| in the form of key-value pairs. The |
111 // program will only see hashed keys and values that are produced using | 182 // program will only see hashed keys and values that are produced using |
112 // |hash_seed| as a key. | 183 // |hash_seed| as a key. |
113 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( | 184 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( |
114 const std::string& hash_seed, | 185 const std::string& hash_seed, |
115 const std::string& program, | 186 const std::string& program, |
116 scoped_ptr<base::DictionaryValue> program_input); | 187 scoped_ptr<base::DictionaryValue> program_input); |
117 | 188 |
118 // Called back when EvaluateConditionsOnWorkerPoolThread() completes executing | |
119 // the program with |results|. Finishes the evaluation flow, and, based on the | |
120 // result, will potentially show the reset prompt. | |
121 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); | |
122 | |
123 // Reports the given metrics through UMA. Virtual, so it can be mocked out in | 189 // Reports the given metrics through UMA. Virtual, so it can be mocked out in |
124 // tests to verify that the correct value are being reported. | 190 // tests to verify that the correct value are being reported. |
125 virtual void ReportStatistics(uint32 satisfied_criteria_mask, | 191 virtual void ReportStatistics(uint32 satisfied_criteria_mask, |
126 uint32 combined_status_mask); | 192 uint32 combined_status_mask); |
127 | 193 |
128 // BrowserContextKeyedService: | 194 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing |
129 virtual void Shutdown() OVERRIDE; | 195 // the program with |results|. Finishes the evaluation flow, and, based on the |
196 // result, potentially initiates the reset prompt flow. | |
197 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); | |
198 | |
199 // Begins the reset prompt flow by triggering the reset prompt, which consists | |
200 // of two parts: (1.) the profile reset (pop-up) bubble, and (2.) a menu item | |
201 // in the wrench menu (provided by a GlobalError). | |
202 // The flow lasts until we receive a clear indication from the user about | |
203 // whether or not they wish to reset their settings. This indication can come | |
204 // in a variety of flavors: | |
205 // * taking definitive action (i.e. selecting either "Reset" or "No, thanks") | |
206 // in the pop-up reset bubble itself, | |
207 // * dismissing the bubble, but then selecting the wrench menu item, which | |
208 // takes them to the WebUI reset dialog in chrome://settings, and then the | |
209 // user can make their choice there, | |
210 // * the user going to the WebUI reset dialog by themself. | |
211 // For the most part, the conclusion of the reset flow coincides with when the | |
212 // reset prompt is dismissed, with the one exception being that the prompt is | |
213 // closed as soon as the WebUI reset dialog is opened, we do not wait until | |
214 // the user actually makes a choice in that dialog. | |
215 void BeginResetPromptFlow(); | |
216 | |
217 // Called back by the ProfileResetter once resetting the profile settings has | |
218 // been completed, when requested by the user from inside the reset bubble. | |
219 // Will dismiss the prompt and conclude the reset prompt flow. | |
220 void OnProfileSettingsResetCompleted(); | |
221 | |
222 // Reports the result of triggering the prompt through UMA. Virtual, so it can | |
223 // be mocked out in tests to verify that the correct value is being reported. | |
224 virtual void ReportPromptResult(PromptResult result); | |
225 | |
226 // Writes the memento values returned by the evaluation program to disk, and | |
227 // then destroys |evaluation_results_|. | |
228 void PersistMementos(); | |
229 | |
230 // Concludes the reset prompt flow. | |
231 void FinishResetPromptFlow(); | |
130 | 232 |
131 Profile* profile_; | 233 Profile* profile_; |
132 | 234 |
133 State state_; | 235 State state_; |
134 bool enumeration_of_loaded_modules_ready_; | 236 bool enumeration_of_loaded_modules_ready_; |
135 bool template_url_service_ready_; | 237 bool template_url_service_ready_; |
238 bool has_already_dismissed_prompt_; | |
136 | 239 |
137 scoped_ptr<InputBuilder> input_builder_; | 240 scoped_ptr<InputBuilder> input_builder_; |
138 std::string hash_seed_; | 241 std::string hash_seed_; |
139 std::string program_; | 242 std::string program_; |
140 | 243 |
244 scoped_ptr<EvaluationResults> evaluation_results_; | |
245 | |
141 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; | 246 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; |
142 scoped_refptr<base::TaskRunner> task_runner_for_waiting_; | 247 scoped_refptr<base::TaskRunner> task_runner_for_waiting_; |
143 | 248 |
144 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; | 249 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; |
145 | 250 |
146 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); | 251 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); |
147 }; | 252 }; |
148 | 253 |
149 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 254 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
OLD | NEW |