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_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_ |
6 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_ | 6 #define CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
11 #include "chrome/browser/search_engines/template_url_service_observer.h" | 12 #include "chrome/browser/search_engines/template_url_service_observer.h" |
12 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 14 #include "content/public/browser/notification_registrar.h" |
14 #include "extensions/common/one_shot_event.h" | 15 #include "extensions/common/one_shot_event.h" |
15 | 16 |
| 17 class BrandcodeConfigFetcher; |
| 18 class BrandcodedDefaultSettings; |
| 19 class GlobalErrorService; |
| 20 class Profile; |
| 21 class ProfileResetter; |
| 22 class ResettableSettingsSnapshot; |
16 class TemplateURLService; | 23 class TemplateURLService; |
17 | 24 |
18 namespace base { | 25 namespace base { |
19 class DictionaryValue; | 26 class DictionaryValue; |
20 class ListValue; | 27 class ListValue; |
21 } | 28 } |
22 | 29 |
23 // Defines the interface for the delegate that will interact with the rest of | 30 // Defines the interface for the delegate that will interact with the rest of |
24 // the browser on behalf of the AutomaticProfileResetter. | 31 // the browser on behalf of the AutomaticProfileResetter. |
25 // The primary reason for this separation is to facilitate unit testing. | 32 // The primary reason for this separation is to facilitate unit testing. |
(...skipping 11 matching lines...) Expand all Loading... |
37 const base::Closure& ready_callback) const = 0; | 44 const base::Closure& ready_callback) const = 0; |
38 | 45 |
39 // Requests the template URL service to load its database (asynchronously). | 46 // Requests the template URL service to load its database (asynchronously). |
40 virtual void LoadTemplateURLServiceIfNeeded() = 0; | 47 virtual void LoadTemplateURLServiceIfNeeded() = 0; |
41 | 48 |
42 // Requests |ready_callback| to be posted on the UI thread once the template | 49 // Requests |ready_callback| to be posted on the UI thread once the template |
43 // URL service has finished loading its database. | 50 // URL service has finished loading its database. |
44 virtual void RequestCallbackWhenTemplateURLServiceIsLoaded( | 51 virtual void RequestCallbackWhenTemplateURLServiceIsLoaded( |
45 const base::Closure& ready_callback) const = 0; | 52 const base::Closure& ready_callback) const = 0; |
46 | 53 |
| 54 // Requests that the configuration file containing the default settings for |
| 55 // the current brandcode be downloaded if it has not been already. |
| 56 virtual void FetchBrandcodedDefaultSettingsIfNeeded() = 0; |
| 57 |
| 58 // Requests |ready_callback| to be posted on the UI thread once the brandcoded |
| 59 // default settings have been downloaded. |
| 60 virtual void RequestCallbackWhenBrandcodedDefaultsAreFetched( |
| 61 const base::Closure& ready_callback) const = 0; |
| 62 |
47 // Returns a list of loaded module name digests. | 63 // Returns a list of loaded module name digests. |
48 virtual scoped_ptr<base::ListValue> GetLoadedModuleNameDigests() const = 0; | 64 virtual scoped_ptr<base::ListValue> GetLoadedModuleNameDigests() const = 0; |
49 | 65 |
50 // Returns attributes of the search engine currently set as the default (or | 66 // Returns attributes of the search engine currently set as the default (or |
51 // an empty dictionary if there is none). | 67 // an empty dictionary if there is none). |
52 // The returned attributes correspond in meaning and format to the user | 68 // The returned attributes correspond in meaning and format to the user |
53 // preferences stored by TemplateURLService::SaveDefaultSearchProviderToPrefs, | 69 // preferences stored by TemplateURLService::SaveDefaultSearchProviderToPrefs, |
54 // and will be named after the second path name segment of the respective | 70 // and will be named after the second path name segment of the respective |
55 // preference (i.e. the part after "default_search_provider."). | 71 // preference (i.e. the part after "default_search_provider."). |
56 // Note that: | 72 // Note that: |
57 // 1.) the "enabled" attribute will not be present, as it is not technically | 73 // 1.) the "enabled" attribute will not be present, as it is not technically |
58 // an attribute of a search provider, | 74 // an attribute of a search provider, |
59 // 2.) "encodings" will be a list of strings, in contrast to a single string | 75 // 2.) "encodings" will be a list of strings, in contrast to a single string |
60 // with tokens delimited by semicolons, but the order will be the same. | 76 // with tokens delimited by semicolons, but the order will be the same. |
61 virtual scoped_ptr<base::DictionaryValue> | 77 virtual scoped_ptr<base::DictionaryValue> |
62 GetDefaultSearchProviderDetails() const = 0; | 78 GetDefaultSearchProviderDetails() const = 0; |
63 | 79 |
64 // Returns whether or not the default search provider is set by policy. | 80 // Returns whether or not the default search provider is set by policy. |
65 virtual bool IsDefaultSearchProviderManaged() const = 0; | 81 virtual bool IsDefaultSearchProviderManaged() const = 0; |
66 | 82 |
67 // Returns a list of dictionaries, each containing attributes for each of the | 83 // Returns a list of dictionaries, each containing attributes for each of the |
68 // pre-populated search engines, in the format described above. | 84 // pre-populated search engines, in the format described above. |
69 virtual scoped_ptr<base::ListValue> | 85 virtual scoped_ptr<base::ListValue> |
70 GetPrepopulatedSearchProvidersDetails() const = 0; | 86 GetPrepopulatedSearchProvidersDetails() const = 0; |
71 | 87 |
72 // Triggers showing the one-time profile settings reset prompt. | 88 // Triggers showing the one-time profile settings reset prompt. |
73 virtual void ShowPrompt() = 0; | 89 virtual void ShowPrompt() = 0; |
| 90 |
| 91 // Triggers the ProfileResetter to reset all supported settings and optionally |
| 92 // |send_feedback|. Will post |completion| on the UI thread once completed. |
| 93 // Brandcoded default settings will be fetched if they are not yet available, |
| 94 // then the reset will be performed once the download is complete. |
| 95 // NOTE: Can only be called at most once during the lifetime of the object. |
| 96 virtual void TriggerProfileSettingsReset(bool send_feedback, |
| 97 const base::Closure& completion) = 0; |
| 98 |
| 99 // Dismisses the one-time profile settings reset prompt. |
| 100 virtual void DismissPrompt() = 0; |
74 }; | 101 }; |
75 | 102 |
76 // Implementation for AutomaticProfileResetterDelegate. | 103 // Implementation for AutomaticProfileResetterDelegate. |
77 // To facilitate unit testing, having the TemplateURLService available is only | 104 // To facilitate unit testing, having a GlobalErrorService or TemplateURLService |
78 // required when using search engine related methods. | 105 // available for the Profile is only required when using specific methods, see |
| 106 // constructor for details. |
79 class AutomaticProfileResetterDelegateImpl | 107 class AutomaticProfileResetterDelegateImpl |
80 : public AutomaticProfileResetterDelegate, | 108 : public AutomaticProfileResetterDelegate, |
| 109 public base::SupportsWeakPtr<AutomaticProfileResetterDelegateImpl>, |
81 public TemplateURLServiceObserver, | 110 public TemplateURLServiceObserver, |
82 public content::NotificationObserver { | 111 public content::NotificationObserver { |
83 public: | 112 public: |
84 // The |template_url_service| may be NULL in unit tests. Must be non-NULL for | 113 // The GlobalErrorService and TemplateURLService for |profile| may be NULL in |
85 // callers who wish to call: | 114 // unit tests. |
| 115 // TemplateURLService must be non-NULL for callers who wish to call: |
86 // * LoadTemplateURLServiceIfNeeded(), | 116 // * LoadTemplateURLServiceIfNeeded(), |
87 // * GetDefaultSearchProviderDetails(), | 117 // * GetDefaultSearchProviderDetails(), |
88 // * GetPrepopulatedSearchProvidersDetails(), or | 118 // * GetPrepopulatedSearchProvidersDetails(), or |
89 // * IsDefaultSearchManaged(). | 119 // * IsDefaultSearchManaged(). |
90 explicit AutomaticProfileResetterDelegateImpl( | 120 // GlobalErrorService must be non-NULL for callers who wish to call: |
91 TemplateURLService* template_url_service); | 121 // * ShowPrompt(), or |
| 122 // * DismissPrompt(). |
| 123 explicit AutomaticProfileResetterDelegateImpl(Profile* profile); |
92 virtual ~AutomaticProfileResetterDelegateImpl(); | 124 virtual ~AutomaticProfileResetterDelegateImpl(); |
93 | 125 |
94 // AutomaticProfileResetterDelegate: | 126 // AutomaticProfileResetterDelegate: |
95 virtual void EnumerateLoadedModulesIfNeeded() OVERRIDE; | 127 virtual void EnumerateLoadedModulesIfNeeded() OVERRIDE; |
96 virtual void RequestCallbackWhenLoadedModulesAreEnumerated( | 128 virtual void RequestCallbackWhenLoadedModulesAreEnumerated( |
97 const base::Closure& ready_callback) const OVERRIDE; | 129 const base::Closure& ready_callback) const OVERRIDE; |
98 virtual void LoadTemplateURLServiceIfNeeded() OVERRIDE; | 130 virtual void LoadTemplateURLServiceIfNeeded() OVERRIDE; |
99 virtual void RequestCallbackWhenTemplateURLServiceIsLoaded( | 131 virtual void RequestCallbackWhenTemplateURLServiceIsLoaded( |
100 const base::Closure& ready_callback) const OVERRIDE; | 132 const base::Closure& ready_callback) const OVERRIDE; |
| 133 virtual void FetchBrandcodedDefaultSettingsIfNeeded() OVERRIDE; |
| 134 virtual void RequestCallbackWhenBrandcodedDefaultsAreFetched( |
| 135 const base::Closure& ready_callback) const OVERRIDE; |
101 virtual scoped_ptr<base::ListValue> | 136 virtual scoped_ptr<base::ListValue> |
102 GetLoadedModuleNameDigests() const OVERRIDE; | 137 GetLoadedModuleNameDigests() const OVERRIDE; |
103 virtual scoped_ptr<base::DictionaryValue> | 138 virtual scoped_ptr<base::DictionaryValue> |
104 GetDefaultSearchProviderDetails() const OVERRIDE; | 139 GetDefaultSearchProviderDetails() const OVERRIDE; |
105 virtual bool IsDefaultSearchProviderManaged() const OVERRIDE; | 140 virtual bool IsDefaultSearchProviderManaged() const OVERRIDE; |
106 virtual scoped_ptr<base::ListValue> | 141 virtual scoped_ptr<base::ListValue> |
107 GetPrepopulatedSearchProvidersDetails() const OVERRIDE; | 142 GetPrepopulatedSearchProvidersDetails() const OVERRIDE; |
108 virtual void ShowPrompt() OVERRIDE; | 143 virtual void ShowPrompt() OVERRIDE; |
| 144 virtual void TriggerProfileSettingsReset( |
| 145 bool send_feedback, |
| 146 const base::Closure& completion) OVERRIDE; |
| 147 virtual void DismissPrompt() OVERRIDE; |
109 | 148 |
110 // TemplateURLServiceObserver: | 149 // TemplateURLServiceObserver: |
111 virtual void OnTemplateURLServiceChanged() OVERRIDE; | 150 virtual void OnTemplateURLServiceChanged() OVERRIDE; |
112 | 151 |
113 // content::NotificationObserver: | 152 // content::NotificationObserver: |
114 virtual void Observe(int type, | 153 virtual void Observe(int type, |
115 const content::NotificationSource& source, | 154 const content::NotificationSource& source, |
116 const content::NotificationDetails& details) OVERRIDE; | 155 const content::NotificationDetails& details) OVERRIDE; |
117 | 156 |
118 private: | 157 private: |
| 158 // Triggers the ProfileResetter to reset all supported settings and optionally |
| 159 // |send_feedback|. Will invoke |completion| on the UI thread once completed |
| 160 // |brandcoded_defaults_| must be already fetched when this is called. |
| 161 void RunProfileSettingsReset(bool send_feedback, |
| 162 const base::Closure& completion); |
| 163 |
| 164 // Called by |brandcoded_config_fetcher_| when it finishes downloading the |
| 165 // brandcoded default settings (or the download times out). |
| 166 void OnBrandcodedDefaultsFetched(); |
| 167 |
| 168 // Called back by the ProfileResetter once resetting the profile settings has |
| 169 // been completed. If |old_settings_snapshot| is non-NULL, will compare it to |
| 170 // the new settings and send the differences to Google for analysis. Finally, |
| 171 // will post |user_callback|. |
| 172 void OnProfileSettingsResetCompleted( |
| 173 const base::Closure& user_callback, |
| 174 scoped_ptr<ResettableSettingsSnapshot> old_settings_snapshot); |
| 175 |
| 176 Profile* profile_; |
| 177 GlobalErrorService* global_error_service_; |
119 TemplateURLService* template_url_service_; | 178 TemplateURLService* template_url_service_; |
120 | 179 |
| 180 scoped_ptr<BrandcodeConfigFetcher> brandcoded_config_fetcher_; |
| 181 scoped_ptr<BrandcodedDefaultSettings> brandcoded_defaults_; |
| 182 |
| 183 scoped_ptr<ProfileResetter> profile_resetter_; |
| 184 |
121 content::NotificationRegistrar registrar_; | 185 content::NotificationRegistrar registrar_; |
122 | 186 |
123 // The list of modules found. Even when |modules_have_been_enumerated_event_| | 187 // The list of modules found. Even when |modules_have_been_enumerated_event_| |
124 // is signaled, this may still be NULL. | 188 // is signaled, this may still be NULL. |
125 scoped_ptr<base::ListValue> module_list_; | 189 scoped_ptr<base::ListValue> module_list_; |
126 | 190 |
127 // This event is signaled once module enumeration has been attempted. If | 191 // This event is signaled once module enumeration has been attempted. If |
128 // during construction, EnumerateModulesModel can supply a non-empty list of | 192 // during construction, EnumerateModulesModel can supply a non-empty list of |
129 // modules, module enumeration has clearly already happened, so the event will | 193 // modules, module enumeration has clearly already happened, so the event will |
130 // be signaled immediately; otherwise, when EnumerateLoadedModulesIfNeeded() | 194 // be signaled immediately; otherwise, when EnumerateLoadedModulesIfNeeded() |
131 // is called, it will ask the model to scan the modules, and then signal the | 195 // is called, it will ask the model to scan the modules, and then signal the |
132 // event once this process is completed. | 196 // event once this process is completed. |
133 extensions::OneShotEvent modules_have_been_enumerated_event_; | 197 extensions::OneShotEvent modules_have_been_enumerated_event_; |
134 | 198 |
135 // This event is signaled once the TemplateURLService has loaded. If the | 199 // This event is signaled once the TemplateURLService has loaded. If the |
136 // TemplateURLService was already loaded prior to the creation of this class, | 200 // TemplateURLService was already loaded prior to the creation of this class, |
137 // the event will be signaled during construction. | 201 // the event will be signaled during construction. |
138 extensions::OneShotEvent template_url_service_ready_event_; | 202 extensions::OneShotEvent template_url_service_ready_event_; |
139 | 203 |
| 204 // This event is signaled once brandcoded default settings have been |
| 205 // downloaded, or it has been established that this is not a branded build. |
| 206 extensions::OneShotEvent brandcoded_defaults_fetched_event_; |
| 207 |
140 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterDelegateImpl); | 208 DISALLOW_COPY_AND_ASSIGN(AutomaticProfileResetterDelegateImpl); |
141 }; | 209 }; |
142 | 210 |
143 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H
_ | 211 #endif // CHROME_BROWSER_PROFILE_RESETTER_AUTOMATIC_PROFILE_RESETTER_DELEGATE_H
_ |
OLD | NEW |