Chromium Code Reviews| 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/browsing_data/browsing_data_counter_utils.h" | 5 #include "chrome/browser/browsing_data/browsing_data_counter_utils.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browsing_data/cache_counter.h" | 9 #include "chrome/browser/browsing_data/cache_counter.h" |
| 10 #include "chrome/browser/browsing_data/media_licenses_counter.h" | 10 #include "chrome/browser/browsing_data/media_licenses_counter.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/browsing_data/core/counters/autofill_counter.h" | 15 #include "components/browsing_data/core/counters/autofill_counter.h" |
|
msramek
2016/08/09 16:28:32
Some of these includes are no longer needed.
ioanap
2016/08/10 09:34:37
Done.
| |
| 16 #include "components/browsing_data/core/counters/history_counter.h" | 16 #include "components/browsing_data/core/counters/history_counter.h" |
| 17 #include "components/browsing_data/core/counters/passwords_counter.h" | 17 #include "components/browsing_data/core/counters/passwords_counter.h" |
| 18 #include "components/browsing_data/core/pref_names.h" | 18 #include "components/browsing_data/core/pref_names.h" |
| 19 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 20 #include "grit/components_strings.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/text/bytes_formatting.h" | 22 #include "ui/base/text/bytes_formatting.h" |
| 22 | 23 |
| 23 #if defined(ENABLE_EXTENSIONS) | 24 #if defined(ENABLE_EXTENSIONS) |
| 24 #include "base/numerics/safe_conversions.h" | 25 #include "base/numerics/safe_conversions.h" |
| 25 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 27 #include "chrome/browser/browsing_data/hosted_apps_counter.h" | 28 #include "chrome/browser/browsing_data/hosted_apps_counter.h" |
| 28 #endif | 29 #endif |
| 29 | 30 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 47 // counter. | 48 // counter. |
| 48 base::string16 FormatBytesMBOrHigher( | 49 base::string16 FormatBytesMBOrHigher( |
| 49 browsing_data::BrowsingDataCounter::ResultInt bytes) { | 50 browsing_data::BrowsingDataCounter::ResultInt bytes) { |
| 50 if (ui::GetByteDisplayUnits(bytes) >= ui::DataUnits::DATA_UNITS_MEBIBYTE) | 51 if (ui::GetByteDisplayUnits(bytes) >= ui::DataUnits::DATA_UNITS_MEBIBYTE) |
| 51 return ui::FormatBytes(bytes); | 52 return ui::FormatBytes(bytes); |
| 52 | 53 |
| 53 return ui::FormatBytesWithUnits( | 54 return ui::FormatBytesWithUnits( |
| 54 bytes, ui::DataUnits::DATA_UNITS_MEBIBYTE, true); | 55 bytes, ui::DataUnits::DATA_UNITS_MEBIBYTE, true); |
| 55 } | 56 } |
| 56 | 57 |
| 57 base::string16 GetCounterTextFromResult( | 58 base::string16 GetChromeCounterTextFromResult( |
| 58 const browsing_data::BrowsingDataCounter::Result* result) { | 59 const browsing_data::BrowsingDataCounter::Result* result) { |
| 59 base::string16 text; | 60 base::string16 text; |
| 60 std::string pref_name = result->source()->GetPrefName(); | 61 std::string pref_name = result->source()->GetPrefName(); |
| 61 | 62 |
| 62 if (!result->Finished()) { | 63 if (!result->Finished()) { |
| 63 // The counter is still counting. | 64 // The counter is still counting. |
| 64 text = l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); | 65 text = l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); |
| 65 | 66 |
| 66 } else if (pref_name == browsing_data::prefs::kDeletePasswords || | 67 } else if (pref_name == browsing_data::prefs::kDeletePasswords || |
| 67 pref_name == browsing_data::prefs::kDeleteDownloadHistory) { | 68 pref_name == browsing_data::prefs::kDeleteBrowsingHistory || |
|
msramek
2016/08/09 16:28:32
Download history seems to have disappeared?
ioanap
2016/08/10 09:34:37
Thank you for spotting it! I moved it now to the u
| |
| 68 // Counters with trivially formatted result: passwords and downloads. | 69 pref_name == browsing_data::prefs::kDeleteFormData) { |
| 69 browsing_data::BrowsingDataCounter::ResultInt count = | 70 text = browsing_data::GetCounterTextFromResult(result); |
|
msramek
2016/08/09 16:28:32
I would restructure this a bit, so that the last l
ioanap
2016/08/10 09:34:37
Done.
| |
| 70 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( | |
| 71 result) | |
| 72 ->Value(); | |
| 73 text = l10n_util::GetPluralStringFUTF16( | |
| 74 pref_name == browsing_data::prefs::kDeletePasswords | |
| 75 ? IDS_DEL_PASSWORDS_COUNTER | |
| 76 : IDS_DEL_DOWNLOADS_COUNTER, | |
| 77 count); | |
| 78 | |
| 79 } else if (pref_name == browsing_data::prefs::kDeleteCache) { | 71 } else if (pref_name == browsing_data::prefs::kDeleteCache) { |
| 80 // Cache counter. | 72 // Cache counter. |
| 81 browsing_data::BrowsingDataCounter::ResultInt cache_size_bytes = | 73 browsing_data::BrowsingDataCounter::ResultInt cache_size_bytes = |
| 82 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( | 74 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( |
| 83 result) | 75 result) |
| 84 ->Value(); | 76 ->Value(); |
| 85 | 77 |
| 86 PrefService* prefs = result->source()->GetPrefs(); | 78 PrefService* prefs = result->source()->GetPrefs(); |
| 87 browsing_data::TimePeriod time_period = | 79 browsing_data::TimePeriod time_period = |
| 88 static_cast<browsing_data::TimePeriod>( | 80 static_cast<browsing_data::TimePeriod>( |
| 89 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod)); | 81 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod)); |
| 90 | 82 |
| 91 // Three cases: Nonzero result for the entire cache, nonzero result for | 83 // Three cases: Nonzero result for the entire cache, nonzero result for |
| 92 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). | 84 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). |
| 93 static const int kBytesInAMegabyte = 1024 * 1024; | 85 static const int kBytesInAMegabyte = 1024 * 1024; |
| 94 if (cache_size_bytes >= kBytesInAMegabyte) { | 86 if (cache_size_bytes >= kBytesInAMegabyte) { |
| 95 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); | 87 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); |
| 96 text = time_period == browsing_data::ALL_TIME | 88 text = time_period == browsing_data::ALL_TIME |
| 97 ? formatted_size | 89 ? formatted_size |
| 98 : l10n_util::GetStringFUTF16( | 90 : l10n_util::GetStringFUTF16( |
| 99 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size); | 91 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size); |
| 100 } else { | 92 } else { |
| 101 text = l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); | 93 text = l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); |
| 102 } | 94 } |
| 103 | |
| 104 } else if (pref_name == browsing_data::prefs::kDeleteBrowsingHistory) { | |
| 105 // History counter. | |
| 106 const browsing_data::HistoryCounter::HistoryResult* history_result = | |
| 107 static_cast<const browsing_data::HistoryCounter::HistoryResult*>( | |
| 108 result); | |
| 109 browsing_data::BrowsingDataCounter::ResultInt local_item_count = | |
| 110 history_result->Value(); | |
| 111 bool has_synced_visits = history_result->has_synced_visits(); | |
| 112 | |
| 113 text = has_synced_visits | |
| 114 ? l10n_util::GetPluralStringFUTF16( | |
| 115 IDS_DEL_BROWSING_HISTORY_COUNTER_SYNCED, local_item_count) | |
| 116 : l10n_util::GetPluralStringFUTF16( | |
| 117 IDS_DEL_BROWSING_HISTORY_COUNTER, local_item_count); | |
| 118 | |
| 119 } else if (pref_name == browsing_data::prefs::kDeleteFormData) { | |
| 120 // Autofill counter. | |
| 121 const browsing_data::AutofillCounter::AutofillResult* autofill_result = | |
| 122 static_cast<const browsing_data::AutofillCounter::AutofillResult*>( | |
| 123 result); | |
| 124 browsing_data::AutofillCounter::ResultInt num_suggestions = | |
| 125 autofill_result->Value(); | |
| 126 browsing_data::AutofillCounter::ResultInt num_credit_cards = | |
| 127 autofill_result->num_credit_cards(); | |
| 128 browsing_data::AutofillCounter::ResultInt num_addresses = | |
| 129 autofill_result->num_addresses(); | |
| 130 | |
| 131 std::vector<base::string16> displayed_strings; | |
| 132 | |
| 133 if (num_credit_cards) { | |
| 134 displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( | |
| 135 IDS_DEL_AUTOFILL_COUNTER_CREDIT_CARDS, num_credit_cards)); | |
| 136 } | |
| 137 if (num_addresses) { | |
| 138 displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( | |
| 139 IDS_DEL_AUTOFILL_COUNTER_ADDRESSES, num_addresses)); | |
| 140 } | |
| 141 if (num_suggestions) { | |
| 142 // We use a different wording for autocomplete suggestions based on the | |
| 143 // length of the entire string. | |
| 144 switch (displayed_strings.size()) { | |
| 145 case 0: | |
| 146 displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( | |
| 147 IDS_DEL_AUTOFILL_COUNTER_SUGGESTIONS, num_suggestions)); | |
| 148 break; | |
| 149 case 1: | |
| 150 displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( | |
| 151 IDS_DEL_AUTOFILL_COUNTER_SUGGESTIONS_LONG, num_suggestions)); | |
| 152 break; | |
| 153 case 2: | |
| 154 displayed_strings.push_back(l10n_util::GetPluralStringFUTF16( | |
| 155 IDS_DEL_AUTOFILL_COUNTER_SUGGESTIONS_SHORT, num_suggestions)); | |
| 156 break; | |
| 157 default: | |
| 158 NOTREACHED(); | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 // Construct the resulting string from the sections in |displayed_strings|. | |
| 163 switch (displayed_strings.size()) { | |
| 164 case 0: | |
| 165 text = l10n_util::GetStringUTF16(IDS_DEL_AUTOFILL_COUNTER_EMPTY); | |
| 166 break; | |
| 167 case 1: | |
| 168 text = displayed_strings[0]; | |
| 169 break; | |
| 170 case 2: | |
| 171 text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_TWO_TYPES, | |
| 172 displayed_strings[0], | |
| 173 displayed_strings[1]); | |
| 174 break; | |
| 175 case 3: | |
| 176 text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_THREE_TYPES, | |
| 177 displayed_strings[0], | |
| 178 displayed_strings[1], | |
| 179 displayed_strings[2]); | |
| 180 break; | |
| 181 default: | |
| 182 NOTREACHED(); | |
| 183 } | |
| 184 | |
| 185 } else if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) { | 95 } else if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) { |
| 186 const MediaLicensesCounter::MediaLicenseResult* media_license_result = | 96 const MediaLicensesCounter::MediaLicenseResult* media_license_result = |
| 187 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result); | 97 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result); |
| 188 if (media_license_result->Value() > 0) { | 98 if (media_license_result->Value() > 0) { |
| 189 text = l10n_util::GetStringFUTF16( | 99 text = l10n_util::GetStringFUTF16( |
| 190 IDS_DEL_MEDIA_LICENSES_COUNTER_SITE_COMMENT, | 100 IDS_DEL_MEDIA_LICENSES_COUNTER_SITE_COMMENT, |
| 191 base::UTF8ToUTF16(media_license_result->GetOneOrigin())); | 101 base::UTF8ToUTF16(media_license_result->GetOneOrigin())); |
| 192 } else { | 102 } else { |
| 193 text = l10n_util::GetStringUTF16( | 103 text = l10n_util::GetStringUTF16( |
| 194 IDS_DEL_MEDIA_LICENSES_COUNTER_GENERAL_COMMENT); | 104 IDS_DEL_MEDIA_LICENSES_COUNTER_GENERAL_COMMENT); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 l10n_util::GetPluralStringFUTF16( | 137 l10n_util::GetPluralStringFUTF16( |
| 228 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count), | 138 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count), |
| 229 replacements, | 139 replacements, |
| 230 nullptr); | 140 nullptr); |
| 231 #endif | 141 #endif |
| 232 } | 142 } |
| 233 | 143 |
| 234 return text; | 144 return text; |
| 235 } | 145 } |
| 236 | 146 |
| 237 bool GetDeletionPreferenceFromDataType( | 147 bool GetDeletionPreferenceFromDataType( |
|
msramek
2016/08/09 16:28:32
Technically unrelated to this CL, but is there a r
ioanap
2016/08/10 09:34:37
By looking at that CL, I think this was not moved
msramek
2016/08/10 09:59:50
Acknowledged.
| |
| 238 browsing_data::BrowsingDataType data_type, | 148 browsing_data::BrowsingDataType data_type, |
| 239 std::string* out_pref) { | 149 std::string* out_pref) { |
| 240 switch (data_type) { | 150 switch (data_type) { |
| 241 case browsing_data::HISTORY: | 151 case browsing_data::HISTORY: |
| 242 *out_pref = browsing_data::prefs::kDeleteBrowsingHistory; | 152 *out_pref = browsing_data::prefs::kDeleteBrowsingHistory; |
| 243 return true; | 153 return true; |
| 244 case browsing_data::CACHE: | 154 case browsing_data::CACHE: |
| 245 *out_pref = browsing_data::prefs::kDeleteCache; | 155 *out_pref = browsing_data::prefs::kDeleteCache; |
| 246 return true; | 156 return true; |
| 247 case browsing_data::COOKIES: | 157 case browsing_data::COOKIES: |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 258 // preference. | 168 // preference. |
| 259 return false; | 169 return false; |
| 260 case browsing_data::NUM_TYPES: | 170 case browsing_data::NUM_TYPES: |
| 261 // This is not an actual type. | 171 // This is not an actual type. |
| 262 NOTREACHED(); | 172 NOTREACHED(); |
| 263 return false; | 173 return false; |
| 264 } | 174 } |
| 265 NOTREACHED(); | 175 NOTREACHED(); |
| 266 return false; | 176 return false; |
| 267 } | 177 } |
| OLD | NEW |