Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_model.h

Issue 2727063006: Settings reset prompt: add startup logic (Closed)
Patch Set: Nits Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <string> 11 #include <string>
12 #include <unordered_map> 12 #include <unordered_map>
13 #include <unordered_set> 13 #include <unordered_set>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/callback_forward.h" 16 #include "base/callback_forward.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/time/time.h"
18 #include "chrome/browser/safe_browsing/settings_reset_prompt/extension_info.h" 19 #include "chrome/browser/safe_browsing/settings_reset_prompt/extension_info.h"
20 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom pt_prefs_manager.h"
19 #include "extensions/common/extension_id.h" 21 #include "extensions/common/extension_id.h"
20 #include "url/gurl.h" 22 #include "url/gurl.h"
21 23
22 class BrandcodedDefaultSettings; 24 class BrandcodedDefaultSettings;
23 class Profile; 25 class Profile;
24 class ProfileResetter; 26 class ProfileResetter;
25 class ResettableSettingsSnapshot; 27 class ResettableSettingsSnapshot;
26 28
27 namespace safe_browsing { 29 namespace safe_browsing {
28 30
29 class SettingsResetPromptConfig; 31 class SettingsResetPromptConfig;
30 32
31 // Encapsulates information about settings needed for the settings reset prompt 33 // Encapsulates information about settings needed for the settings reset prompt
32 // and implements the reset logic. 34 // and implements the reset logic.
33 // 35 //
34 // When more than one setting has a match in the list of domains in the config 36 // When more than one setting has a match in the list of domains in the config
35 // object, the model chooses one of the settings for reset based on the 37 // object, the model chooses one of the settings for reset based on the
36 // following priority list: 38 // following priority list:
37 // 1. Default search engine 39 // 1. Default search engine
38 // 2. Startup URLs 40 // 2. Startup URLs
39 // 3. Homepage 41 // 3. Homepage
40 class SettingsResetPromptModel { 42 class SettingsResetPromptModel {
41 public: 43 public:
42 enum ResetState { 44 enum ResetState {
43 RESET_REQUIRED = 1, 45 RESET_REQUIRED = 1,
44 NO_RESET_REQUIRED_DUE_TO_DOMAIN_NOT_MATCHED = 2, 46 NO_RESET_REQUIRED_DUE_TO_DOMAIN_NOT_MATCHED = 2,
45 NO_RESET_REQUIRED_DUE_TO_OTHER_SETTING_REQUIRING_RESET = 3, 47 NO_RESET_REQUIRED_DUE_TO_ALREADY_PROMPTED_FOR_SETTING = 3,
48 NO_RESET_REQUIRED_DUE_TO_RECENTLY_PROMPTED = 4,
49 NO_RESET_REQUIRED_DUE_TO_OTHER_SETTING_REQUIRING_RESET = 5,
46 }; 50 };
47 51
48 using ExtensionMap = 52 using ExtensionMap =
49 std::unordered_map<extensions::ExtensionId, ExtensionInfo>; 53 std::unordered_map<extensions::ExtensionId, ExtensionInfo>;
50 using CreateCallback = 54 using CreateCallback =
51 base::Callback<void(std::unique_ptr<SettingsResetPromptModel>)>; 55 base::Callback<void(std::unique_ptr<SettingsResetPromptModel>)>;
52 56
53 // Creates a new |SettingsResetPromptModel| and passes it to |callback|. This 57 // Creates a new |SettingsResetPromptModel| and passes it to |callback|. This
54 // function should be called on the UI thread. 58 // function should be called on the UI thread.
55 static void Create(Profile* profile, 59 static void Create(Profile* profile,
(...skipping 13 matching lines...) Expand all
69 73
70 // Returns true if reset is enabled for any settings type. 74 // Returns true if reset is enabled for any settings type.
71 virtual bool ShouldPromptForReset() const; 75 virtual bool ShouldPromptForReset() const;
72 // Resets the settings whose reset states are set to |RESET_REQUIRED| as 76 // Resets the settings whose reset states are set to |RESET_REQUIRED| as
73 // returned by the methods below. Should be called only on the UI 77 // returned by the methods below. Should be called only on the UI
74 // thread. |done_callback| will called from the UI thread when the reset 78 // thread. |done_callback| will called from the UI thread when the reset
75 // operation has been completed. 79 // operation has been completed.
76 // 80 //
77 // NOTE: Can only be called once during the lifetime of this object. 81 // NOTE: Can only be called once during the lifetime of this object.
78 virtual void PerformReset(const base::Closure& done_callback); 82 virtual void PerformReset(const base::Closure& done_callback);
83 // To be called when the reset prompt dialog has been shown so that
84 // preferences can be updated.
85 virtual void DialogShown();
79 86
80 virtual GURL homepage() const; 87 virtual GURL homepage() const;
81 virtual ResetState homepage_reset_state() const; 88 virtual ResetState homepage_reset_state() const;
82 89
83 virtual GURL default_search() const; 90 virtual GURL default_search() const;
84 virtual ResetState default_search_reset_state() const; 91 virtual ResetState default_search_reset_state() const;
85 92
86 // Returns list of all current startup URLs. Returns empty list if session 93 // Returns list of all current startup URLs. Returns empty list if session
87 // startup is set to show the NTP or restore last session. 94 // startup is set to show the NTP or restore last session.
88 virtual const std::vector<GURL>& startup_urls() const; 95 virtual const std::vector<GURL>& startup_urls() const;
(...skipping 23 matching lines...) Expand all
112 std::unique_ptr<BrandcodedDefaultSettings> default_settings); 119 std::unique_ptr<BrandcodedDefaultSettings> default_settings);
113 120
114 // Functions to be called by the constructor to initialize the model 121 // Functions to be called by the constructor to initialize the model
115 // object. These functions should be called in the order in which they are 122 // object. These functions should be called in the order in which they are
116 // declared here so that the correct setting is chosen for the prompt when 123 // declared here so that the correct setting is chosen for the prompt when
117 // more than one setting requires reset (see also the class description). 124 // more than one setting requires reset (see also the class description).
118 void InitDefaultSearchData(); 125 void InitDefaultSearchData();
119 void InitStartupUrlsData(); 126 void InitStartupUrlsData();
120 void InitHomepageData(); 127 void InitHomepageData();
121 void InitExtensionData(); 128 void InitExtensionData();
129
130 // Helper function for the Init* functions above to determine the reset state
131 // of settings that have a match in the config.
132 ResetState GetResetStateForSetting(
133 const base::Time& last_triggered_for_setting) const;
134
122 // Return true if any setting's reset state is set to |RESET_REQUIRED|. 135 // Return true if any setting's reset state is set to |RESET_REQUIRED|.
123 bool SomeSettingRequiresReset() const; 136 bool SomeSettingRequiresReset() const;
124 137
125 Profile* const profile_; 138 Profile* const profile_;
139
140 SettingsResetPromptPrefsManager prefs_manager_;
126 std::unique_ptr<SettingsResetPromptConfig> prompt_config_; 141 std::unique_ptr<SettingsResetPromptConfig> prompt_config_;
127 std::unique_ptr<ResettableSettingsSnapshot> settings_snapshot_; 142 std::unique_ptr<ResettableSettingsSnapshot> settings_snapshot_;
128 // |default_settings_| should only be accessed on the UI thread after 143 // |default_settings_| should only be accessed on the UI thread after
129 // construction. 144 // construction.
130 std::unique_ptr<BrandcodedDefaultSettings> default_settings_; 145 std::unique_ptr<BrandcodedDefaultSettings> default_settings_;
131 std::unique_ptr<ProfileResetter> profile_resetter_; 146 std::unique_ptr<ProfileResetter> profile_resetter_;
132 147
148 // A single timestamp to be used by all initialization functions to determine
149 // if enough time has passed between the last time the prompt was shown and
150 // "now" for a new prompt to be shown.
151 base::Time now_;
152 // The time since the last prompt was shown for any setting.
153 base::TimeDelta time_since_last_prompt_;
154
133 // Bits to keep track of which settings types have been initialized. 155 // Bits to keep track of which settings types have been initialized.
134 uint32_t settings_types_initialized_; 156 uint32_t settings_types_initialized_;
135 157
136 GURL homepage_url_; 158 GURL homepage_url_;
137 int homepage_reset_domain_id_; 159 int homepage_reset_domain_id_;
138 ResetState homepage_reset_state_; 160 ResetState homepage_reset_state_;
139 161
140 GURL default_search_url_; 162 GURL default_search_url_;
141 int default_search_reset_domain_id_; 163 int default_search_reset_domain_id_;
142 ResetState default_search_reset_state_; 164 ResetState default_search_reset_state_;
143 165
144 std::vector<GURL> startup_urls_; 166 std::vector<GURL> startup_urls_;
145 std::vector<GURL> startup_urls_to_reset_; 167 std::vector<GURL> startup_urls_to_reset_;
146 // Reset domain IDs for URLs in |startup_urls_to_reset_|; 168 // Reset domain IDs for URLs in |startup_urls_to_reset_|;
147 std::unordered_set<int> domain_ids_for_startup_urls_to_reset_; 169 std::unordered_set<int> domain_ids_for_startup_urls_to_reset_;
148 ResetState startup_urls_reset_state_; 170 ResetState startup_urls_reset_state_;
149 171
150 ExtensionMap extensions_to_disable_; 172 ExtensionMap extensions_to_disable_;
151 173
152 DISALLOW_COPY_AND_ASSIGN(SettingsResetPromptModel); 174 DISALLOW_COPY_AND_ASSIGN(SettingsResetPromptModel);
153 }; 175 };
154 176
155 } // namespace safe_browsing 177 } // namespace safe_browsing
156 178
157 #endif // CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_SETTINGS_RESET_PRO MPT_MODEL_H_ 179 #endif // CHROME_BROWSER_SAFE_BROWSING_SETTINGS_RESET_PROMPT_SETTINGS_RESET_PRO MPT_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698