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

Side by Side Diff: chrome/browser/ui/webui/options/reset_profile_settings_handler.cc

Issue 533183002: Revert "Eliminate all code related to the AutomaticProfileResetter." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/webui/options/reset_profile_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/reset_profile_settings_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/google/google_brand.h" 13 #include "chrome/browser/google/google_brand.h"
14 #include "chrome/browser/profile_resetter/automatic_profile_resetter.h"
15 #include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
14 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h" 16 #include "chrome/browser/profile_resetter/brandcode_config_fetcher.h"
15 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h" 17 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
16 #include "chrome/browser/profile_resetter/profile_resetter.h" 18 #include "chrome/browser/profile_resetter/profile_resetter.h"
17 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h" 19 #include "chrome/browser/profile_resetter/resettable_settings_snapshot.h"
18 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
20 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
21 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
22 #include "content/public/browser/user_metrics.h" 24 #include "content/public/browser/user_metrics.h"
23 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
24 26
25 namespace options { 27 namespace options {
26 28
27 ResetProfileSettingsHandler::ResetProfileSettingsHandler() { 29 ResetProfileSettingsHandler::ResetProfileSettingsHandler()
30 : automatic_profile_resetter_(NULL),
31 has_shown_confirmation_dialog_(false) {
28 google_brand::GetBrand(&brandcode_); 32 google_brand::GetBrand(&brandcode_);
29 } 33 }
30 34
31 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {} 35 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {}
32 36
33 void ResetProfileSettingsHandler::InitializeHandler() { 37 void ResetProfileSettingsHandler::InitializeHandler() {
34 Profile* profile = Profile::FromWebUI(web_ui()); 38 Profile* profile = Profile::FromWebUI(web_ui());
35 resetter_.reset(new ProfileResetter(profile)); 39 resetter_.reset(new ProfileResetter(profile));
40 automatic_profile_resetter_ =
41 AutomaticProfileResetterFactory::GetForBrowserContext(profile);
36 } 42 }
37 43
38 void ResetProfileSettingsHandler::InitializePage() { 44 void ResetProfileSettingsHandler::InitializePage() {
39 web_ui()->CallJavascriptFunction( 45 web_ui()->CallJavascriptFunction(
40 "ResetProfileSettingsOverlay.setResettingState", 46 "ResetProfileSettingsOverlay.setResettingState",
41 base::FundamentalValue(resetter_->IsActive())); 47 base::FundamentalValue(resetter_->IsActive()));
48 if (automatic_profile_resetter_ &&
49 automatic_profile_resetter_->ShouldShowResetBanner()) {
50 web_ui()->CallJavascriptFunction("ResetProfileSettingsBanner.show");
51 }
52 }
53
54 void ResetProfileSettingsHandler::Uninitialize() {
55 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) {
56 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog(
57 false /*performed_reset*/);
58 }
42 } 59 }
43 60
44 void ResetProfileSettingsHandler::GetLocalizedValues( 61 void ResetProfileSettingsHandler::GetLocalizedValues(
45 base::DictionaryValue* localized_strings) { 62 base::DictionaryValue* localized_strings) {
46 DCHECK(localized_strings); 63 DCHECK(localized_strings);
47 64
48 static OptionsStringResource resources[] = { 65 static OptionsStringResource resources[] = {
66 { "resetProfileSettingsBannerText",
67 IDS_RESET_PROFILE_SETTINGS_BANNER_TEXT },
49 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON }, 68 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON },
50 { "resetProfileSettingsExplanation", 69 { "resetProfileSettingsExplanation",
51 IDS_RESET_PROFILE_SETTINGS_EXPLANATION }, 70 IDS_RESET_PROFILE_SETTINGS_EXPLANATION },
52 { "resetProfileSettingsFeedback", IDS_RESET_PROFILE_SETTINGS_FEEDBACK } 71 { "resetProfileSettingsFeedback", IDS_RESET_PROFILE_SETTINGS_FEEDBACK }
53 }; 72 };
54 73
55 RegisterStrings(localized_strings, resources, arraysize(resources)); 74 RegisterStrings(localized_strings, resources, arraysize(resources));
56 RegisterTitle(localized_strings, "resetProfileSettingsOverlay", 75 RegisterTitle(localized_strings, "resetProfileSettingsOverlay",
57 IDS_RESET_PROFILE_SETTINGS_TITLE); 76 IDS_RESET_PROFILE_SETTINGS_TITLE);
58 localized_strings->SetString( 77 localized_strings->SetString(
59 "resetProfileSettingsLearnMoreUrl", 78 "resetProfileSettingsLearnMoreUrl",
60 chrome::kResetProfileSettingsLearnMoreURL); 79 chrome::kResetProfileSettingsLearnMoreURL);
61 } 80 }
62 81
63 void ResetProfileSettingsHandler::RegisterMessages() { 82 void ResetProfileSettingsHandler::RegisterMessages() {
64 // Setup handlers specific to this panel. 83 // Setup handlers specific to this panel.
65 web_ui()->RegisterMessageCallback("performResetProfileSettings", 84 web_ui()->RegisterMessageCallback("performResetProfileSettings",
66 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, 85 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings,
67 base::Unretained(this))); 86 base::Unretained(this)));
68 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", 87 web_ui()->RegisterMessageCallback("onShowResetProfileDialog",
69 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, 88 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog,
70 base::Unretained(this))); 89 base::Unretained(this)));
71 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", 90 web_ui()->RegisterMessageCallback("onHideResetProfileDialog",
72 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, 91 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog,
73 base::Unretained(this))); 92 base::Unretained(this)));
93 web_ui()->RegisterMessageCallback("onDismissedResetProfileSettingsBanner",
94 base::Bind(&ResetProfileSettingsHandler::
95 OnDismissedResetProfileSettingsBanner,
96 base::Unretained(this)));
74 } 97 }
75 98
76 void ResetProfileSettingsHandler::HandleResetProfileSettings( 99 void ResetProfileSettingsHandler::HandleResetProfileSettings(
77 const base::ListValue* value) { 100 const base::ListValue* value) {
78 bool send_settings = false; 101 bool send_settings = false;
79 if (!value->GetBoolean(0, &send_settings)) 102 if (!value->GetBoolean(0, &send_settings))
80 NOTREACHED(); 103 NOTREACHED();
81 104
82 DCHECK(brandcode_.empty() || config_fetcher_); 105 DCHECK(brandcode_.empty() || config_fetcher_);
83 if (config_fetcher_ && config_fetcher_->IsActive()) { 106 if (config_fetcher_ && config_fetcher_->IsActive()) {
(...skipping 11 matching lines...) Expand all
95 bool send_feedback) { 118 bool send_feedback) {
96 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); 119 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting");
97 if (send_feedback && setting_snapshot_) { 120 if (send_feedback && setting_snapshot_) {
98 Profile* profile = Profile::FromWebUI(web_ui()); 121 Profile* profile = Profile::FromWebUI(web_ui());
99 ResettableSettingsSnapshot current_snapshot(profile); 122 ResettableSettingsSnapshot current_snapshot(profile);
100 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); 123 int difference = setting_snapshot_->FindDifferentFields(current_snapshot);
101 if (difference) { 124 if (difference) {
102 setting_snapshot_->Subtract(current_snapshot); 125 setting_snapshot_->Subtract(current_snapshot);
103 std::string report = SerializeSettingsReport(*setting_snapshot_, 126 std::string report = SerializeSettingsReport(*setting_snapshot_,
104 difference); 127 difference);
105 SendSettingsFeedback(report, profile); 128 bool is_reset_prompt_active = automatic_profile_resetter_ &&
129 automatic_profile_resetter_->IsResetPromptFlowActive();
130 SendSettingsFeedback(report, profile, is_reset_prompt_active ?
131 PROFILE_RESET_PROMPT : PROFILE_RESET_WEBUI);
106 } 132 }
107 } 133 }
108 setting_snapshot_.reset(); 134 setting_snapshot_.reset();
135 if (automatic_profile_resetter_) {
136 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog(
137 true /*performed_reset*/);
138 }
109 } 139 }
110 140
111 void ResetProfileSettingsHandler::OnShowResetProfileDialog( 141 void ResetProfileSettingsHandler::OnShowResetProfileDialog(
112 const base::ListValue* value) { 142 const base::ListValue* value) {
113 if (!resetter_->IsActive()) { 143 if (!resetter_->IsActive()) {
114 setting_snapshot_.reset( 144 setting_snapshot_.reset(
115 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui()))); 145 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui())));
116 setting_snapshot_->RequestShortcuts(base::Bind( 146 setting_snapshot_->RequestShortcuts(base::Bind(
117 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr())); 147 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr()));
118 UpdateFeedbackUI(); 148 UpdateFeedbackUI();
119 } 149 }
120 150
151 if (automatic_profile_resetter_)
152 automatic_profile_resetter_->NotifyDidOpenWebUIResetDialog();
153 has_shown_confirmation_dialog_ = true;
154
121 if (brandcode_.empty()) 155 if (brandcode_.empty())
122 return; 156 return;
123 config_fetcher_.reset(new BrandcodeConfigFetcher( 157 config_fetcher_.reset(new BrandcodeConfigFetcher(
124 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched, 158 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched,
125 Unretained(this)), 159 Unretained(this)),
126 GURL("https://tools.google.com/service/update2"), 160 GURL("https://tools.google.com/service/update2"),
127 brandcode_)); 161 brandcode_));
128 } 162 }
129 163
130 void ResetProfileSettingsHandler::OnHideResetProfileDialog( 164 void ResetProfileSettingsHandler::OnHideResetProfileDialog(
131 const base::ListValue* value) { 165 const base::ListValue* value) {
132 if (!resetter_->IsActive()) 166 if (!resetter_->IsActive())
133 setting_snapshot_.reset(); 167 setting_snapshot_.reset();
134 } 168 }
135 169
170 void ResetProfileSettingsHandler::OnDismissedResetProfileSettingsBanner(
171 const base::ListValue* args) {
172 if (automatic_profile_resetter_)
173 automatic_profile_resetter_->NotifyDidCloseWebUIResetBanner();
174 }
175
136 void ResetProfileSettingsHandler::OnSettingsFetched() { 176 void ResetProfileSettingsHandler::OnSettingsFetched() {
137 DCHECK(config_fetcher_); 177 DCHECK(config_fetcher_);
138 DCHECK(!config_fetcher_->IsActive()); 178 DCHECK(!config_fetcher_->IsActive());
139 // The master prefs is fetched. We are waiting for user pressing 'Reset'. 179 // The master prefs is fetched. We are waiting for user pressing 'Reset'.
140 } 180 }
141 181
142 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) { 182 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) {
143 DCHECK(resetter_); 183 DCHECK(resetter_);
144 DCHECK(!resetter_->IsActive()); 184 DCHECK(!resetter_->IsActive());
145 185
(...skipping 28 matching lines...) Expand all
174 Profile::FromWebUI(web_ui()), 214 Profile::FromWebUI(web_ui()),
175 *setting_snapshot_); 215 *setting_snapshot_);
176 base::DictionaryValue feedback_info; 216 base::DictionaryValue feedback_info;
177 feedback_info.Set("feedbackInfo", list.release()); 217 feedback_info.Set("feedbackInfo", list.release());
178 web_ui()->CallJavascriptFunction( 218 web_ui()->CallJavascriptFunction(
179 "ResetProfileSettingsOverlay.setFeedbackInfo", 219 "ResetProfileSettingsOverlay.setFeedbackInfo",
180 feedback_info); 220 feedback_info);
181 } 221 }
182 222
183 } // namespace options 223 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/reset_profile_settings_handler.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698