| 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/autofill_counter.h" | 9 #include "chrome/browser/browsing_data/autofill_counter.h" |
| 10 #include "chrome/browser/browsing_data/cache_counter.h" | 10 #include "chrome/browser/browsing_data/cache_counter.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 base::string16 GetCounterTextFromResult( | 57 base::string16 GetCounterTextFromResult( |
| 58 const browsing_data::BrowsingDataCounter::Result* result) { | 58 const browsing_data::BrowsingDataCounter::Result* result) { |
| 59 base::string16 text; | 59 base::string16 text; |
| 60 std::string pref_name = result->source()->GetPrefName(); | 60 std::string pref_name = result->source()->GetPrefName(); |
| 61 | 61 |
| 62 if (!result->Finished()) { | 62 if (!result->Finished()) { |
| 63 // The counter is still counting. | 63 // The counter is still counting. |
| 64 text = l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); | 64 text = l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); |
| 65 | 65 |
| 66 } else if (pref_name == prefs::kDeletePasswords || | 66 } else if (pref_name == browsing_data::prefs::kDeletePasswords || |
| 67 pref_name == prefs::kDeleteDownloadHistory) { | 67 pref_name == browsing_data::prefs::kDeleteDownloadHistory) { |
| 68 // Counters with trivially formatted result: passwords and downloads. | 68 // Counters with trivially formatted result: passwords and downloads. |
| 69 browsing_data::BrowsingDataCounter::ResultInt count = | 69 browsing_data::BrowsingDataCounter::ResultInt count = |
| 70 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( | 70 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( |
| 71 result) | 71 result) |
| 72 ->Value(); | 72 ->Value(); |
| 73 text = l10n_util::GetPluralStringFUTF16( | 73 text = l10n_util::GetPluralStringFUTF16( |
| 74 pref_name == prefs::kDeletePasswords | 74 pref_name == browsing_data::prefs::kDeletePasswords |
| 75 ? IDS_DEL_PASSWORDS_COUNTER | 75 ? IDS_DEL_PASSWORDS_COUNTER |
| 76 : IDS_DEL_DOWNLOADS_COUNTER, | 76 : IDS_DEL_DOWNLOADS_COUNTER, |
| 77 count); | 77 count); |
| 78 | 78 |
| 79 } else if (pref_name == prefs::kDeleteCache) { | 79 } else if (pref_name == browsing_data::prefs::kDeleteCache) { |
| 80 // Cache counter. | 80 // Cache counter. |
| 81 browsing_data::BrowsingDataCounter::ResultInt cache_size_bytes = | 81 browsing_data::BrowsingDataCounter::ResultInt cache_size_bytes = |
| 82 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( | 82 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( |
| 83 result) | 83 result) |
| 84 ->Value(); | 84 ->Value(); |
| 85 | 85 |
| 86 PrefService* prefs = result->source()->GetPrefs(); | 86 PrefService* prefs = result->source()->GetPrefs(); |
| 87 browsing_data::TimePeriod time_period = | 87 browsing_data::TimePeriod time_period = |
| 88 static_cast<browsing_data::TimePeriod>( | 88 static_cast<browsing_data::TimePeriod>( |
| 89 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod)); | 89 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod)); |
| 90 | 90 |
| 91 // Three cases: Nonzero result for the entire cache, nonzero result for | 91 // 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). | 92 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). |
| 93 static const int kBytesInAMegabyte = 1024 * 1024; | 93 static const int kBytesInAMegabyte = 1024 * 1024; |
| 94 if (cache_size_bytes >= kBytesInAMegabyte) { | 94 if (cache_size_bytes >= kBytesInAMegabyte) { |
| 95 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); | 95 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); |
| 96 text = time_period == browsing_data::EVERYTHING | 96 text = time_period == browsing_data::EVERYTHING |
| 97 ? formatted_size | 97 ? formatted_size |
| 98 : l10n_util::GetStringFUTF16( | 98 : l10n_util::GetStringFUTF16( |
| 99 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size); | 99 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size); |
| 100 } else { | 100 } else { |
| 101 text = l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); | 101 text = l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } else if (pref_name == prefs::kDeleteBrowsingHistory) { | 104 } else if (pref_name == browsing_data::prefs::kDeleteBrowsingHistory) { |
| 105 // History counter. | 105 // History counter. |
| 106 const HistoryCounter::HistoryResult* history_result = | 106 const HistoryCounter::HistoryResult* history_result = |
| 107 static_cast<const HistoryCounter::HistoryResult*>(result); | 107 static_cast<const HistoryCounter::HistoryResult*>(result); |
| 108 browsing_data::BrowsingDataCounter::ResultInt local_item_count = | 108 browsing_data::BrowsingDataCounter::ResultInt local_item_count = |
| 109 history_result->Value(); | 109 history_result->Value(); |
| 110 bool has_synced_visits = history_result->has_synced_visits(); | 110 bool has_synced_visits = history_result->has_synced_visits(); |
| 111 | 111 |
| 112 text = has_synced_visits | 112 text = has_synced_visits |
| 113 ? l10n_util::GetPluralStringFUTF16( | 113 ? l10n_util::GetPluralStringFUTF16( |
| 114 IDS_DEL_BROWSING_HISTORY_COUNTER_SYNCED, local_item_count) | 114 IDS_DEL_BROWSING_HISTORY_COUNTER_SYNCED, local_item_count) |
| 115 : l10n_util::GetPluralStringFUTF16( | 115 : l10n_util::GetPluralStringFUTF16( |
| 116 IDS_DEL_BROWSING_HISTORY_COUNTER, local_item_count); | 116 IDS_DEL_BROWSING_HISTORY_COUNTER, local_item_count); |
| 117 | 117 |
| 118 } else if (pref_name == prefs::kDeleteFormData) { | 118 } else if (pref_name == browsing_data::prefs::kDeleteFormData) { |
| 119 // Autofill counter. | 119 // Autofill counter. |
| 120 const AutofillCounter::AutofillResult* autofill_result = | 120 const AutofillCounter::AutofillResult* autofill_result = |
| 121 static_cast<const AutofillCounter::AutofillResult*>(result); | 121 static_cast<const AutofillCounter::AutofillResult*>(result); |
| 122 AutofillCounter::ResultInt num_suggestions = autofill_result->Value(); | 122 AutofillCounter::ResultInt num_suggestions = autofill_result->Value(); |
| 123 AutofillCounter::ResultInt num_credit_cards = | 123 AutofillCounter::ResultInt num_credit_cards = |
| 124 autofill_result->num_credit_cards(); | 124 autofill_result->num_credit_cards(); |
| 125 AutofillCounter::ResultInt num_addresses = autofill_result->num_addresses(); | 125 AutofillCounter::ResultInt num_addresses = autofill_result->num_addresses(); |
| 126 | 126 |
| 127 std::vector<base::string16> displayed_strings; | 127 std::vector<base::string16> displayed_strings; |
| 128 | 128 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 case 3: | 171 case 3: |
| 172 text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_THREE_TYPES, | 172 text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_THREE_TYPES, |
| 173 displayed_strings[0], | 173 displayed_strings[0], |
| 174 displayed_strings[1], | 174 displayed_strings[1], |
| 175 displayed_strings[2]); | 175 displayed_strings[2]); |
| 176 break; | 176 break; |
| 177 default: | 177 default: |
| 178 NOTREACHED(); | 178 NOTREACHED(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 } else if (pref_name == prefs::kDeleteMediaLicenses) { | 181 } else if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) { |
| 182 const MediaLicensesCounter::MediaLicenseResult* media_license_result = | 182 const MediaLicensesCounter::MediaLicenseResult* media_license_result = |
| 183 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result); | 183 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result); |
| 184 if (media_license_result->Value() > 0) { | 184 if (media_license_result->Value() > 0) { |
| 185 text = l10n_util::GetStringFUTF16( | 185 text = l10n_util::GetStringFUTF16( |
| 186 IDS_DEL_MEDIA_LICENSES_COUNTER_SITE_COMMENT, | 186 IDS_DEL_MEDIA_LICENSES_COUNTER_SITE_COMMENT, |
| 187 base::UTF8ToUTF16(media_license_result->GetOneOrigin())); | 187 base::UTF8ToUTF16(media_license_result->GetOneOrigin())); |
| 188 } else { | 188 } else { |
| 189 text = l10n_util::GetStringUTF16( | 189 text = l10n_util::GetStringUTF16( |
| 190 IDS_DEL_MEDIA_LICENSES_COUNTER_GENERAL_COMMENT); | 190 IDS_DEL_MEDIA_LICENSES_COUNTER_GENERAL_COMMENT); |
| 191 } | 191 } |
| 192 | 192 |
| 193 #if defined(ENABLE_EXTENSIONS) | 193 #if defined(ENABLE_EXTENSIONS) |
| 194 } else if (pref_name == prefs::kDeleteHostedAppsData) { | 194 } else if (pref_name == browsing_data::prefs::kDeleteHostedAppsData) { |
| 195 // Hosted apps counter. | 195 // Hosted apps counter. |
| 196 const HostedAppsCounter::HostedAppsResult* hosted_apps_result = | 196 const HostedAppsCounter::HostedAppsResult* hosted_apps_result = |
| 197 static_cast<const HostedAppsCounter::HostedAppsResult*>(result); | 197 static_cast<const HostedAppsCounter::HostedAppsResult*>(result); |
| 198 int hosted_apps_count = hosted_apps_result->Value(); | 198 int hosted_apps_count = hosted_apps_result->Value(); |
| 199 | 199 |
| 200 DCHECK_GE(hosted_apps_result->Value(), | 200 DCHECK_GE(hosted_apps_result->Value(), |
| 201 base::checked_cast<browsing_data::BrowsingDataCounter::ResultInt>( | 201 base::checked_cast<browsing_data::BrowsingDataCounter::ResultInt>( |
| 202 hosted_apps_result->examples().size())); | 202 hosted_apps_result->examples().size())); |
| 203 | 203 |
| 204 std::vector<base::string16> replacements; | 204 std::vector<base::string16> replacements; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 228 } | 228 } |
| 229 | 229 |
| 230 return text; | 230 return text; |
| 231 } | 231 } |
| 232 | 232 |
| 233 bool GetDeletionPreferenceFromDataType( | 233 bool GetDeletionPreferenceFromDataType( |
| 234 browsing_data::BrowsingDataType data_type, | 234 browsing_data::BrowsingDataType data_type, |
| 235 std::string* out_pref) { | 235 std::string* out_pref) { |
| 236 switch (data_type) { | 236 switch (data_type) { |
| 237 case browsing_data::HISTORY: | 237 case browsing_data::HISTORY: |
| 238 *out_pref = prefs::kDeleteBrowsingHistory; | 238 *out_pref = browsing_data::prefs::kDeleteBrowsingHistory; |
| 239 return true; | 239 return true; |
| 240 case browsing_data::CACHE: | 240 case browsing_data::CACHE: |
| 241 *out_pref = prefs::kDeleteCache; | 241 *out_pref = browsing_data::prefs::kDeleteCache; |
| 242 return true; | 242 return true; |
| 243 case browsing_data::COOKIES: | 243 case browsing_data::COOKIES: |
| 244 *out_pref = prefs::kDeleteCookies; | 244 *out_pref = browsing_data::prefs::kDeleteCookies; |
| 245 return true; | 245 return true; |
| 246 case browsing_data::PASSWORDS: | 246 case browsing_data::PASSWORDS: |
| 247 *out_pref = prefs::kDeletePasswords; | 247 *out_pref = browsing_data::prefs::kDeletePasswords; |
| 248 return true; | 248 return true; |
| 249 case browsing_data::FORM_DATA: | 249 case browsing_data::FORM_DATA: |
| 250 *out_pref = prefs::kDeleteFormData; | 250 *out_pref = browsing_data::prefs::kDeleteFormData; |
| 251 return true; | 251 return true; |
| 252 case browsing_data::BOOKMARKS: | 252 case browsing_data::BOOKMARKS: |
| 253 // Bookmarks are deleted on the Android side. No corresponding deletion | 253 // Bookmarks are deleted on the Android side. No corresponding deletion |
| 254 // preference. | 254 // preference. |
| 255 return false; | 255 return false; |
| 256 case browsing_data::NUM_TYPES: | 256 case browsing_data::NUM_TYPES: |
| 257 // This is not an actual type. | 257 // This is not an actual type. |
| 258 NOTREACHED(); | 258 NOTREACHED(); |
| 259 return false; | 259 return false; |
| 260 } | 260 } |
| 261 NOTREACHED(); | 261 NOTREACHED(); |
| 262 return false; | 262 return false; |
| 263 } | 263 } |
| OLD | NEW |