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 // The reset prompt has been triggered; but the reset bubble has not yet |
| 148 // been shown. |
| 149 STATE_HAS_TRIGGERED_PROMPT, |
| 150 // The reset prompt has been triggered; the reset bubble has been shown, and |
| 151 // potentially already dismissed by the user. |
| 152 STATE_HAS_SHOWN_BUBBLE, |
| 153 STATE_PERFORMING_RESET, |
79 STATE_DONE | 154 STATE_DONE |
80 }; | 155 }; |
81 | 156 |
82 // Prepares the asynchronous evaluation flow by requesting services that it | 157 // Prepares the asynchronous evaluation flow by requesting services that it |
83 // depends on to make themselves ready. | 158 // depends on to make themselves ready. |
84 void PrepareEvaluationFlow(); | 159 void PrepareEvaluationFlow(); |
85 | 160 |
86 // Called back by |resetter_delegate_| when the template URL service is ready. | 161 // Called back by |resetter_delegate_| when the template URL service is ready. |
87 void OnTemplateURLServiceIsLoaded(); | 162 void OnTemplateURLServiceIsLoaded(); |
88 | 163 |
(...skipping 19 matching lines...) Expand all Loading... |
108 // |program| that will evaluate whether the conditions are met for showing the | 183 // |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 | 184 // 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 | 185 // 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 | 186 // program will only see hashed keys and values that are produced using |
112 // |hash_seed| as a key. | 187 // |hash_seed| as a key. |
113 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( | 188 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( |
114 const std::string& hash_seed, | 189 const std::string& hash_seed, |
115 const std::string& program, | 190 const std::string& program, |
116 scoped_ptr<base::DictionaryValue> program_input); | 191 scoped_ptr<base::DictionaryValue> program_input); |
117 | 192 |
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 | 193 // 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. | 194 // tests to verify that the correct value are being reported. |
125 virtual void ReportStatistics(uint32 satisfied_criteria_mask, | 195 virtual void ReportStatistics(uint32 satisfied_criteria_mask, |
126 uint32 combined_status_mask); | 196 uint32 combined_status_mask); |
127 | 197 |
128 // BrowserContextKeyedService: | 198 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing |
129 virtual void Shutdown() OVERRIDE; | 199 // the program with |results|. Finishes the evaluation flow, and, based on the |
| 200 // result, potentially initiates the reset prompt flow. |
| 201 void FinishEvaluationFlow(scoped_ptr<EvaluationResults> results); |
| 202 |
| 203 // Begins the reset prompt flow by triggering the reset prompt, which consists |
| 204 // of two parts: (1.) the profile reset (pop-up) bubble, and (2.) a menu item |
| 205 // in the wrench menu (provided by a GlobalError). |
| 206 // The flow lasts until we receive a clear indication from the user about |
| 207 // whether or not they wish to reset their settings. This indication can come |
| 208 // in a variety of flavors: |
| 209 // * taking definitive action (i.e. selecting either "Reset" or "No, thanks") |
| 210 // in the pop-up reset bubble itself, |
| 211 // * dismissing the bubble, but then selecting the wrench menu item, which |
| 212 // takes them to the WebUI reset dialog in chrome://settings, and then the |
| 213 // user can make their choice there, |
| 214 // * the user going to the WebUI reset dialog by themself. |
| 215 // For the most part, the conclusion of the reset flow coincides with when the |
| 216 // reset prompt is dismissed, with the one exception being that the prompt is |
| 217 // closed as soon as the WebUI reset dialog is opened, we do not wait until |
| 218 // the user actually makes a choice in that dialog. |
| 219 void BeginResetPromptFlow(); |
| 220 |
| 221 // Called back by the ProfileResetter once resetting the profile settings has |
| 222 // been completed, when requested by the user from inside the reset bubble. |
| 223 // Will dismiss the prompt and conclude the reset prompt flow. |
| 224 void OnProfileSettingsResetCompleted(); |
| 225 |
| 226 // Reports the result of triggering the prompt through UMA. Virtual, so it can |
| 227 // be mocked out in tests to verify that the correct value is being reported. |
| 228 virtual void ReportPromptResult(PromptResult result); |
| 229 |
| 230 // Writes the memento values returned by the evaluation program to disk, and |
| 231 // then destroys |evaluation_results_|. |
| 232 void PersistMementos(); |
| 233 |
| 234 // Concludes the reset prompt flow. |
| 235 void FinishResetPromptFlow(); |
130 | 236 |
131 Profile* profile_; | 237 Profile* profile_; |
132 | 238 |
133 State state_; | 239 State state_; |
134 bool enumeration_of_loaded_modules_ready_; | 240 bool enumeration_of_loaded_modules_ready_; |
135 bool template_url_service_ready_; | 241 bool template_url_service_ready_; |
| 242 bool has_already_dismissed_prompt_; |
136 | 243 |
137 scoped_ptr<InputBuilder> input_builder_; | 244 scoped_ptr<InputBuilder> input_builder_; |
138 std::string hash_seed_; | 245 std::string hash_seed_; |
139 std::string program_; | 246 std::string program_; |
140 | 247 |
| 248 scoped_ptr<EvaluationResults> evaluation_results_; |
| 249 |
141 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; | 250 scoped_ptr<AutomaticProfileResetterDelegate> delegate_; |
142 scoped_refptr<base::TaskRunner> task_runner_for_waiting_; | 251 scoped_refptr<base::TaskRunner> task_runner_for_waiting_; |
143 | 252 |
144 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; | 253 base::WeakPtrFactory<AutomaticProfileResetter> weak_ptr_factory_; |
145 | 254 |
146 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); | 255 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetter); |
147 }; | 256 }; |
148 | 257 |
149 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ | 258 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_H_ |
OLD | NEW |