| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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_SAFE_BROWSING_SETTINGS_RESET_PROMPT_SETTINGS_RESET_PROMPT
_MODEL_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_SETTINGS_RESET_PROMPT
_MODEL_H_ |
| 6 #define CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_SETTINGS_RESET_PROMPT
_MODEL_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_SETTINGS_RESET_PROMPT
_MODEL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 NO_RESET_REQUIRED_DUE_TO_DOMAIN_NOT_MATCHED = 2, | 46 NO_RESET_REQUIRED_DUE_TO_DOMAIN_NOT_MATCHED = 2, |
| 47 NO_RESET_REQUIRED_DUE_TO_ALREADY_PROMPTED_FOR_SETTING = 3, | 47 NO_RESET_REQUIRED_DUE_TO_ALREADY_PROMPTED_FOR_SETTING = 3, |
| 48 NO_RESET_REQUIRED_DUE_TO_RECENTLY_PROMPTED = 4, | 48 NO_RESET_REQUIRED_DUE_TO_RECENTLY_PROMPTED = 4, |
| 49 NO_RESET_REQUIRED_DUE_TO_OTHER_SETTING_REQUIRING_RESET = 5, | 49 NO_RESET_REQUIRED_DUE_TO_OTHER_SETTING_REQUIRING_RESET = 5, |
| 50 NO_RESET_REQUIRED_DUE_TO_POLICY = 6, | 50 NO_RESET_REQUIRED_DUE_TO_POLICY = 6, |
| 51 RESET_STATE_MAX = 7 | 51 RESET_STATE_MAX = 7 |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 using ExtensionMap = | 54 using ExtensionMap = |
| 55 std::unordered_map<extensions::ExtensionId, ExtensionInfo>; | 55 std::unordered_map<extensions::ExtensionId, ExtensionInfo>; |
| 56 using CreateCallback = | |
| 57 base::Callback<void(std::unique_ptr<SettingsResetPromptModel>)>; | |
| 58 | 56 |
| 59 // Creates a new |SettingsResetPromptModel| and passes it to |callback|. This | 57 SettingsResetPromptModel( |
| 60 // function should be called on the UI thread. | |
| 61 static void Create(Profile* profile, | |
| 62 std::unique_ptr<SettingsResetPromptConfig> prompt_config, | |
| 63 CreateCallback callback); | |
| 64 static std::unique_ptr<SettingsResetPromptModel> CreateForTesting( | |
| 65 Profile* profile, | 58 Profile* profile, |
| 66 std::unique_ptr<SettingsResetPromptConfig> prompt_config, | 59 std::unique_ptr<SettingsResetPromptConfig> prompt_config, |
| 67 std::unique_ptr<ResettableSettingsSnapshot> settings_snapshot, | |
| 68 std::unique_ptr<BrandcodedDefaultSettings> default_settings, | |
| 69 std::unique_ptr<ProfileResetter> profile_resetter); | 60 std::unique_ptr<ProfileResetter> profile_resetter); |
| 70 | |
| 71 virtual ~SettingsResetPromptModel(); | 61 virtual ~SettingsResetPromptModel(); |
| 72 | 62 |
| 73 Profile* profile() const; | 63 Profile* profile() const; |
| 74 SettingsResetPromptConfig* config() const; | 64 SettingsResetPromptConfig* config() const; |
| 75 | 65 |
| 76 // Returns true if reset is enabled for any settings type. | 66 // Returns true if reset is enabled for any settings type. |
| 77 virtual bool ShouldPromptForReset() const; | 67 virtual bool ShouldPromptForReset() const; |
| 78 // Resets the settings whose reset states are set to |RESET_REQUIRED| as | 68 // Resets the settings whose reset states are set to |RESET_REQUIRED| as |
| 79 // returned by the methods below. Should be called only on the UI | 69 // returned by the methods below. Should be called only on the UI |
| 80 // thread. |done_callback| will called from the UI thread when the reset | 70 // thread. |done_callback| will called from the UI thread when the reset |
| 81 // operation has been completed. | 71 // operation has been completed. |
| 82 // | 72 // |
| 83 // NOTE: Can only be called once during the lifetime of this object. | 73 // NOTE: Can only be called once during the lifetime of this object. |
| 84 virtual void PerformReset(const base::Closure& done_callback); | 74 virtual void PerformReset( |
| 75 std::unique_ptr<BrandcodedDefaultSettings> default_settings, |
| 76 const base::Closure& done_callback); |
| 85 // To be called when the reset prompt dialog has been shown so that | 77 // To be called when the reset prompt dialog has been shown so that |
| 86 // preferences can be updated. | 78 // preferences can be updated. |
| 87 virtual void DialogShown(); | 79 virtual void DialogShown(); |
| 88 | 80 |
| 89 virtual GURL homepage() const; | 81 virtual GURL homepage() const; |
| 90 virtual ResetState homepage_reset_state() const; | 82 virtual ResetState homepage_reset_state() const; |
| 91 | 83 |
| 92 virtual GURL default_search() const; | 84 virtual GURL default_search() const; |
| 93 virtual ResetState default_search_reset_state() const; | 85 virtual ResetState default_search_reset_state() const; |
| 94 | 86 |
| 95 // Returns list of all current startup URLs. Returns empty list if session | 87 // Returns list of all current startup URLs. Returns empty list if session |
| 96 // startup is set to show the NTP or restore last session. | 88 // startup is set to show the NTP or restore last session. |
| 97 virtual const std::vector<GURL>& startup_urls() const; | 89 virtual const std::vector<GURL>& startup_urls() const; |
| 98 // Returns the list of all startup URLs that have a match in the prompt | 90 // Returns the list of all startup URLs that have a match in the prompt |
| 99 // config. This is a subset of the URLs returned by |startup_urls()|. | 91 // config. This is a subset of the URLs returned by |startup_urls()|. |
| 100 virtual const std::vector<GURL>& startup_urls_to_reset() const; | 92 virtual const std::vector<GURL>& startup_urls_to_reset() const; |
| 101 virtual ResetState startup_urls_reset_state() const; | 93 virtual ResetState startup_urls_reset_state() const; |
| 102 | 94 |
| 103 // Returns a map of extension ID -> ExtensionInfo for all extensions that will | 95 // Returns a map of extension ID -> ExtensionInfo for all extensions that will |
| 104 // be disabled. | 96 // be disabled. |
| 105 virtual const ExtensionMap& extensions_to_disable() const; | 97 virtual const ExtensionMap& extensions_to_disable() const; |
| 106 | 98 |
| 107 void ReportUmaMetrics() const; | 99 void ReportUmaMetrics() const; |
| 108 | 100 |
| 109 protected: | |
| 110 // Exposed for mocking in tests. | |
| 111 SettingsResetPromptModel( | |
| 112 Profile* profile, | |
| 113 std::unique_ptr<SettingsResetPromptConfig> prompt_config, | |
| 114 std::unique_ptr<ResettableSettingsSnapshot> settings_snapshot, | |
| 115 std::unique_ptr<BrandcodedDefaultSettings> default_settings, | |
| 116 std::unique_ptr<ProfileResetter> profile_resetter); | |
| 117 | |
| 118 private: | 101 private: |
| 119 static void OnSettingsFetched( | |
| 120 Profile* profile, | |
| 121 std::unique_ptr<SettingsResetPromptConfig> prompt_config, | |
| 122 SettingsResetPromptModel::CreateCallback callback, | |
| 123 std::unique_ptr<BrandcodedDefaultSettings> default_settings); | |
| 124 | |
| 125 // Functions to be called by the constructor to initialize the model | 102 // Functions to be called by the constructor to initialize the model |
| 126 // object. These functions should be called in the order in which they are | 103 // object. These functions should be called in the order in which they are |
| 127 // declared here so that the correct setting is chosen for the prompt when | 104 // declared here so that the correct setting is chosen for the prompt when |
| 128 // more than one setting requires reset (see also the class description). | 105 // more than one setting requires reset (see also the class description). |
| 129 void InitDefaultSearchData(); | 106 void InitDefaultSearchData(); |
| 130 void InitStartupUrlsData(); | 107 void InitStartupUrlsData(); |
| 131 void InitHomepageData(); | 108 void InitHomepageData(); |
| 132 void InitExtensionData(); | 109 void InitExtensionData(); |
| 133 | 110 |
| 134 // Helper function for the Init* functions above to determine the reset state | 111 // Helper function for the Init* functions above to determine the reset state |
| 135 // of settings that have a match in the config. | 112 // of settings that have a match in the config. |
| 136 ResetState GetResetStateForSetting( | 113 ResetState GetResetStateForSetting( |
| 137 const base::Time& last_triggered_for_setting) const; | 114 const base::Time& last_triggered_for_setting) const; |
| 138 | 115 |
| 139 // Return true if any setting's reset state is set to |RESET_REQUIRED|. | 116 // Return true if any setting's reset state is set to |RESET_REQUIRED|. |
| 140 bool SomeSettingRequiresReset() const; | 117 bool SomeSettingRequiresReset() const; |
| 141 | 118 |
| 142 bool SomeSettingIsManaged() const; | 119 bool SomeSettingIsManaged() const; |
| 143 bool SomeExtensionMustRemainEnabled() const; | 120 bool SomeExtensionMustRemainEnabled() const; |
| 144 | 121 |
| 145 Profile* const profile_; | 122 Profile* const profile_; |
| 146 | 123 |
| 147 SettingsResetPromptPrefsManager prefs_manager_; | 124 SettingsResetPromptPrefsManager prefs_manager_; |
| 148 std::unique_ptr<SettingsResetPromptConfig> prompt_config_; | 125 std::unique_ptr<SettingsResetPromptConfig> prompt_config_; |
| 149 std::unique_ptr<ResettableSettingsSnapshot> settings_snapshot_; | 126 std::unique_ptr<ResettableSettingsSnapshot> settings_snapshot_; |
| 150 // |default_settings_| should only be accessed on the UI thread after | |
| 151 // construction. | |
| 152 std::unique_ptr<BrandcodedDefaultSettings> default_settings_; | |
| 153 std::unique_ptr<ProfileResetter> profile_resetter_; | 127 std::unique_ptr<ProfileResetter> profile_resetter_; |
| 154 | 128 |
| 155 // A single timestamp to be used by all initialization functions to determine | 129 // A single timestamp to be used by all initialization functions to determine |
| 156 // if enough time has passed between the last time the prompt was shown and | 130 // if enough time has passed between the last time the prompt was shown and |
| 157 // "now" for a new prompt to be shown. | 131 // "now" for a new prompt to be shown. |
| 158 base::Time now_; | 132 base::Time now_; |
| 159 // The time since the last prompt was shown for any setting. | 133 // The time since the last prompt was shown for any setting. |
| 160 base::TimeDelta time_since_last_prompt_; | 134 base::TimeDelta time_since_last_prompt_; |
| 161 | 135 |
| 162 // Bits to keep track of which settings types have been initialized. | 136 // Bits to keep track of which settings types have been initialized. |
| 163 uint32_t settings_types_initialized_; | 137 uint32_t settings_types_initialized_ = 0; |
| 164 | 138 |
| 165 GURL homepage_url_; | 139 GURL homepage_url_; |
| 166 int homepage_reset_domain_id_; | 140 int homepage_reset_domain_id_ = -1; |
| 167 ResetState homepage_reset_state_; | 141 ResetState homepage_reset_state_ = |
| 142 NO_RESET_REQUIRED_DUE_TO_DOMAIN_NOT_MATCHED; |
| 168 | 143 |
| 169 GURL default_search_url_; | 144 GURL default_search_url_; |
| 170 int default_search_reset_domain_id_; | 145 int default_search_reset_domain_id_ = -1; |
| 171 ResetState default_search_reset_state_; | 146 ResetState default_search_reset_state_ = |
| 147 NO_RESET_REQUIRED_DUE_TO_DOMAIN_NOT_MATCHED; |
| 172 | 148 |
| 173 std::vector<GURL> startup_urls_; | 149 std::vector<GURL> startup_urls_; |
| 174 std::vector<GURL> startup_urls_to_reset_; | 150 std::vector<GURL> startup_urls_to_reset_; |
| 175 // Reset domain IDs for URLs in |startup_urls_to_reset_|; | 151 // Reset domain IDs for URLs in |startup_urls_to_reset_|; |
| 176 std::unordered_set<int> domain_ids_for_startup_urls_to_reset_; | 152 std::unordered_set<int> domain_ids_for_startup_urls_to_reset_; |
| 177 ResetState startup_urls_reset_state_; | 153 ResetState startup_urls_reset_state_ = |
| 154 NO_RESET_REQUIRED_DUE_TO_DOMAIN_NOT_MATCHED; |
| 178 | 155 |
| 179 ExtensionMap extensions_to_disable_; | 156 ExtensionMap extensions_to_disable_; |
| 180 | 157 |
| 181 DISALLOW_COPY_AND_ASSIGN(SettingsResetPromptModel); | 158 DISALLOW_COPY_AND_ASSIGN(SettingsResetPromptModel); |
| 182 }; | 159 }; |
| 183 | 160 |
| 184 } // namespace safe_browsing | 161 } // namespace safe_browsing |
| 185 | 162 |
| 186 #endif // CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_SETTINGS_RESET_PRO
MPT_MODEL_H_ | 163 #endif // CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_SETTINGS_RESET_PRO
MPT_MODEL_H_ |
| OLD | NEW |