Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_DEFAULT_SETTINGS_FETC HER_H_ | |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_DEFAULT_SETTINGS_FETC HER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 | |
| 12 class BrandcodedDefaultSettings; | |
| 13 class BrandcodeConfigFetcher; | |
| 14 | |
| 15 namespace safe_browsing { | |
| 16 | |
| 17 // Class that fetches default settings to be used for the settings reset | |
| 18 // prompt. The static |FetchDefaultSettings()| function will create and manage | |
| 19 // the lifetime of |DefaultSettingsFetcher| instances. | |
| 20 class DefaultSettingsFetcher { | |
| 21 public: | |
| 22 using SettingsCallback = | |
| 23 base::Callback<void(std::unique_ptr<BrandcodedDefaultSettings>)>; | |
| 24 | |
| 25 // Fetches default settings and passes the corresponding | |
| 26 // |BrandcodedDefaultSettings| object to |callback| on the UI thread. The | |
|
csharp
2017/05/01 19:11:37
nit: The function -> This function (I think it mak
alito
2017/05/01 19:18:19
Done.
| |
| 27 // function should be called on the UI thread as well. | |
| 28 static void FetchDefaultSettings(SettingsCallback callback); | |
| 29 // Allows tests to specify the default settings that were fetched in | |
| 30 // |fetched_settings|. Passing nullptr as |fetched_settings| corresponds to | |
| 31 // the case when fetching default settings over the network fails. | |
| 32 static void FetchDefaultSettingsForTesting( | |
| 33 SettingsCallback callback, | |
| 34 std::unique_ptr<BrandcodedDefaultSettings> fetched_settings); | |
| 35 | |
| 36 private: | |
| 37 // Instances of |DefaultSettingsFetcher| own themselves and will delete | |
| 38 // themselves once default settings have been fetched and |callback| has been | |
| 39 // posted on the UI thread. | |
| 40 // | |
| 41 // The main reason for this design is that |BrandcodeConfigFetcher| takes a | |
| 42 // callback and initiates the fetching process in its constructor, and we need | |
| 43 // to hold on to the instance of the fetcher until settings have been | |
| 44 // fetched. This design saves us from having to explicitly manage global | |
| 45 // |BrandcodeConfigFetcher| instances. | |
| 46 explicit DefaultSettingsFetcher(SettingsCallback callback); | |
| 47 ~DefaultSettingsFetcher(); | |
| 48 | |
| 49 // Starts the process of fetching default settings and will ensure that | |
| 50 // |PostCallbackAndDeleteSelf| is called once settings have been fetched. | |
| 51 void Start(); | |
| 52 void OnSettingsFetched(); | |
| 53 // Posts a call to |callback_| on the UI thread, passing to it | |
| 54 // |default_settings|, and deletes |this|. | |
| 55 void PostCallbackAndDeleteSelf( | |
| 56 std::unique_ptr<BrandcodedDefaultSettings> default_settings); | |
| 57 | |
| 58 std::unique_ptr<BrandcodeConfigFetcher> config_fetcher_; | |
| 59 SettingsCallback callback_; | |
| 60 }; | |
| 61 | |
| 62 } // namespace safe_browsing | |
| 63 | |
| 64 #endif // CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_DEFAULT_SETTINGS_F ETCHER_H_ | |
| OLD | NEW |