| 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/passwords_counter.h" | 31 #include "chrome/browser/browsing_data/passwords_counter.h" |
| 33 #include "chrome/browser/history/web_history_service_factory.h" | 32 #include "chrome/browser/history/web_history_service_factory.h" |
| 34 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 33 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/sync/profile_sync_service_factory.h" | 35 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 37 #include "chrome/browser/ui/accelerator_utils.h" | 36 #include "chrome/browser/ui/accelerator_utils.h" |
| 38 #include "chrome/common/channel_info.h" | 37 #include "chrome/common/channel_info.h" |
| 39 #include "chrome/common/pref_names.h" | 38 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/grit/generated_resources.h" | 39 #include "chrome/grit/generated_resources.h" |
| 41 #include "chrome/grit/locale_settings.h" | 40 #include "chrome/grit/locale_settings.h" |
| 41 #include "components/browsing_data/counters/browsing_data_counter.h" |
| 42 #include "components/browsing_data/pref_names.h" |
| 42 #include "components/browsing_data_ui/history_notice_utils.h" | 43 #include "components/browsing_data_ui/history_notice_utils.h" |
| 43 #include "components/google/core/browser/google_util.h" | 44 #include "components/google/core/browser/google_util.h" |
| 44 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| 45 #include "content/public/browser/notification_details.h" | 46 #include "content/public/browser/notification_details.h" |
| 46 #include "content/public/browser/web_ui.h" | 47 #include "content/public/browser/web_ui.h" |
| 47 #include "ui/base/accelerators/accelerator.h" | 48 #include "ui/base/accelerators/accelerator.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 49 #include "ui/base/l10n/l10n_util.h" |
| 49 #include "ui/events/keycodes/keyboard_codes.h" | 50 #include "ui/events/keycodes/keyboard_codes.h" |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, prefs); | 86 clear_plugin_lso_data_enabled_.Init(prefs::kClearPluginLSODataEnabled, prefs); |
| 86 pepper_flash_settings_enabled_.Init(prefs::kPepperFlashSettingsEnabled, | 87 pepper_flash_settings_enabled_.Init(prefs::kPepperFlashSettingsEnabled, |
| 87 prefs); | 88 prefs); |
| 88 allow_deleting_browser_history_.Init( | 89 allow_deleting_browser_history_.Init( |
| 89 prefs::kAllowDeletingBrowserHistory, | 90 prefs::kAllowDeletingBrowserHistory, |
| 90 prefs, | 91 prefs, |
| 91 base::Bind(&ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged, | 92 base::Bind(&ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged, |
| 92 base::Unretained(this))); | 93 base::Unretained(this))); |
| 93 | 94 |
| 94 if (AreCountersEnabled()) { | 95 if (AreCountersEnabled()) { |
| 95 AddCounter(base::WrapUnique(new PasswordsCounter())); | 96 Profile* profile = Profile::FromWebUI(web_ui()); |
| 96 AddCounter(base::WrapUnique(new HistoryCounter())); | 97 AddCounter(base::WrapUnique(new PasswordsCounter(profile))); |
| 97 AddCounter(base::WrapUnique(new CacheCounter())); | 98 AddCounter(base::WrapUnique(new HistoryCounter(profile))); |
| 98 AddCounter(base::WrapUnique(new AutofillCounter())); | 99 AddCounter(base::WrapUnique(new CacheCounter(profile))); |
| 100 AddCounter(base::WrapUnique(new AutofillCounter(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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 other_types, | 310 other_types, |
| 310 other_types + num_other_types, | 311 other_types + num_other_types, |
| 311 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); | 312 [prefs](const std::string& pref) { return prefs->GetBoolean(pref); }); |
| 312 UMA_HISTOGRAM_SPARSE_SLOWLY( | 313 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 313 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", | 314 "History.ClearBrowsingData.PasswordsDeletion.AdditionalDatatypesCount", |
| 314 checked_other_types); | 315 checked_other_types); |
| 315 } | 316 } |
| 316 | 317 |
| 317 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile); | 318 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile); |
| 318 remover_->AddObserver(this); | 319 remover_->AddObserver(this); |
| 319 int period_selected = prefs->GetInteger(prefs::kDeleteTimePeriod); | 320 int period_selected = |
| 320 remover_->Remove( | 321 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |
| 321 BrowsingDataRemover::Period( | 322 remover_->Remove(BrowsingDataRemover::Period( |
| 322 static_cast<BrowsingDataRemover::TimePeriod>(period_selected)), | 323 static_cast<browsing_data::TimePeriod>(period_selected)), |
| 323 remove_mask, origin_mask); | 324 remove_mask, origin_mask); |
| 324 | 325 |
| 325 // Store the clear browsing data time. Next time the clear browsing data | 326 // Store the clear browsing data time. Next time the clear browsing data |
| 326 // dialog is open, this time is used to decide whether to display an info | 327 // dialog is open, this time is used to decide whether to display an info |
| 327 // banner or not. | 328 // banner or not. |
| 328 prefs->SetInt64(prefs::kLastClearBrowsingDataTime, | 329 prefs->SetInt64(prefs::kLastClearBrowsingDataTime, |
| 329 base::Time::Now().ToInternalValue()); | 330 base::Time::Now().ToInternalValue()); |
| 330 } | 331 } |
| 331 | 332 |
| 332 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { | 333 void ClearBrowserDataHandler::OnBrowsingDataRemoverDone() { |
| 333 remover_->RemoveObserver(this); | 334 remover_->RemoveObserver(this); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 360 base::FundamentalValue(show_notice)); | 361 base::FundamentalValue(show_notice)); |
| 361 } | 362 } |
| 362 | 363 |
| 363 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { | 364 void ClearBrowserDataHandler::OnBrowsingHistoryPrefChanged() { |
| 364 web_ui()->CallJavascriptFunctionUnsafe( | 365 web_ui()->CallJavascriptFunctionUnsafe( |
| 365 "ClearBrowserDataOverlay.setAllowDeletingHistory", | 366 "ClearBrowserDataOverlay.setAllowDeletingHistory", |
| 366 base::FundamentalValue(*allow_deleting_browser_history_)); | 367 base::FundamentalValue(*allow_deleting_browser_history_)); |
| 367 } | 368 } |
| 368 | 369 |
| 369 void ClearBrowserDataHandler::AddCounter( | 370 void ClearBrowserDataHandler::AddCounter( |
| 370 std::unique_ptr<BrowsingDataCounter> counter) { | 371 std::unique_ptr<browsing_data::BrowsingDataCounter> counter) { |
| 371 DCHECK(AreCountersEnabled()); | 372 DCHECK(AreCountersEnabled()); |
| 372 | 373 |
| 373 counter->Init( | 374 counter->Init(Profile::FromWebUI(web_ui())->GetPrefs(), |
| 374 Profile::FromWebUI(web_ui()), | 375 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, |
| 375 base::Bind(&ClearBrowserDataHandler::UpdateCounterText, | 376 base::Unretained(this))); |
| 376 base::Unretained(this))); | |
| 377 counters_.push_back(std::move(counter)); | 377 counters_.push_back(std::move(counter)); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void ClearBrowserDataHandler::UpdateCounterText( | 380 void ClearBrowserDataHandler::UpdateCounterText( |
| 381 std::unique_ptr<BrowsingDataCounter::Result> result) { | 381 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
| 382 DCHECK(AreCountersEnabled()); | 382 DCHECK(AreCountersEnabled()); |
| 383 web_ui()->CallJavascriptFunctionUnsafe( | 383 web_ui()->CallJavascriptFunctionUnsafe( |
| 384 "ClearBrowserDataOverlay.updateCounter", | 384 "ClearBrowserDataOverlay.updateCounter", |
| 385 base::StringValue(result->source()->GetPrefName()), | 385 base::StringValue(result->source()->GetPrefName()), |
| 386 base::StringValue(GetCounterTextFromResult(result.get()))); | 386 base::StringValue(GetCounterTextFromResult(result.get()))); |
| 387 } | 387 } |
| 388 | 388 |
| 389 void ClearBrowserDataHandler::OnStateChanged() { | 389 void ClearBrowserDataHandler::OnStateChanged() { |
| 390 web_ui()->CallJavascriptFunctionUnsafe( | 390 web_ui()->CallJavascriptFunctionUnsafe( |
| 391 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter", | 391 "ClearBrowserDataOverlay.updateSyncWarningAndHistoryFooter", |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", | 424 "History.ClearBrowsingData.HistoryNoticeShownInFooterWhenUpdated", |
| 425 should_show_history_notice_); | 425 should_show_history_notice_); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { | 428 void ClearBrowserDataHandler::UpdateHistoryDeletionDialog(bool show) { |
| 429 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). | 429 // This is used by OnBrowsingDataRemoverDone (when the deletion finishes). |
| 430 should_show_history_deletion_dialog_ = show; | 430 should_show_history_deletion_dialog_ = show; |
| 431 } | 431 } |
| 432 | 432 |
| 433 } // namespace options | 433 } // namespace options |
| OLD | NEW |