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

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

Issue 272763002: Make code for the AutomaticProfileResetter more readabile (readability review) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments by pkasting@. Created 6 years, 6 months 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 | no next file » | 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 // Declares a delegate that interacts with the rest of the browser on behalf of
6 // the AutomaticProfileResetter.
7 //
8 // The reason for this separation is to facilitate unit testing. Factoring out
9 // the implementation for each interaction step (encapsulated by one method of
10 // the delegate) allows it to be tested independently in itself. It also becomes
11 // easier to verify that the state machine inside AutomaticProfileResetter works
12 // correctly: by mocking out the interaction methods in the delegate, we can, in
13 // effect, mock out the entire rest of the browser, allowing us to easily
14 // simulate scenarios that are interesting for testing the state machine.
15 //
16 // The delegate is normally instantiated by AutomaticProfileResetter internally,
17 // while a mock implementation can be injected during unit tests.
18
5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_ 19 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_
6 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_ 20 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_
7 21
8 #include "base/basictypes.h" 22 #include "base/basictypes.h"
9 #include "base/callback_forward.h" 23 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 25 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/profile_resetter/profile_resetter.h" 26 #include "chrome/browser/profile_resetter/profile_resetter.h"
13 #include "chrome/browser/search_engines/template_url_service_observer.h" 27 #include "chrome/browser/search_engines/template_url_service_observer.h"
14 #include "content/public/browser/notification_observer.h" 28 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h" 29 #include "content/public/browser/notification_registrar.h"
16 #include "extensions/common/one_shot_event.h" 30 #include "extensions/common/one_shot_event.h"
17 31
18 class BrandcodeConfigFetcher; 32 class BrandcodeConfigFetcher;
19 class GlobalErrorService; 33 class GlobalErrorService;
20 class Profile; 34 class Profile;
21 class ResettableSettingsSnapshot; 35 class ResettableSettingsSnapshot;
22 class TemplateURLService; 36 class TemplateURLService;
23 37
24 namespace base { 38 namespace base {
25 class DictionaryValue; 39 class DictionaryValue;
26 class ListValue; 40 class ListValue;
27 } 41 }
28 42
29 // Defines the interface for the delegate that will interact with the rest of 43 // Defines the interface for the delegate that will interact with the rest of
30 // the browser on behalf of the AutomaticProfileResetter. 44 // the browser on behalf of the AutomaticProfileResetter.
31 // The primary reason for this separation is to facilitate unit testing.
32 class AutomaticProfileResetterDelegate { 45 class AutomaticProfileResetterDelegate {
33 public: 46 public:
34 virtual ~AutomaticProfileResetterDelegate() {} 47 virtual ~AutomaticProfileResetterDelegate() {}
35 48
36 // Requests the module enumerator to start scanning for loaded modules now, if 49 // Requests the module enumerator to start scanning for loaded modules now, if
37 // it has not done so already. 50 // it has not done so already.
38 virtual void EnumerateLoadedModulesIfNeeded() = 0; 51 virtual void EnumerateLoadedModulesIfNeeded() = 0;
39 52
40 // Requests |ready_callback| to be posted on the UI thread once the module 53 // Requests |ready_callback| to be posted on the UI thread once the module
41 // enumerator has finished scanning for loaded modules. 54 // enumerator has finished scanning for loaded modules.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 void OnBrandcodedDefaultsFetched(); 180 void OnBrandcodedDefaultsFetched();
168 181
169 // Called back by the ProfileResetter once resetting the profile settings has 182 // Called back by the ProfileResetter once resetting the profile settings has
170 // been completed. If |old_settings_snapshot| is non-NULL, will compare it to 183 // been completed. If |old_settings_snapshot| is non-NULL, will compare it to
171 // the new settings and send the differences to Google for analysis. Finally, 184 // the new settings and send the differences to Google for analysis. Finally,
172 // will post |user_callback|. 185 // will post |user_callback|.
173 void OnProfileSettingsResetCompleted( 186 void OnProfileSettingsResetCompleted(
174 const base::Closure& user_callback, 187 const base::Closure& user_callback,
175 scoped_ptr<ResettableSettingsSnapshot> old_settings_snapshot); 188 scoped_ptr<ResettableSettingsSnapshot> old_settings_snapshot);
176 189
190 // The profile that this delegate operates on.
177 Profile* profile_; 191 Profile* profile_;
192
193 // Shortcuts to |profile_| keyed services, to reduce boilerplate. These may be
194 // NULL in unit tests that do not initialize the respective service(s).
178 GlobalErrorService* global_error_service_; 195 GlobalErrorService* global_error_service_;
179 TemplateURLService* template_url_service_; 196 TemplateURLService* template_url_service_;
180 197
198 // Helper to asynchronously download the default settings for the current
199 // distribution channel (identified by brand code). Instantiated on-demand.
181 scoped_ptr<BrandcodeConfigFetcher> brandcoded_config_fetcher_; 200 scoped_ptr<BrandcodeConfigFetcher> brandcoded_config_fetcher_;
201
202 // Once |brandcoded_defaults_fetched_event_| has fired, this will contain the
203 // brandcoded default settings, or empty settings for a non-branded build.
182 scoped_ptr<BrandcodedDefaultSettings> brandcoded_defaults_; 204 scoped_ptr<BrandcodedDefaultSettings> brandcoded_defaults_;
183 205
206 // Overwritten to avoid resetting aspects that will not work in unit tests.
184 const ProfileResetter::ResettableFlags resettable_aspects_; 207 const ProfileResetter::ResettableFlags resettable_aspects_;
208
209 // The profile resetter to perform the actual reset. Instantiated on-demand.
185 scoped_ptr<ProfileResetter> profile_resetter_; 210 scoped_ptr<ProfileResetter> profile_resetter_;
186 211
212 // Manages registrations/unregistrations for notifications.
187 content::NotificationRegistrar registrar_; 213 content::NotificationRegistrar registrar_;
188 214
189 // The list of modules found. Even when |modules_have_been_enumerated_event_| 215 // The list of modules found. Even when |modules_have_been_enumerated_event_|
190 // is signaled, this may still be NULL. 216 // is signaled, this may still be NULL.
191 scoped_ptr<base::ListValue> module_list_; 217 scoped_ptr<base::ListValue> module_list_;
192 218
193 // This event is signaled once module enumeration has been attempted. If 219 // This event is signaled once module enumeration has been attempted. If
194 // during construction, EnumerateModulesModel can supply a non-empty list of 220 // during construction, EnumerateModulesModel can supply a non-empty list of
195 // modules, module enumeration has clearly already happened, so the event will 221 // modules, module enumeration has clearly already happened, so the event will
196 // be signaled immediately; otherwise, when EnumerateLoadedModulesIfNeeded() 222 // be signaled immediately; otherwise, when EnumerateLoadedModulesIfNeeded()
197 // is called, it will ask the model to scan the modules, and then signal the 223 // is called, it will ask the model to scan the modules, and then signal the
198 // event once this process is completed. 224 // event once this process is completed.
199 extensions::OneShotEvent modules_have_been_enumerated_event_; 225 extensions::OneShotEvent modules_have_been_enumerated_event_;
200 226
201 // This event is signaled once the TemplateURLService has loaded. If the 227 // This event is signaled once the TemplateURLService has loaded. If the
202 // TemplateURLService was already loaded prior to the creation of this class, 228 // TemplateURLService was already loaded prior to the creation of this class,
203 // the event will be signaled during construction. 229 // the event will be signaled during construction.
204 extensions::OneShotEvent template_url_service_ready_event_; 230 extensions::OneShotEvent template_url_service_ready_event_;
205 231
206 // This event is signaled once brandcoded default settings have been fetched, 232 // This event is signaled once brandcoded default settings have been fetched,
207 // or once it has been established that this is not a branded build. 233 // or once it has been established that this is not a branded build.
208 extensions::OneShotEvent brandcoded_defaults_fetched_event_; 234 extensions::OneShotEvent brandcoded_defaults_fetched_event_;
209 235
210 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterDelegateImpl); 236 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterDelegateImpl);
211 }; 237 };
212 238
213 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H _ 239 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H _
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698