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