Index: chrome/browser/safe_browsing/settings_reset_prompt/default_settings_fetcher.h |
diff --git a/chrome/browser/safe_browsing/settings_reset_prompt/default_settings_fetcher.h b/chrome/browser/safe_browsing/settings_reset_prompt/default_settings_fetcher.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ffd5e9eaa8eb062a97d13c7702d80ce616948e71 |
--- /dev/null |
+++ b/chrome/browser/safe_browsing/settings_reset_prompt/default_settings_fetcher.h |
@@ -0,0 +1,64 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_DEFAULT_SETTINGS_FETCHER_H_ |
+#define CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_DEFAULT_SETTINGS_FETCHER_H_ |
+ |
+#include <memory> |
+ |
+#include "base/callback.h" |
+ |
+class BrandcodedDefaultSettings; |
+class BrandcodeConfigFetcher; |
+ |
+namespace safe_browsing { |
+ |
+// Class that fetches default settings to be used for the settings reset |
+// prompt. The static |FetchDefaultSettings()| function will create and manage |
+// the lifetime of |DefaultSettingsFetcher| instances. |
+class DefaultSettingsFetcher { |
+ public: |
+ using SettingsCallback = |
+ base::Callback<void(std::unique_ptr<BrandcodedDefaultSettings>)>; |
+ |
+ // Fetches default settings and passes the corresponding |
+ // |BrandcodedDefaultSettings| object to |callback| on the UI thread. This |
+ // function must be called on the UI thread as well. |
+ static void FetchDefaultSettings(SettingsCallback callback); |
+ // Allows tests to specify the default settings that were fetched in |
+ // |fetched_settings|. Passing nullptr as |fetched_settings| corresponds to |
+ // the case when fetching default settings over the network fails. |
+ static void FetchDefaultSettingsForTesting( |
+ SettingsCallback callback, |
+ std::unique_ptr<BrandcodedDefaultSettings> fetched_settings); |
+ |
+ private: |
+ // Instances of |DefaultSettingsFetcher| own themselves and will delete |
+ // themselves once default settings have been fetched and |callback| has been |
+ // posted on the UI thread. |
+ // |
+ // The main reason for this design is that |BrandcodeConfigFetcher| takes a |
+ // callback and initiates the fetching process in its constructor, and we need |
+ // to hold on to the instance of the fetcher until settings have been |
+ // fetched. This design saves us from having to explicitly manage global |
+ // |BrandcodeConfigFetcher| instances. |
+ explicit DefaultSettingsFetcher(SettingsCallback callback); |
+ ~DefaultSettingsFetcher(); |
+ |
+ // Starts the process of fetching default settings and will ensure that |
+ // |PostCallbackAndDeleteSelf| is called once settings have been fetched. |
+ void Start(); |
+ void OnSettingsFetched(); |
+ // Posts a call to |callback_| on the UI thread, passing to it |
+ // |default_settings|, and deletes |this|. |
+ void PostCallbackAndDeleteSelf( |
+ std::unique_ptr<BrandcodedDefaultSettings> default_settings); |
+ |
+ std::unique_ptr<BrandcodeConfigFetcher> config_fetcher_; |
+ SettingsCallback callback_; |
+}; |
+ |
+} // namespace safe_browsing |
+ |
+#endif // CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_DEFAULT_SETTINGS_FETCHER_H_ |