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

Unified Diff: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc

Issue 2918053003: Settings reset prompt: Fetch default settings only when needed. (Closed)
Patch Set: Addressed Chris's comment Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
diff --git a/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc b/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
index 6a1cacd0af502433b11fc57f6250ab886d648754..0d79644dd97f8e4cdf6f14cbececcc9225f92df0 100644
--- a/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
+++ b/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_controller.cc
@@ -10,11 +10,15 @@
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/logging.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/time/time.h"
+#include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
+#include "chrome/browser/profile_resetter/profile_resetter.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/safe_browsing/settings_reset_prompt/default_settings_fetcher.h"
#include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config.h"
#include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_model.h"
#include "chrome/browser/ui/browser.h"
@@ -50,25 +54,16 @@ bool ResetHomepageEnabled(const SettingsResetPromptModel& model) {
SettingsResetPromptModel::RESET_REQUIRED;
}
-// Function that is passed the newly created |SettingsResetPromptModel| object
-// as a result of a call to |MaybeShowSettingsResetPrompt()| below. Will display
-// the settings reset prompt if required by the model and there is at least one
-// non-incognito browser available for the corresponding profile.
-void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) {
- if (!model)
- return;
-
- model->ReportUmaMetrics();
-
- if (!model->ShouldPromptForReset())
- return;
-
- Profile* profile = model->profile();
+void TryToShowSettingsResetPrompt(
+ std::unique_ptr<SettingsResetPromptModel> model,
+ std::unique_ptr<BrandcodedDefaultSettings> default_settings) {
+ DCHECK(model);
+ DCHECK(default_settings);
// Ensure that there is at least one non-incognito browser open for the
// profile before attempting to show the dialog.
- Browser* browser =
- chrome::FindTabbedBrowser(profile, /*match_original_profiles=*/false);
+ Browser* browser = chrome::FindTabbedBrowser(
+ model->profile(), /*match_original_profiles=*/false);
if (!browser)
return;
@@ -81,9 +76,12 @@ void OnModelCreated(std::unique_ptr<SettingsResetPromptModel> model) {
// The |SettingsResetPromptController| object will delete itself after the
// reset prompt dialog has been closed.
SettingsResetPromptController::ShowSettingsResetPrompt(
- browser, new SettingsResetPromptController(std::move(model)));
+ browser, new SettingsResetPromptController(std::move(model),
+ std::move(default_settings)));
}
+// Will display the settings reset prompt if required and if there is at least
+// one non-incognito browser available for the corresponding profile.
void MaybeShowSettingsResetPrompt(
std::unique_ptr<SettingsResetPromptConfig> config) {
DCHECK(config);
@@ -96,17 +94,29 @@ void MaybeShowSettingsResetPrompt(
// ensure that there is at least one non-incognito browser open before
// displaying the dialog.
Profile* profile = browser->profile()->GetOriginalProfile();
- SettingsResetPromptModel::Create(profile, std::move(config),
- base::Bind(OnModelCreated));
+
+ auto model = base::MakeUnique<SettingsResetPromptModel>(
+ profile, std::move(config), base::MakeUnique<ProfileResetter>(profile));
+
+ model->ReportUmaMetrics();
+
+ if (!model->ShouldPromptForReset())
+ return;
+
+ DefaultSettingsFetcher::FetchDefaultSettings(
+ base::Bind(&TryToShowSettingsResetPrompt, base::Passed(&model)));
}
} // namespace.
SettingsResetPromptController::SettingsResetPromptController(
- std::unique_ptr<SettingsResetPromptModel> model)
- : model_(std::move(model)) {
+ std::unique_ptr<SettingsResetPromptModel> model,
+ std::unique_ptr<BrandcodedDefaultSettings> default_settings)
+ : model_(std::move(model)), default_settings_(std::move(default_settings)) {
DCHECK(model_);
DCHECK(model_->ShouldPromptForReset());
+ DCHECK(default_settings_);
+
// In the current implementation of the reset dialog, we ask users to reset
// one settings type. If more than one setting requires reset, the model will
// choose which setting we should prompt the user for.
@@ -158,11 +168,14 @@ void SettingsResetPromptController::DialogShown() {
void SettingsResetPromptController::Accept() {
DCHECK(!time_dialog_shown_.is_null());
+ DCHECK(default_settings_);
+
base::RecordAction(base::UserMetricsAction("SettingsResetPrompt_Accepted"));
UMA_HISTOGRAM_LONG_TIMES_100("SettingsResetPrompt.TimeUntilAccepted",
base::Time::Now() - time_dialog_shown_);
UMA_HISTOGRAM_BOOLEAN("SettingsResetPrompt.PromptAccepted", true);
model_->PerformReset(
+ std::move(default_settings_),
base::Bind(&SettingsResetPromptController::OnInteractionDone,
base::Unretained(this)));
}

Powered by Google App Engine
This is Rietveld 408576698