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