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/browsing_data_counter_factory.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" | |
18 #include "chrome/browser/browsing_data/downloads_counter.h" | |
19 #include "chrome/browser/browsing_data/history_counter.h" | |
20 #include "chrome/browser/browsing_data/hosted_apps_counter.h" | |
21 #include "chrome/browser/browsing_data/media_licenses_counter.h" | |
22 #include "chrome/browser/browsing_data/passwords_counter.h" | |
23 #include "chrome/browser/history/web_history_service_factory.h" | 17 #include "chrome/browser/history/web_history_service_factory.h" |
24 #include "chrome/browser/sync/profile_sync_service_factory.h" | 18 #include "chrome/browser/sync/profile_sync_service_factory.h" |
25 #include "chrome/common/channel_info.h" | 19 #include "chrome/common/channel_info.h" |
26 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
27 #include "components/browsing_data/pref_names.h" | 21 #include "components/browsing_data/pref_names.h" |
28 #include "components/browsing_data_ui/history_notice_utils.h" | 22 #include "components/browsing_data_ui/history_notice_utils.h" |
29 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
30 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
31 | 25 |
32 namespace { | 26 namespace { |
33 | 27 |
34 const int kMaxTimesHistoryNoticeShown = 1; | 28 const int kMaxTimesHistoryNoticeShown = 1; |
35 | 29 |
36 } | 30 // TODO(msramek): Get the list of deletion preferences from the JS side. |
| 31 const char* kCounterPrefs[] = { |
| 32 prefs::kDeleteBrowsingHistory, |
| 33 prefs::kDeleteCache, |
| 34 prefs::kDeleteDownloadHistory, |
| 35 prefs::kDeleteFormData, |
| 36 prefs::kDeleteHostedAppsData, |
| 37 prefs::kDeleteMediaLicenses, |
| 38 prefs::kDeletePasswords, |
| 39 }; |
| 40 |
| 41 } // namespace |
37 | 42 |
38 namespace settings { | 43 namespace settings { |
39 | 44 |
40 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) | 45 ClearBrowsingDataHandler::ClearBrowsingDataHandler(content::WebUI* webui) |
41 : profile_(Profile::FromWebUI(webui)), | 46 : profile_(Profile::FromWebUI(webui)), |
42 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), | 47 sync_service_(ProfileSyncServiceFactory::GetForProfile(profile_)), |
43 sync_service_observer_(this), | 48 sync_service_observer_(this), |
44 remover_(nullptr), | 49 remover_(nullptr), |
45 show_history_footer_(false), | 50 show_history_footer_(false), |
46 show_history_deletion_dialog_(false), | 51 show_history_deletion_dialog_(false), |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 "cr.webUIListenerCallback", | 213 "cr.webUIListenerCallback", |
209 base::StringValue("browsing-history-pref-changed"), | 214 base::StringValue("browsing-history-pref-changed"), |
210 base::FundamentalValue( | 215 base::FundamentalValue( |
211 profile_->GetPrefs()->GetBoolean( | 216 profile_->GetPrefs()->GetBoolean( |
212 prefs::kAllowDeletingBrowserHistory))); | 217 prefs::kAllowDeletingBrowserHistory))); |
213 } | 218 } |
214 | 219 |
215 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { | 220 void ClearBrowsingDataHandler::HandleInitialize(const base::ListValue* args) { |
216 AllowJavascript(); | 221 AllowJavascript(); |
217 | 222 |
218 // TODO(msramek): Simplify this using a factory. | 223 for (const std::string& pref : kCounterPrefs) { |
219 AddCounter(base::WrapUnique(new AutofillCounter(profile_))); | 224 AddCounter( |
220 AddCounter(base::WrapUnique(new CacheCounter(profile_))); | 225 BrowsingDataCounterFactory::GetForProfileAndPref(profile_, pref)); |
221 AddCounter(base::WrapUnique(new DownloadsCounter(profile_))); | 226 } |
222 AddCounter(base::WrapUnique(new HistoryCounter(profile_))); | |
223 AddCounter(base::WrapUnique(new HostedAppsCounter(profile_))); | |
224 AddCounter(base::WrapUnique(new PasswordsCounter(profile_))); | |
225 AddCounter(base::WrapUnique(new MediaLicensesCounter(profile_))); | |
226 | 227 |
227 OnStateChanged(); | 228 OnStateChanged(); |
228 RefreshHistoryNotice(); | 229 RefreshHistoryNotice(); |
229 } | 230 } |
230 | 231 |
231 void ClearBrowsingDataHandler::OnStateChanged() { | 232 void ClearBrowsingDataHandler::OnStateChanged() { |
232 CallJavascriptFunction( | 233 CallJavascriptFunction( |
233 "cr.webUIListenerCallback", | 234 "cr.webUIListenerCallback", |
234 base::StringValue("update-footer"), | 235 base::StringValue("update-footer"), |
235 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 236 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 void ClearBrowsingDataHandler::UpdateCounterText( | 286 void ClearBrowsingDataHandler::UpdateCounterText( |
286 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 287 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
287 CallJavascriptFunction( | 288 CallJavascriptFunction( |
288 "cr.webUIListenerCallback", | 289 "cr.webUIListenerCallback", |
289 base::StringValue("update-counter-text"), | 290 base::StringValue("update-counter-text"), |
290 base::StringValue(result->source()->GetPrefName()), | 291 base::StringValue(result->source()->GetPrefName()), |
291 base::StringValue(GetCounterTextFromResult(result.get()))); | 292 base::StringValue(GetCounterTextFromResult(result.get()))); |
292 } | 293 } |
293 | 294 |
294 } // namespace settings | 295 } // namespace settings |
OLD | NEW |