OLD | NEW |
---|---|
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), has_shown_confirmation_dialog_(false) { | |
Dan Beam
2014/09/05 19:21:45
nit: \n after ,
engedy
2014/09/10 13:46:26
Done.
| |
28 google_brand::GetBrand(&brandcode_); | 31 google_brand::GetBrand(&brandcode_); |
29 } | 32 } |
30 | 33 |
31 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {} | 34 ResetProfileSettingsHandler::~ResetProfileSettingsHandler() {} |
32 | 35 |
33 void ResetProfileSettingsHandler::InitializeHandler() { | 36 void ResetProfileSettingsHandler::InitializeHandler() { |
34 Profile* profile = Profile::FromWebUI(web_ui()); | 37 Profile* profile = Profile::FromWebUI(web_ui()); |
35 resetter_.reset(new ProfileResetter(profile)); | 38 resetter_.reset(new ProfileResetter(profile)); |
39 automatic_profile_resetter_ = | |
40 AutomaticProfileResetterFactory::GetForBrowserContext(profile); | |
36 } | 41 } |
37 | 42 |
38 void ResetProfileSettingsHandler::InitializePage() { | 43 void ResetProfileSettingsHandler::InitializePage() { |
39 web_ui()->CallJavascriptFunction( | 44 web_ui()->CallJavascriptFunction( |
40 "ResetProfileSettingsOverlay.setResettingState", | 45 "ResetProfileSettingsOverlay.setResettingState", |
41 base::FundamentalValue(resetter_->IsActive())); | 46 base::FundamentalValue(resetter_->IsActive())); |
47 if (automatic_profile_resetter_ && | |
48 automatic_profile_resetter_->ShouldShowResetBanner()) | |
Dan Beam
2014/09/05 19:21:45
curlies
engedy
2014/09/10 13:46:26
Done.
| |
49 web_ui()->CallJavascriptFunction("ResetProfileSettingsBanner.show"); | |
50 } | |
51 | |
52 void ResetProfileSettingsHandler::Uninitialize() { | |
53 if (has_shown_confirmation_dialog_ && automatic_profile_resetter_) { | |
54 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( | |
55 false /*performed_reset*/); | |
56 } | |
42 } | 57 } |
43 | 58 |
44 void ResetProfileSettingsHandler::GetLocalizedValues( | 59 void ResetProfileSettingsHandler::GetLocalizedValues( |
45 base::DictionaryValue* localized_strings) { | 60 base::DictionaryValue* localized_strings) { |
46 DCHECK(localized_strings); | 61 DCHECK(localized_strings); |
47 | 62 |
48 static OptionsStringResource resources[] = { | 63 static OptionsStringResource resources[] = { |
64 { "resetProfileSettingsBannerText", | |
65 IDS_RESET_PROFILE_SETTINGS_BANNER_TEXT }, | |
49 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON }, | 66 { "resetProfileSettingsCommit", IDS_RESET_PROFILE_SETTINGS_COMMIT_BUTTON }, |
50 { "resetProfileSettingsExplanation", | 67 { "resetProfileSettingsExplanation", |
51 IDS_RESET_PROFILE_SETTINGS_EXPLANATION }, | 68 IDS_RESET_PROFILE_SETTINGS_EXPLANATION }, |
52 { "resetProfileSettingsFeedback", IDS_RESET_PROFILE_SETTINGS_FEEDBACK } | 69 { "resetProfileSettingsFeedback", IDS_RESET_PROFILE_SETTINGS_FEEDBACK } |
53 }; | 70 }; |
54 | 71 |
55 RegisterStrings(localized_strings, resources, arraysize(resources)); | 72 RegisterStrings(localized_strings, resources, arraysize(resources)); |
56 RegisterTitle(localized_strings, "resetProfileSettingsOverlay", | 73 RegisterTitle(localized_strings, "resetProfileSettingsOverlay", |
57 IDS_RESET_PROFILE_SETTINGS_TITLE); | 74 IDS_RESET_PROFILE_SETTINGS_TITLE); |
58 localized_strings->SetString( | 75 localized_strings->SetString( |
59 "resetProfileSettingsLearnMoreUrl", | 76 "resetProfileSettingsLearnMoreUrl", |
60 chrome::kResetProfileSettingsLearnMoreURL); | 77 chrome::kResetProfileSettingsLearnMoreURL); |
61 } | 78 } |
62 | 79 |
63 void ResetProfileSettingsHandler::RegisterMessages() { | 80 void ResetProfileSettingsHandler::RegisterMessages() { |
64 // Setup handlers specific to this panel. | 81 // Setup handlers specific to this panel. |
65 web_ui()->RegisterMessageCallback("performResetProfileSettings", | 82 web_ui()->RegisterMessageCallback("performResetProfileSettings", |
66 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, | 83 base::Bind(&ResetProfileSettingsHandler::HandleResetProfileSettings, |
67 base::Unretained(this))); | 84 base::Unretained(this))); |
68 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", | 85 web_ui()->RegisterMessageCallback("onShowResetProfileDialog", |
69 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, | 86 base::Bind(&ResetProfileSettingsHandler::OnShowResetProfileDialog, |
70 base::Unretained(this))); | 87 base::Unretained(this))); |
71 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", | 88 web_ui()->RegisterMessageCallback("onHideResetProfileDialog", |
72 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, | 89 base::Bind(&ResetProfileSettingsHandler::OnHideResetProfileDialog, |
73 base::Unretained(this))); | 90 base::Unretained(this))); |
91 web_ui()->RegisterMessageCallback("onDismissedResetProfileSettingsBanner", | |
92 base::Bind(&ResetProfileSettingsHandler:: | |
93 OnDismissedResetProfileSettingsBanner, | |
Dan Beam
2014/09/05 19:21:45
usually these methods are named HandleChromeSendNa
engedy
2014/09/10 13:46:26
True. However, the messages above also use this di
Dan Beam
2014/09/10 19:14:44
I don't say I feel *strongly* as there is a bit of
| |
94 base::Unretained(this))); | |
74 } | 95 } |
75 | 96 |
76 void ResetProfileSettingsHandler::HandleResetProfileSettings( | 97 void ResetProfileSettingsHandler::HandleResetProfileSettings( |
77 const base::ListValue* value) { | 98 const base::ListValue* value) { |
78 bool send_settings = false; | 99 bool send_settings = false; |
79 if (!value->GetBoolean(0, &send_settings)) | 100 if (!value->GetBoolean(0, &send_settings)) |
80 NOTREACHED(); | 101 NOTREACHED(); |
81 | 102 |
82 DCHECK(brandcode_.empty() || config_fetcher_); | 103 DCHECK(brandcode_.empty() || config_fetcher_); |
83 if (config_fetcher_ && config_fetcher_->IsActive()) { | 104 if (config_fetcher_ && config_fetcher_->IsActive()) { |
(...skipping 11 matching lines...) Expand all Loading... | |
95 bool send_feedback) { | 116 bool send_feedback) { |
96 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); | 117 web_ui()->CallJavascriptFunction("ResetProfileSettingsOverlay.doneResetting"); |
97 if (send_feedback && setting_snapshot_) { | 118 if (send_feedback && setting_snapshot_) { |
98 Profile* profile = Profile::FromWebUI(web_ui()); | 119 Profile* profile = Profile::FromWebUI(web_ui()); |
99 ResettableSettingsSnapshot current_snapshot(profile); | 120 ResettableSettingsSnapshot current_snapshot(profile); |
100 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); | 121 int difference = setting_snapshot_->FindDifferentFields(current_snapshot); |
101 if (difference) { | 122 if (difference) { |
102 setting_snapshot_->Subtract(current_snapshot); | 123 setting_snapshot_->Subtract(current_snapshot); |
103 std::string report = SerializeSettingsReport(*setting_snapshot_, | 124 std::string report = SerializeSettingsReport(*setting_snapshot_, |
104 difference); | 125 difference); |
105 SendSettingsFeedback(report, profile); | 126 bool is_reset_prompt_active = automatic_profile_resetter_ && |
127 automatic_profile_resetter_->IsResetPromptFlowActive(); | |
128 SendSettingsFeedback(report, profile, is_reset_prompt_active ? | |
129 PROFILE_RESET_PROMPT : PROFILE_RESET_WEBUI); | |
106 } | 130 } |
107 } | 131 } |
108 setting_snapshot_.reset(); | 132 setting_snapshot_.reset(); |
133 if (automatic_profile_resetter_) { | |
134 automatic_profile_resetter_->NotifyDidCloseWebUIResetDialog( | |
135 true /*performed_reset*/); | |
136 } | |
109 } | 137 } |
110 | 138 |
111 void ResetProfileSettingsHandler::OnShowResetProfileDialog( | 139 void ResetProfileSettingsHandler::OnShowResetProfileDialog( |
112 const base::ListValue* value) { | 140 const base::ListValue* value) { |
113 if (!resetter_->IsActive()) { | 141 if (!resetter_->IsActive()) { |
114 setting_snapshot_.reset( | 142 setting_snapshot_.reset( |
115 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui()))); | 143 new ResettableSettingsSnapshot(Profile::FromWebUI(web_ui()))); |
116 setting_snapshot_->RequestShortcuts(base::Bind( | 144 setting_snapshot_->RequestShortcuts(base::Bind( |
117 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr())); | 145 &ResetProfileSettingsHandler::UpdateFeedbackUI, AsWeakPtr())); |
118 UpdateFeedbackUI(); | 146 UpdateFeedbackUI(); |
119 } | 147 } |
120 | 148 |
149 if (automatic_profile_resetter_) | |
150 automatic_profile_resetter_->NotifyDidOpenWebUIResetDialog(); | |
151 has_shown_confirmation_dialog_ = true; | |
152 | |
121 if (brandcode_.empty()) | 153 if (brandcode_.empty()) |
122 return; | 154 return; |
123 config_fetcher_.reset(new BrandcodeConfigFetcher( | 155 config_fetcher_.reset(new BrandcodeConfigFetcher( |
124 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched, | 156 base::Bind(&ResetProfileSettingsHandler::OnSettingsFetched, |
125 Unretained(this)), | 157 Unretained(this)), |
126 GURL("https://tools.google.com/service/update2"), | 158 GURL("https://tools.google.com/service/update2"), |
127 brandcode_)); | 159 brandcode_)); |
128 } | 160 } |
129 | 161 |
130 void ResetProfileSettingsHandler::OnHideResetProfileDialog( | 162 void ResetProfileSettingsHandler::OnHideResetProfileDialog( |
131 const base::ListValue* value) { | 163 const base::ListValue* value) { |
132 if (!resetter_->IsActive()) | 164 if (!resetter_->IsActive()) |
133 setting_snapshot_.reset(); | 165 setting_snapshot_.reset(); |
134 } | 166 } |
135 | 167 |
168 void ResetProfileSettingsHandler::OnDismissedResetProfileSettingsBanner( | |
169 const base::ListValue* args) { | |
170 if (automatic_profile_resetter_) | |
171 automatic_profile_resetter_->NotifyDidCloseWebUIResetBanner(); | |
172 } | |
173 | |
136 void ResetProfileSettingsHandler::OnSettingsFetched() { | 174 void ResetProfileSettingsHandler::OnSettingsFetched() { |
137 DCHECK(config_fetcher_); | 175 DCHECK(config_fetcher_); |
138 DCHECK(!config_fetcher_->IsActive()); | 176 DCHECK(!config_fetcher_->IsActive()); |
139 // The master prefs is fetched. We are waiting for user pressing 'Reset'. | 177 // The master prefs is fetched. We are waiting for user pressing 'Reset'. |
140 } | 178 } |
141 | 179 |
142 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) { | 180 void ResetProfileSettingsHandler::ResetProfile(bool send_settings) { |
143 DCHECK(resetter_); | 181 DCHECK(resetter_); |
144 DCHECK(!resetter_->IsActive()); | 182 DCHECK(!resetter_->IsActive()); |
145 | 183 |
(...skipping 28 matching lines...) Expand all Loading... | |
174 Profile::FromWebUI(web_ui()), | 212 Profile::FromWebUI(web_ui()), |
175 *setting_snapshot_); | 213 *setting_snapshot_); |
176 base::DictionaryValue feedback_info; | 214 base::DictionaryValue feedback_info; |
177 feedback_info.Set("feedbackInfo", list.release()); | 215 feedback_info.Set("feedbackInfo", list.release()); |
178 web_ui()->CallJavascriptFunction( | 216 web_ui()->CallJavascriptFunction( |
179 "ResetProfileSettingsOverlay.setFeedbackInfo", | 217 "ResetProfileSettingsOverlay.setFeedbackInfo", |
180 feedback_info); | 218 feedback_info); |
181 } | 219 } |
182 | 220 |
183 } // namespace options | 221 } // namespace options |
OLD | NEW |