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