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/feature_list.h" | 8 #include "base/feature_list.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/browsing_data/cache_counter.h" | 10 #include "chrome/browser/browsing_data/cache_counter.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 base::string16 FormatBytesMBOrHigher( | 61 base::string16 FormatBytesMBOrHigher( |
62 browsing_data::BrowsingDataCounter::ResultInt bytes) { | 62 browsing_data::BrowsingDataCounter::ResultInt bytes) { |
63 if (ui::GetByteDisplayUnits(bytes) >= ui::DataUnits::DATA_UNITS_MEBIBYTE) | 63 if (ui::GetByteDisplayUnits(bytes) >= ui::DataUnits::DATA_UNITS_MEBIBYTE) |
64 return ui::FormatBytes(bytes); | 64 return ui::FormatBytes(bytes); |
65 | 65 |
66 return ui::FormatBytesWithUnits( | 66 return ui::FormatBytesWithUnits( |
67 bytes, ui::DataUnits::DATA_UNITS_MEBIBYTE, true); | 67 bytes, ui::DataUnits::DATA_UNITS_MEBIBYTE, true); |
68 } | 68 } |
69 | 69 |
70 base::string16 GetChromeCounterTextFromResult( | 70 base::string16 GetChromeCounterTextFromResult( |
71 const browsing_data::BrowsingDataCounter::Result* result) { | 71 const browsing_data::BrowsingDataCounter::Result* result, |
| 72 browsing_data::ClearBrowsingDataTab cbd_tab) { |
72 std::string pref_name = result->source()->GetPrefName(); | 73 std::string pref_name = result->source()->GetPrefName(); |
73 | 74 |
74 if (!result->Finished()) { | 75 if (!result->Finished()) { |
75 // The counter is still counting. | 76 // The counter is still counting. |
76 return l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); | 77 return l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); |
77 } | 78 } |
78 | 79 |
79 if (pref_name == browsing_data::prefs::kDeleteCache || | 80 if (pref_name == browsing_data::prefs::kDeleteCache || |
80 pref_name == browsing_data::prefs::kDeleteCacheBasic) { | 81 pref_name == browsing_data::prefs::kDeleteCacheBasic) { |
81 // Cache counter. | 82 // Cache counter. |
82 const auto* cache_result = | 83 const auto* cache_result = |
83 static_cast<const CacheCounter::CacheResult*>(result); | 84 static_cast<const CacheCounter::CacheResult*>(result); |
84 int64_t cache_size_bytes = cache_result->cache_size(); | 85 int64_t cache_size_bytes = cache_result->cache_size(); |
85 bool is_upper_limit = cache_result->is_upper_limit(); | 86 bool is_upper_limit = cache_result->is_upper_limit(); |
86 | 87 |
87 // Three cases: Nonzero result for the entire cache, nonzero result for | 88 // Three cases: Nonzero result for the entire cache, nonzero result for |
88 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). | 89 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). |
89 static const int kBytesInAMegabyte = 1024 * 1024; | 90 static const int kBytesInAMegabyte = 1024 * 1024; |
| 91 base::string16 size_string; |
90 if (cache_size_bytes >= kBytesInAMegabyte) { | 92 if (cache_size_bytes >= kBytesInAMegabyte) { |
91 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); | 93 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); |
92 return !is_upper_limit | 94 size_string = !is_upper_limit ? formatted_size |
93 ? formatted_size | 95 : l10n_util::GetStringFUTF16( |
94 : l10n_util::GetStringFUTF16( | 96 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, |
95 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size); | 97 formatted_size); |
| 98 } else { |
| 99 size_string = |
| 100 l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); |
96 } | 101 } |
97 return l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); | 102 switch (cbd_tab) { |
| 103 case browsing_data::ClearBrowsingDataTab::ADVANCED: |
| 104 return size_string; |
| 105 case browsing_data::ClearBrowsingDataTab::BASIC: |
| 106 return l10n_util::GetStringFUTF16(IDS_DEL_CACHE_COUNTER_BASIC, |
| 107 size_string); |
| 108 case browsing_data::ClearBrowsingDataTab::NUM_TYPES: |
| 109 NOTREACHED(); |
| 110 } |
98 } | 111 } |
99 | 112 |
100 if (pref_name == browsing_data::prefs::kDeleteCookies) { | 113 if (pref_name == browsing_data::prefs::kDeleteCookies || |
| 114 pref_name == browsing_data::prefs::kDeleteCookiesBasic) { |
101 // Site data counter. | 115 // Site data counter. |
102 DCHECK(IsSiteDataCounterEnabled()); | 116 DCHECK(IsSiteDataCounterEnabled()); |
103 browsing_data::BrowsingDataCounter::ResultInt origins = | 117 browsing_data::BrowsingDataCounter::ResultInt origins = |
104 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( | 118 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( |
105 result) | 119 result) |
106 ->Value(); | 120 ->Value(); |
107 return l10n_util::GetPluralStringFUTF16(IDS_DEL_COOKIES_COUNTER_ADVANCED, | 121 switch (cbd_tab) { |
108 origins); | 122 case browsing_data::ClearBrowsingDataTab::ADVANCED: |
| 123 return l10n_util::GetPluralStringFUTF16( |
| 124 IDS_DEL_COOKIES_COUNTER_ADVANCED, origins); |
| 125 // The basic tab doesn't show cookie counter results. |
| 126 case browsing_data::ClearBrowsingDataTab::BASIC: |
| 127 case browsing_data::ClearBrowsingDataTab::NUM_TYPES: |
| 128 NOTREACHED(); |
| 129 } |
109 } | 130 } |
110 | 131 |
111 if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) { | 132 if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) { |
112 const MediaLicensesCounter::MediaLicenseResult* media_license_result = | 133 const MediaLicensesCounter::MediaLicenseResult* media_license_result = |
113 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result); | 134 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result); |
114 if (media_license_result->Value() > 0) { | 135 if (media_license_result->Value() > 0) { |
115 return l10n_util::GetStringFUTF16( | 136 return l10n_util::GetStringFUTF16( |
116 IDS_DEL_MEDIA_LICENSES_COUNTER_SITE_COMMENT, | 137 IDS_DEL_MEDIA_LICENSES_COUNTER_SITE_COMMENT, |
117 base::UTF8ToUTF16(media_license_result->GetOneOrigin())); | 138 base::UTF8ToUTF16(media_license_result->GetOneOrigin())); |
118 } | 139 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // placeholders ($1, $2, $3). First fetch the correct plural string first, | 171 // placeholders ($1, $2, $3). First fetch the correct plural string first, |
151 // then substitute the $ placeholders. | 172 // then substitute the $ placeholders. |
152 return base::ReplaceStringPlaceholders( | 173 return base::ReplaceStringPlaceholders( |
153 l10n_util::GetPluralStringFUTF16( | 174 l10n_util::GetPluralStringFUTF16( |
154 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count), | 175 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count), |
155 replacements, | 176 replacements, |
156 nullptr); | 177 nullptr); |
157 } | 178 } |
158 #endif | 179 #endif |
159 | 180 |
160 return browsing_data::GetCounterTextFromResult(result); | 181 return browsing_data::GetCounterTextFromResult(result, cbd_tab); |
161 } | 182 } |
OLD | NEW |