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

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

Issue 62193002: Integrate UI and reset logic into AutomaticProfileResetter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit tests, some other smaller changes. Created 7 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/profile_resetter/automatic_profile_resetter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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
MAD 2013/11/11 13:26:11 resp. ???
engedy 2013/11/13 00:40:44 Done.
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
MAD 2013/11/11 13:26:11 Not sure if we should document here who calls this
engedy 2013/11/13 00:40:44 Removed, also 4 in instances below.
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
MAD 2013/11/11 13:26:11 Not sure we need the word "already" here... and I
engedy 2013/11/13 00:40:44 Done.
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
115 // BrowserContextKeyedService:
116 virtual void Shutdown() OVERRIDE;
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
68 private: 133 private:
69 struct EvaluationResults; 134 struct EvaluationResults;
70 135
71 enum State { 136 enum State {
72 STATE_UNINITIALIZED, 137 STATE_UNINITIALIZED,
73 STATE_INITIALIZED, 138 STATE_INITIALIZED,
74 STATE_DISABLED, 139 STATE_DISABLED,
75 STATE_WAITING_ON_DEPENDENCIES, 140 STATE_WAITING_ON_DEPENDENCIES,
76 STATE_READY, 141 STATE_READY,
77 STATE_WORKING, 142 STATE_EVALUATING_CONDITIONS,
143 STATE_AWAITING_USER_CHOICE,
144 STATE_PERFORMING_RESET,
78 STATE_DONE 145 STATE_DONE
79 }; 146 };
80 147
81 // Prepares the asynchronous evaluation flow by requesting services that it 148 // Prepares the asynchronous evaluation flow by requesting services that it
82 // depends on to make themselves ready. 149 // depends on to make themselves ready.
83 void PrepareEvaluationFlow(); 150 void PrepareEvaluationFlow();
84 151
85 // Called back by |resetter_delegate_| when the template URL service is ready. 152 // Called back by |resetter_delegate_| when the template URL service is ready.
86 void OnTemplateURLServiceIsLoaded(); 153 void OnTemplateURLServiceIsLoaded();
87 154
(...skipping 24 matching lines...) Expand all
112 // |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
113 // 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
114 // 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
115 // 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
116 // |hash_seed| as a key. 183 // |hash_seed| as a key.
117 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread( 184 static scoped_ptr<EvaluationResults> EvaluateConditionsOnWorkerPoolThread(
118 const std::string& hash_seed, 185 const std::string& hash_seed,
119 const std::string& program, 186 const std::string& program,
120 scoped_ptr<base::DictionaryValue> program_input); 187 scoped_ptr<base::DictionaryValue> program_input);
121 188
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 189 // 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. 190 // tests to verify that the correct value are being reported.
129 virtual void ReportStatistics(uint32 satisfied_criteria_mask, 191 virtual void ReportStatistics(uint32 satisfied_criteria_mask,
130 uint32 combined_status_mask); 192 uint32 combined_status_mask);
131 193
132 // BrowserContextKeyedService: 194 // Called back when EvaluateConditionsOnWorkerPoolThread completes executing
133 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.
202 // The flow is considered to be "active" until we receive a clear indication
203 // from the user about whether or not they wish to reset their settings. This
204 // indication can come 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
209 // making their choice there,
210 // * going to the WebUI reset dialog by themselves.
211 void BeginResetPromptFlow();
212
213 // Called back by the ProfileResetter once resetting the profile settings has
214 // been completed, when requested by the user from inside the reset bubble.
215 // Will conclude the reset prompt flow.
216 void OnProfileSettingsResetCompleted();
217
218 // Reports the result of showing the prompt through UMA. Virtual, so it can be
219 // mocked out in tests to verify that the correct value is being reported.
220 virtual void ReportPromptResult(PromptResult result);
221
222 // Concludes the reset prompt flow with |prompt_result|, and persists the
223 // memento values returned by the evaluator program to disk.
224 void FinishResetPromptFlow(PromptResult prompt_result);
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_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/profile_resetter/automatic_profile_resetter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698