| 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 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_model.h" | 5 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_model.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/google/google_brand.h" | 13 #include "chrome/browser/google/google_brand.h" |
| 13 #include "chrome/browser/prefs/session_startup_pref.h" | 14 #include "chrome/browser/prefs/session_startup_pref.h" |
| 14 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" | 15 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" |
| 15 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" | 16 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" |
| 16 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" | 17 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" | 19 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" |
| 19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 20 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.
h" | 21 #include "chrome/common/extensions/manifest_handlers/settings_overrides_handler.
h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 23 #include "components/search_engines/template_url_service.h" | 24 #include "components/search_engines/template_url_service.h" |
| 24 #include "components/url_formatter/url_fixer.h" | 25 #include "components/url_formatter/url_fixer.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "extensions/browser/extension_registry.h" | 27 #include "extensions/browser/extension_registry.h" |
| 27 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 29 #include "extensions/common/extension_id.h" | 30 #include "extensions/common/extension_id.h" |
| 30 #include "extensions/common/extension_set.h" | 31 #include "extensions/common/extension_set.h" |
| 31 | 32 |
| 32 namespace safe_browsing { | 33 namespace safe_browsing { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 #if defined(GOOGLE_CHROME_BUILD) | 37 #if defined(GOOGLE_CHROME_BUILD) |
| 37 constexpr char kOmahaUrl[] = "https://tools.google.com/service/update2"; | 38 constexpr char kOmahaUrl[] = "https://tools.google.com/service/update2"; |
| 38 #endif // defined(GOOGLE_CHROME_BUILD) | 39 #endif // defined(GOOGLE_CHROME_BUILD) |
| 39 | 40 |
| 41 // These values are used for UMA metrics reporting. New enum values can be |
| 42 // added, but existing enums must never be renumbered or deleted and reused. |
| 43 enum SettingsReset { |
| 44 SETTINGS_RESET_HOMEPAGE = 1, |
| 45 SETTINGS_RESET_DEFAULT_SEARCH = 2, |
| 46 SETTINGS_RESET_STARTUP_URLS = 3, |
| 47 SETTINGS_RESET_MAX, |
| 48 }; |
| 49 |
| 40 // Used to keep track of which settings types have been initialized in | 50 // Used to keep track of which settings types have been initialized in |
| 41 // |SettingsResetPromptModel|. | 51 // |SettingsResetPromptModel|. |
| 42 enum SettingsType : uint32_t { | 52 enum SettingsType : uint32_t { |
| 43 SETTINGS_TYPE_HOMEPAGE = 1 << 0, | 53 SETTINGS_TYPE_HOMEPAGE = 1 << 0, |
| 44 SETTINGS_TYPE_DEFAULT_SEARCH = 1 << 1, | 54 SETTINGS_TYPE_DEFAULT_SEARCH = 1 << 1, |
| 45 SETTINGS_TYPE_STARTUP_URLS = 1 << 2, | 55 SETTINGS_TYPE_STARTUP_URLS = 1 << 2, |
| 46 SETTINGS_TYPE_ALL = SETTINGS_TYPE_HOMEPAGE | SETTINGS_TYPE_DEFAULT_SEARCH | | 56 SETTINGS_TYPE_ALL = SETTINGS_TYPE_HOMEPAGE | SETTINGS_TYPE_DEFAULT_SEARCH | |
| 47 SETTINGS_TYPE_STARTUP_URLS, | 57 SETTINGS_TYPE_STARTUP_URLS, |
| 48 }; | 58 }; |
| 49 | 59 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 212 |
| 203 // Disable all extensions that override settings that need to be reset. | 213 // Disable all extensions that override settings that need to be reset. |
| 204 ExtensionService* extension_service = | 214 ExtensionService* extension_service = |
| 205 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 215 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 206 DCHECK(extension_service); | 216 DCHECK(extension_service); |
| 207 for (const auto& item : extensions_to_disable()) { | 217 for (const auto& item : extensions_to_disable()) { |
| 208 const extensions::ExtensionId& extension_id = item.first; | 218 const extensions::ExtensionId& extension_id = item.first; |
| 209 extension_service->DisableExtension( | 219 extension_service->DisableExtension( |
| 210 extension_id, extensions::Extension::DISABLE_USER_ACTION); | 220 extension_id, extensions::Extension::DISABLE_USER_ACTION); |
| 211 } | 221 } |
| 222 UMA_HISTOGRAM_COUNTS_100("SettingsResetPrompt.NumberOfExtensionsDisabled", |
| 223 extensions_to_disable().size()); |
| 212 | 224 |
| 213 // Disable all the settings that need to be reset. | 225 // Disable all the settings that need to be reset. |
| 214 ProfileResetter::ResettableFlags reset_flags = 0; | 226 ProfileResetter::ResettableFlags reset_flags = 0; |
| 215 if (homepage_reset_state() == RESET_REQUIRED) | 227 if (homepage_reset_state() == RESET_REQUIRED) { |
| 216 reset_flags |= ProfileResetter::HOMEPAGE; | 228 reset_flags |= ProfileResetter::HOMEPAGE; |
| 217 if (default_search_reset_state() == RESET_REQUIRED) | 229 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.SettingsReset", |
| 230 SETTINGS_RESET_HOMEPAGE, SETTINGS_RESET_MAX); |
| 231 } |
| 232 if (default_search_reset_state() == RESET_REQUIRED) { |
| 218 reset_flags |= ProfileResetter::DEFAULT_SEARCH_ENGINE; | 233 reset_flags |= ProfileResetter::DEFAULT_SEARCH_ENGINE; |
| 219 if (startup_urls_reset_state() == RESET_REQUIRED) | 234 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.SettingsReset", |
| 235 SETTINGS_RESET_DEFAULT_SEARCH, |
| 236 SETTINGS_RESET_MAX); |
| 237 } |
| 238 if (startup_urls_reset_state() == RESET_REQUIRED) { |
| 220 reset_flags |= ProfileResetter::STARTUP_PAGES; | 239 reset_flags |= ProfileResetter::STARTUP_PAGES; |
| 240 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.SettingsReset", |
| 241 SETTINGS_RESET_STARTUP_URLS, SETTINGS_RESET_MAX); |
| 242 } |
| 243 |
| 221 profile_resetter_->Reset(reset_flags, std::move(default_settings_), | 244 profile_resetter_->Reset(reset_flags, std::move(default_settings_), |
| 222 done_callback); | 245 done_callback); |
| 223 } | 246 } |
| 224 | 247 |
| 225 void SettingsResetPromptModel::DialogShown() { | 248 void SettingsResetPromptModel::DialogShown() { |
| 226 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 249 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 227 DCHECK(SomeSettingRequiresReset()); | 250 DCHECK(SomeSettingRequiresReset()); |
| 228 | 251 |
| 229 base::Time now = base::Time::Now(); | 252 base::Time now = base::Time::Now(); |
| 230 if (default_search_reset_state() == RESET_REQUIRED) | 253 if (default_search_reset_state() == RESET_REQUIRED) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 SettingsResetPromptModel::ResetState | 292 SettingsResetPromptModel::ResetState |
| 270 SettingsResetPromptModel::startup_urls_reset_state() const { | 293 SettingsResetPromptModel::startup_urls_reset_state() const { |
| 271 return startup_urls_reset_state_; | 294 return startup_urls_reset_state_; |
| 272 } | 295 } |
| 273 | 296 |
| 274 const SettingsResetPromptModel::ExtensionMap& | 297 const SettingsResetPromptModel::ExtensionMap& |
| 275 SettingsResetPromptModel::extensions_to_disable() const { | 298 SettingsResetPromptModel::extensions_to_disable() const { |
| 276 return extensions_to_disable_; | 299 return extensions_to_disable_; |
| 277 } | 300 } |
| 278 | 301 |
| 302 void SettingsResetPromptModel::ReportUmaMetrics() const { |
| 303 UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.PromptRequired", |
| 304 ShouldPromptForReset()); |
| 305 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.ResetState_DefaultSearch", |
| 306 default_search_reset_state(), RESET_STATE_MAX); |
| 307 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.ResetState_StartupUrls", |
| 308 startup_urls_reset_state(), RESET_STATE_MAX); |
| 309 UMA_HISTOGRAM_ENUMERATION("SettingsResetPrompt.ResetState_Homepage", |
| 310 homepage_reset_state(), RESET_STATE_MAX); |
| 311 UMA_HISTOGRAM_COUNTS_100("SettingsResetPrompt.NumberOfExtensionsToDisable", |
| 312 extensions_to_disable().size()); |
| 313 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 314 "SettingsResetPrompt.DelayBeforePromptParam", |
| 315 prompt_config_->delay_before_prompt().InSeconds()); |
| 316 } |
| 317 |
| 279 // static | 318 // static |
| 280 void SettingsResetPromptModel::OnSettingsFetched( | 319 void SettingsResetPromptModel::OnSettingsFetched( |
| 281 Profile* profile, | 320 Profile* profile, |
| 282 std::unique_ptr<SettingsResetPromptConfig> prompt_config, | 321 std::unique_ptr<SettingsResetPromptConfig> prompt_config, |
| 283 SettingsResetPromptModel::CreateCallback callback, | 322 SettingsResetPromptModel::CreateCallback callback, |
| 284 std::unique_ptr<BrandcodedDefaultSettings> default_settings) { | 323 std::unique_ptr<BrandcodedDefaultSettings> default_settings) { |
| 285 DCHECK(profile); | 324 DCHECK(profile); |
| 286 DCHECK(prompt_config); | 325 DCHECK(prompt_config); |
| 287 DCHECK(default_settings); | 326 DCHECK(default_settings); |
| 288 | 327 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 GetExtension(profile_, extension_id); | 553 GetExtension(profile_, extension_id); |
| 515 if (extension && management_policy->MustRemainEnabled(extension, nullptr)) | 554 if (extension && management_policy->MustRemainEnabled(extension, nullptr)) |
| 516 return true; | 555 return true; |
| 517 } | 556 } |
| 518 } | 557 } |
| 519 | 558 |
| 520 return false; | 559 return false; |
| 521 } | 560 } |
| 522 | 561 |
| 523 } // namespace safe_browsing. | 562 } // namespace safe_browsing. |
| OLD | NEW |