OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/clear_browser_data_handler.h" | 5 #include "chrome/browser/ui/webui/options/clear_browser_data_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/values.h" | 21 #include "base/values.h" |
22 #include "chrome/app/chrome_command_ids.h" | 22 #include "chrome/app/chrome_command_ids.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/browsing_data/autofill_counter.h" | 24 #include "chrome/browser/browsing_data/autofill_counter.h" |
25 #include "chrome/browser/browsing_data/browsing_data_counter.h" | |
26 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" | 25 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
27 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 26 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
28 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 27 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
29 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 28 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
30 #include "chrome/browser/browsing_data/cache_counter.h" | 29 #include "chrome/browser/browsing_data/cache_counter.h" |
31 #include "chrome/browser/browsing_data/history_counter.h" | 30 #include "chrome/browser/browsing_data/history_counter.h" |
32 #include "chrome/browser/browsing_data/media_licenses_counter.h" | 31 #include "chrome/browser/browsing_data/media_licenses_counter.h" |
33 #include "chrome/browser/browsing_data/passwords_counter.h" | 32 #include "chrome/browser/browsing_data/passwords_counter.h" |
34 #include "chrome/browser/history/web_history_service_factory.h" | 33 #include "chrome/browser/history/web_history_service_factory.h" |
35 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 34 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
36 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
37 #include "chrome/browser/sync/profile_sync_service_factory.h" | 36 #include "chrome/browser/sync/profile_sync_service_factory.h" |
38 #include "chrome/browser/ui/accelerator_utils.h" | 37 #include "chrome/browser/ui/accelerator_utils.h" |
39 #include "chrome/common/channel_info.h" | 38 #include "chrome/common/channel_info.h" |
40 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
41 #include "chrome/grit/generated_resources.h" | 40 #include "chrome/grit/generated_resources.h" |
42 #include "chrome/grit/locale_settings.h" | 41 #include "chrome/grit/locale_settings.h" |
| 42 #include "components/browsing_data/counters/browsing_data_counter.h" |
| 43 #include "components/browsing_data/pref_names.h" |
43 #include "components/browsing_data_ui/history_notice_utils.h" | 44 #include "components/browsing_data_ui/history_notice_utils.h" |
44 #include "components/google/core/browser/google_util.h" | 45 #include "components/google/core/browser/google_util.h" |
45 #include "components/prefs/pref_service.h" | 46 #include "components/prefs/pref_service.h" |
46 #include "content/public/browser/notification_details.h" | 47 #include "content/public/browser/notification_details.h" |
47 #include "content/public/browser/web_ui.h" | 48 #include "content/public/browser/web_ui.h" |
48 #include "ui/base/accelerators/accelerator.h" | 49 #include "ui/base/accelerators/accelerator.h" |
49 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
50 #include "ui/events/keycodes/keyboard_codes.h" | 51 #include "ui/events/keycodes/keyboard_codes.h" |
51 | 52 |
52 namespace { | 53 namespace { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void ClearBrowserDataHandler::InitializeHandler() { | 85 void ClearBrowserDataHandler::InitializeHandler() { |
85 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); | 86 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
86 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, prefs); | 87 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, prefs); |
87 allow_deleting_browser_history_.Init( | 88 allow_deleting_browser_history_.Init( |
88 prefs::kAllowDeletingBrowserHistory, | 89 prefs::kAllowDeletingBrowserHistory, |
89 prefs, | 90 prefs, |
90 base::Bind(&ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged, | 91 base::Bind(&ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged, |
91 base::Unretained(this))); | 92 base::Unretained(this))); |
92 | 93 |
93 if (AreCountersEnabled()) { | 94 if (AreCountersEnabled()) { |
94 AddCounter(base::WrapUnique(new PasswordsCounter())); | 95 Profile* profile = Profile::FromWebUI(web_ui()); |
95 AddCounter(base::WrapUnique(new HistoryCounter())); | 96 AddCounter(base::WrapUnique(new PasswordsCounter(profile))); |
96 AddCounter(base::WrapUnique(new CacheCounter())); | 97 AddCounter(base::WrapUnique(new HistoryCounter(profile))); |
97 AddCounter(base::WrapUnique(new AutofillCounter())); | 98 AddCounter(base::WrapUnique(new CacheCounter(profile))); |
98 AddCounter(base::WrapUnique(new MediaLicensesCounter())); | 99 AddCounter(base::WrapUnique(new AutofillCounter(profile))); |
| 100 AddCounter(base::WrapUnique(new MediaLicensesCounter(profile))); |
99 | 101 |
100 sync_service_ = | 102 sync_service_ = ProfileSyncServiceFactory::GetForProfile(profile); |
101 ProfileSyncServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); | |
102 if (sync_service_) | 103 if (sync_service_) |
103 sync_service_->AddObserver(this); | 104 sync_service_->AddObserver(this); |
104 } | 105 } |
105 } | 106 } |
106 | 107 |
107 void ClearBrowserDataHandler::InitializePage() { | 108 void ClearBrowserDataHandler::InitializePage() { |
108 web_ui()->CallJavascriptFunctionUnsafe( | 109 web_ui()->CallJavascriptFunctionUnsafe( |
109 "ClearBrowserDataOverlay.createFooter", | 110 "ClearBrowserDataOverlay.createFooter", |
110 base::FundamentalValue(AreCountersEnabled()), | 111 base::FundamentalValue(AreCountersEnabled()), |
111 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), | 112 base::FundamentalValue(sync_service_ && sync_service_->IsSyncActive()), |
(...skipping 27 matching lines...) Expand all Loading... |
139 text = l10n_util::GetStringFUTF16(IDS_CLEAR_BROWSING_DATA_INFO_BAR_TEXT, | 140 text = l10n_util::GetStringFUTF16(IDS_CLEAR_BROWSING_DATA_INFO_BAR_TEXT, |
140 acc.GetShortcutText()); | 141 acc.GetShortcutText()); |
141 } | 142 } |
142 } | 143 } |
143 | 144 |
144 web_ui()->CallJavascriptFunctionUnsafe( | 145 web_ui()->CallJavascriptFunctionUnsafe( |
145 "ClearBrowserDataOverlay.setBannerText", base::StringValue(text)); | 146 "ClearBrowserDataOverlay.setBannerText", base::StringValue(text)); |
146 } | 147 } |
147 | 148 |
148 void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) { | 149 void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) { |
149 for (BrowsingDataCounter* counter : counters_) { | 150 for (browsing_data::BrowsingDataCounter* counter : counters_) { |
150 DCHECK(AreCountersEnabled()); | 151 DCHECK(AreCountersEnabled()); |
151 counter->Restart(); | 152 counter->Restart(); |
152 } | 153 } |
153 } | 154 } |
154 | 155 |
155 void ClearBrowserDataHandler::GetLocalizedValues( | 156 void ClearBrowserDataHandler::GetLocalizedValues( |
156 base::DictionaryValue* localized_strings) { | 157 base::DictionaryValue* localized_strings) { |
157 DCHECK(localized_strings); | 158 DCHECK(localized_strings); |
158 | 159 |
159 static OptionsStringResource resources[] = { | 160 static OptionsStringResource resources[] = { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 other_types, | 306 other_types, |
306 other_types + num_other_types, | 307 other_types + num_other_types, |
307 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 308 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
308 UMA_HISTOGRAM_SPARSE_SLOWLY( | 309 UMA_HISTOGRAM_SPARSE_SLOWLY( |
309 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 310 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
310 checked_other_types); | 311 checked_other_types); |
311 } | 312 } |
312 | 313 |
313 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile); | 314 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile); |
314 remover_->AddObserver(this); | 315 remover_->AddObserver(this); |
315 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); | 316 int period_selected = |
316 remover_->Remove( | 317 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
317 BrowsingDataRemover::Period( | 318 remover_->Remove(BrowsingDataRemover::Period( |
318 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)), | 319 static_cast<browsing_data::TimePeriod>(period_selected)), |
319 remove_mask, origin_mask); | 320 remove_mask, origin_mask); |
320 | 321 |
321 // Store the clear browsing data time. Next time the clear browsing data | 322 // Store the clear browsing data time. Next time the clear browsing data |
322 // dialog is open, this time is used to decide whether to display an info | 323 // dialog is open, this time is used to decide whether to display an info |
323 // banner or not. | 324 // banner or not. |
324 prefs->SetInt64(prefs::kLastClearBrowsingDataTime, | 325 prefs->SetInt64(prefs::kLastClearBrowsingDataTime, |
325 base::Time::Now().ToInternalValue()); | 326 base::Time::Now().ToInternalValue()); |
326 } | 327 } |
327 | 328 |
328 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { | 329 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { |
329 remover_->RemoveObserver(this); | 330 remover_->RemoveObserver(this); |
(...skipping 26 matching lines...) Expand all Loading... |
356 base::FundamentalValue(show_notice)); | 357 base::FundamentalValue(show_notice)); |
357 } | 358 } |
358 | 359 |
359 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { | 360 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { |
360 web_ui()->CallJavascriptFunctionUnsafe( | 361 web_ui()->CallJavascriptFunctionUnsafe( |
361 "ClearBrowserDataOverlay.setAllowDeletingHistory", | 362 "ClearBrowserDataOverlay.setAllowDeletingHistory", |
362 base::FundamentalValue(*allow_deleting_browser_history_)); | 363 base::FundamentalValue(*allow_deleting_browser_history_)); |
363 } | 364 } |
364 | 365 |
365 void ClearBrowserDataHandler::AddCounter( | 366 void ClearBrowserDataHandler::AddCounter( |
366 std::unique_ptr<BrowsingDataCounter> counter) { | 367 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { |
367 DCHECK(AreCountersEnabled()); | 368 DCHECK(AreCountersEnabled()); |
368 | 369 |
369 counter->Init( | 370 counter->Init(Profile::FromWebUI(web_ui())->GetPrefs(), |
370 Profile::FromWebUI(web_ui()), | 371 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, |
371 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, | 372 base::Unretained(this))); |
372 base::Unretained(this))); | |
373 counters_.push_back(std::move(counter)); | 373 counters_.push_back(std::move(counter)); |
374 } | 374 } |
375 | 375 |
376 void ClearBrowserDataHandler::UpdateCounterText( | 376 void ClearBrowserDataHandler::UpdateCounterText( |
377 std::unique_ptr<BrowsingDataCounter::Result> result) { | 377 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
378 DCHECK(AreCountersEnabled()); | 378 DCHECK(AreCountersEnabled()); |
379 web_ui()->CallJavascriptFunctionUnsafe( | 379 web_ui()->CallJavascriptFunctionUnsafe( |
380 "ClearBrowserDataOverlay.updateCounter", | 380 "ClearBrowserDataOverlay.updateCounter", |
381 base::StringValue(result->source()->GetPrefName()), | 381 base::StringValue(result->source()->GetPrefName()), |
382 base::StringValue(GetCounterTextFromResult(result.get()))); | 382 base::StringValue(GetCounterTextFromResult(result.get()))); |
383 } | 383 } |
384 | 384 |
385 void ClearBrowserDataHandler::OnStateChanged() { | 385 void ClearBrowserDataHandler::OnStateChanged() { |
386 web_ui()->CallJavascriptFunctionUnsafe( | 386 web_ui()->CallJavascriptFunctionUnsafe( |
387 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter", | 387 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter", |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 420 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
421 should_show_history_notice_); | 421 should_show_history_notice_); |
422 } | 422 } |
423 | 423 |
424 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { | 424 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { |
425 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). | 425 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). |
426 should_show_history_deletion_dialog_ = show; | 426 should_show_history_deletion_dialog_ = show; |
427 } | 427 } |
428 | 428 |
429 } // namespace options | 429 } // namespace options |
OLD | NEW |