OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/settings/settings_clear_browsing_data_handler. h" | 5 #include "chrome/browser/ui/webui/settings/settings_clear_browsing_data_handler. h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
13 #include "chrome/browser/browsing_data/autofill_counter.h" | 13 #include "chrome/browser/browsing_data/autofill_counter.h" |
14 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | 14 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
15 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 15 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
17 #include "chrome/browser/browsing_data/cache_counter.h" | 17 #include "chrome/browser/browsing_data/cache_counter.h" |
18 #include "chrome/browser/browsing_data/downloads_counter.h" | 18 #include "chrome/browser/browsing_data/downloads_counter.h" |
19 #include "chrome/browser/browsing_data/history_counter.h" | 19 #include "chrome/browser/browsing_data/history_counter.h" |
20 #include "chrome/browser/browsing_data/hosted_apps_counter.h" | 20 #include "chrome/browser/browsing_data/hosted_apps_counter.h" |
21 #include "chrome/browser/browsing_data/passwords_counter.h" | 21 #include "chrome/browser/browsing_data/passwords_counter.h" |
22 #include "chrome/browser/history/web_history_service_factory.h" | 22 #include "chrome/browser/history/web_history_service_factory.h" |
23 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
24 #include "chrome/common/channel_info.h" | |
24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
25 #include "components/browsing_data_ui/history_notice_utils.h" | 26 #include "components/browsing_data_ui/history_notice_utils.h" |
26 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
27 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
28 | 29 |
30 namespace { | |
31 | |
32 const int kMaxTimesHistoryNoticeShown = 1; | |
33 | |
34 } | |
35 | |
29 namespace settings { | 36 namespace settings { |
30 | 37 |
31 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) | 38 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) |
32 : profile_(Profile::FromWebUI(webui)), | 39 : profile_(Profile::FromWebUI(webui)), |
33 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), | 40 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), |
34 sync_service_observer_(this), | 41 sync_service_observer_(this), |
35 remover_(nullptr), | 42 remover_(nullptr), |
36 should_show_history_footer_(false), | 43 should_show_history_footer_(false), |
37 weak_ptr_factory_(this) {} | 44 weak_ptr_factory_(this) {} |
38 | 45 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 remover_->AddObserver(this); | 166 remover_->AddObserver(this); |
160 remover_->Remove( | 167 remover_->Remove( |
161 BrowsingDataRemover::Period( | 168 BrowsingDataRemover::Period( |
162 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)), | 169 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)), |
163 remove_mask, origin_mask); | 170 remove_mask, origin_mask); |
164 } | 171 } |
165 | 172 |
166 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { | 173 void ClearBrowsingDataHandler::OnBrowsingDataRemoverDone() { |
167 remover_->RemoveObserver(this); | 174 remover_->RemoveObserver(this); |
168 remover_ = nullptr; | 175 remover_ = nullptr; |
176 | |
177 PrefService* prefs = profile_->GetPrefs(); | |
178 int notice_shown_times = | |
179 prefs->GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); | |
180 | |
181 // When the deletion is complete, we might show an additional dialog with | |
182 // a notice about other forms of browsing history. This is the case if | |
183 const bool show_notice = | |
184 // 1. The dialog is relevant for the user. | |
185 should_show_history_deletion_dialog_ && | |
186 // 2. The selected data types contained browsing history. | |
187 prefs->GetBoolean(prefs::kDeleteBrowsingHistory) && | |
188 // 3. The notice has been shown less than |kMaxTimesHistoryNoticeShown|. | |
189 notice_shown_times < kMaxTimesHistoryNoticeShown; | |
dschuyler
2016/06/25 01:34:54
nit: not a big deal, but if #2 and #3 were swapped
msramek
2016/06/27 15:24:59
Done.
| |
190 | |
191 if (show_notice) { | |
192 // Increment the preference. | |
193 prefs->SetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes, | |
194 notice_shown_times + 1); | |
dschuyler
2016/06/25 01:34:54
trivia: it looks like there is a potential race
co
msramek
2016/06/27 15:24:59
Acknowledged. Thanks for pointing it out.
| |
195 } | |
196 | |
197 UMA_HISTOGRAM_BOOLEAN( | |
198 "History.ClearBrowsingData.ShownHistoryNoticeAfterClearing", show_notice); | |
199 | |
169 ResolveJavascriptCallback( | 200 ResolveJavascriptCallback( |
170 base::StringValue(webui_callback_id_), | 201 base::StringValue(webui_callback_id_), |
171 *base::Value::CreateNullValue()); | 202 base::FundamentalValue(show_notice)); |
172 webui_callback_id_.clear(); | 203 webui_callback_id_.clear(); |
173 } | 204 } |
174 | 205 |
175 void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() { | 206 void ClearBrowsingDataHandler::OnBrowsingHistoryPrefChanged() { |
176 CallJavascriptFunction( | 207 CallJavascriptFunction( |
177 "cr.webUIListenerCallback", | 208 "cr.webUIListenerCallback", |
178 base::StringValue("browsing-history-pref-changed"), | 209 base::StringValue("browsing-history-pref-changed"), |
179 base::FundamentalValue( | 210 base::FundamentalValue( |
180 profile_->GetPrefs()->GetBoolean( | 211 profile_->GetPrefs()->GetBoolean( |
181 prefs::kAllowDeletingBrowserHistory))); | 212 prefs::kAllowDeletingBrowserHistory))); |
(...skipping 21 matching lines...) Expand all Loading... | |
203 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 234 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
204 base::FundamentalValue(should_show_history_footer_)); | 235 base::FundamentalValue(should_show_history_footer_)); |
205 } | 236 } |
206 | 237 |
207 void ClearBrowsingDataHandler::RefreshHistoryNotice() { | 238 void ClearBrowsingDataHandler::RefreshHistoryNotice() { |
208 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( | 239 browsing_data_ui::ShouldShowNoticeAboutOtherFormsOfBrowsingHistory( |
209 sync_service_, | 240 sync_service_, |
210 WebHistoryServiceFactory::GetForProfile(profile_), | 241 WebHistoryServiceFactory::GetForProfile(profile_), |
211 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryNotice, | 242 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryNotice, |
212 weak_ptr_factory_.GetWeakPtr())); | 243 weak_ptr_factory_.GetWeakPtr())); |
244 | |
245 // If the dialog with history notice has been shown less than | |
246 // |kMaxTimesHistoryNoticeShown| times, we might have to show it when the | |
247 // user deletes history. Find out if the conditions are met. | |
248 int notice_shown_times = profile_->GetPrefs()-> | |
249 GetInteger(prefs::kClearBrowsingDataHistoryNoticeShownTimes); | |
250 | |
251 if (notice_shown_times < kMaxTimesHistoryNoticeShown) { | |
252 browsing_data_ui::ShouldPopupDialogAboutOtherFormsOfBrowsingHistory( | |
253 sync_service_, | |
254 WebHistoryServiceFactory::GetForProfile(profile_), | |
255 chrome::GetChannel(), | |
256 base::Bind(&ClearBrowsingDataHandler::UpdateHistoryDeletionDialog, | |
257 weak_ptr_factory_.GetWeakPtr())); | |
258 } | |
213 } | 259 } |
214 | 260 |
215 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { | 261 void ClearBrowsingDataHandler::UpdateHistoryNotice(bool show) { |
216 should_show_history_footer_ = show; | 262 should_show_history_footer_ = show; |
217 OnStateChanged(); | 263 OnStateChanged(); |
218 | 264 |
219 UMA_HISTOGRAM_BOOLEAN( | 265 UMA_HISTOGRAM_BOOLEAN( |
220 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 266 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
221 should_show_history_footer_); | 267 should_show_history_footer_); |
222 } | 268 } |
223 | 269 |
270 void ClearBrowsingDataHandler::UpdateHistoryDeletionDialog(bool show) { | |
271 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). | |
272 should_show_history_deletion_dialog_ = show; | |
273 } | |
274 | |
224 void ClearBrowsingDataHandler::AddCounter( | 275 void ClearBrowsingDataHandler::AddCounter( |
225 std::unique_ptr<BrowsingDataCounter> counter) { | 276 std::unique_ptr<BrowsingDataCounter> counter) { |
226 counter->Init( | 277 counter->Init( |
227 profile_, | 278 profile_, |
228 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, | 279 base::Bind(&ClearBrowsingDataHandler::UpdateCounterText, |
229 base::Unretained(this))); | 280 base::Unretained(this))); |
230 counter->Restart(); | 281 counter->Restart(); |
231 counters_.push_back(std::move(counter)); | 282 counters_.push_back(std::move(counter)); |
232 } | 283 } |
233 | 284 |
234 void ClearBrowsingDataHandler::UpdateCounterText( | 285 void ClearBrowsingDataHandler::UpdateCounterText( |
235 std::unique_ptr<BrowsingDataCounter::Result> result) { | 286 std::unique_ptr<BrowsingDataCounter::Result> result) { |
236 CallJavascriptFunction( | 287 CallJavascriptFunction( |
237 "cr.webUIListenerCallback", | 288 "cr.webUIListenerCallback", |
238 base::StringValue("update-counter-text"), | 289 base::StringValue("update-counter-text"), |
239 base::StringValue(result->source()->GetPrefName()), | 290 base::StringValue(result->source()->GetPrefName()), |
240 base::StringValue(GetCounterTextFromResult(result.get()))); | 291 base::StringValue(GetCounterTextFromResult(result.get()))); |
241 } | 292 } |
242 | 293 |
243 } // namespace settings | 294 } // namespace settings |
OLD | NEW |