Index: chrome/browser/ui/webui/options/clear_browser_data_handler.cc |
diff --git a/chrome/browser/ui/webui/options/clear_browser_data_handler.cc b/chrome/browser/ui/webui/options/clear_browser_data_handler.cc |
index eafdd4433a1e5d6fa0a59d028908c110899f9717..847d0b5d6fe147e70d664b7ee33007534a2cd19d 100644 |
--- a/chrome/browser/ui/webui/options/clear_browser_data_handler.cc |
+++ b/chrome/browser/ui/webui/options/clear_browser_data_handler.cc |
@@ -9,7 +9,6 @@ |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
-#include "base/command_line.h" |
#include "base/macros.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/metrics/sparse_histogram.h" |
@@ -21,6 +20,7 @@ |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/browsing_data/autofill_counter.h" |
#include "chrome/browser/browsing_data/browsing_data_counter.h" |
+#include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
#include "chrome/browser/browsing_data/browsing_data_helper.h" |
#include "chrome/browser/browsing_data/browsing_data_remover.h" |
#include "chrome/browser/browsing_data/cache_counter.h" |
@@ -30,7 +30,6 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/browser/ui/accelerator_utils.h" |
-#include "chrome/common/chrome_switches.h" |
#include "chrome/common/pref_names.h" |
#include "chrome/grit/generated_resources.h" |
#include "chrome/grit/locale_settings.h" |
@@ -39,7 +38,6 @@ |
#include "content/public/browser/web_ui.h" |
#include "ui/base/accelerators/accelerator.h" |
#include "ui/base/l10n/l10n_util.h" |
-#include "ui/base/text/bytes_formatting.h" |
#include "ui/events/keycodes/keyboard_codes.h" |
namespace { |
@@ -47,32 +45,6 @@ namespace { |
const char kClearBrowsingDataLearnMoreUrl[] = |
"https://support.google.com/chrome/?p=settings_clear_browsing_data"; |
-bool AreCountersEnabled() { |
- if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kEnableClearBrowsingDataCounters)) { |
- return true; |
- } |
- |
- if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kDisableClearBrowsingDataCounters)) { |
- return false; |
- } |
- |
- // Enabled by default. |
- return true; |
-} |
- |
-// A helper function to display the size of cache in units of MB or higher. |
-// We need this, as 1 MB is the lowest nonzero cache size displayed by the |
-// counter. |
-base::string16 FormatBytesMBOrHigher(BrowsingDataCounter::ResultInt bytes) { |
- if (ui::GetByteDisplayUnits(bytes) >= ui::DataUnits::DATA_UNITS_MEBIBYTE) |
- return ui::FormatBytes(bytes); |
- |
- return ui::FormatBytesWithUnits( |
- bytes, ui::DataUnits::DATA_UNITS_MEBIBYTE, true); |
-} |
- |
} // namespace |
namespace options { |
@@ -151,128 +123,6 @@ void ClearBrowserDataHandler::UpdateInfoBannerVisibility() { |
base::StringValue(text)); |
} |
-// static |
-base::string16 ClearBrowserDataHandler::GetCounterTextFromResult( |
- const BrowsingDataCounter::Result* result) { |
- base::string16 text; |
- std::string pref_name = result->source()->GetPrefName(); |
- |
- if (!result->Finished()) { |
- // The counter is still counting. |
- text = l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); |
- |
- } else if (pref_name == prefs::kDeletePasswords) { |
- // Passwords counter. |
- BrowsingDataCounter::ResultInt passwords_count = |
- static_cast<const BrowsingDataCounter::FinishedResult*>( |
- result)->Value(); |
- text = l10n_util::GetPluralStringFUTF16( |
- IDS_DEL_PASSWORDS_COUNTER, passwords_count); |
- |
- } else if (pref_name == prefs::kDeleteCache) { |
- // Cache counter. |
- BrowsingDataCounter::ResultInt cache_size_bytes = |
- static_cast<const BrowsingDataCounter::FinishedResult*>( |
- result)->Value(); |
- |
- PrefService* prefs = result->source()->GetProfile()->GetPrefs(); |
- BrowsingDataRemover::TimePeriod time_period = |
- static_cast<BrowsingDataRemover::TimePeriod>( |
- prefs->GetInteger(prefs::kDeleteTimePeriod)); |
- |
- // Three cases: Nonzero result for the entire cache, nonzero result for |
- // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). |
- static const int kBytesInAMegabyte = 1024 * 1024; |
- if (cache_size_bytes >= kBytesInAMegabyte) { |
- base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); |
- text = time_period == BrowsingDataRemover::EVERYTHING |
- ? formatted_size |
- : l10n_util::GetStringFUTF16(IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, |
- formatted_size); |
- } else { |
- text = l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); |
- } |
- |
- } else if (pref_name == prefs::kDeleteBrowsingHistory) { |
- // History counter. |
- const HistoryCounter::HistoryResult* history_result = |
- static_cast<const HistoryCounter::HistoryResult*>(result); |
- BrowsingDataCounter::ResultInt local_item_count = history_result->Value(); |
- bool has_synced_visits = history_result->has_synced_visits(); |
- |
- text = has_synced_visits |
- ? l10n_util::GetPluralStringFUTF16( |
- IDS_DEL_BROWSING_HISTORY_COUNTER_SYNCED, local_item_count) |
- : l10n_util::GetPluralStringFUTF16( |
- IDS_DEL_BROWSING_HISTORY_COUNTER, local_item_count); |
- |
- } else if (pref_name == prefs::kDeleteFormData) { |
- // Autofill counter. |
- const AutofillCounter::AutofillResult* autofill_result = |
- static_cast<const AutofillCounter::AutofillResult*>(result); |
- AutofillCounter::ResultInt num_suggestions = autofill_result->Value(); |
- AutofillCounter::ResultInt num_credit_cards = |
- autofill_result->num_credit_cards(); |
- AutofillCounter::ResultInt num_addresses = autofill_result->num_addresses(); |
- |
- std::vector<base::string16> displayed_strings; |
- |
- if (num_credit_cards) { |
- displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( |
- IDS_DEL_AUTOFILL_COUNTER_CREDIT_CARDS, num_credit_cards)); |
- } |
- if (num_addresses) { |
- displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( |
- IDS_DEL_AUTOFILL_COUNTER_ADDRESSES, num_addresses)); |
- } |
- if (num_suggestions) { |
- // We use a different wording for autocomplete suggestions based on the |
- // length of the entire string. |
- switch (displayed_strings.size()) { |
- case 0: |
- displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( |
- IDS_DEL_AUTOFILL_COUNTER_SUGGESTIONS, num_suggestions)); |
- break; |
- case 1: |
- displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( |
- IDS_DEL_AUTOFILL_COUNTER_SUGGESTIONS_LONG, num_suggestions)); |
- break; |
- case 2: |
- displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( |
- IDS_DEL_AUTOFILL_COUNTER_SUGGESTIONS_SHORT, num_suggestions)); |
- break; |
- default: |
- NOTREACHED(); |
- } |
- } |
- |
- // Construct the resulting string from the sections in |displayed_strings|. |
- switch (displayed_strings.size()) { |
- case 0: |
- text = l10n_util::GetStringUTF16(IDS_DEL_AUTOFILL_COUNTER_EMPTY); |
- break; |
- case 1: |
- text = displayed_strings[0]; |
- break; |
- case 2: |
- text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_TWO_TYPES, |
- displayed_strings[0], |
- displayed_strings[1]); |
- break; |
- case 3: |
- text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_THREE_TYPES, |
- displayed_strings[0], |
- displayed_strings[1], |
- displayed_strings[2]); |
- break; |
- default: |
- NOTREACHED(); |
- } |
- } |
- |
- return text; |
-} |
- |
void ClearBrowserDataHandler::OnPageOpened(const base::ListValue* value) { |
for (BrowsingDataCounter* counter : counters_) { |
DCHECK(AreCountersEnabled()); |