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/string_util.h" | |
9 #include "base/strings/utf_string_conversions.h" | |
8 #include "chrome/browser/browsing_data/autofill_counter.h" | 10 #include "chrome/browser/browsing_data/autofill_counter.h" |
9 #include "chrome/browser/browsing_data/cache_counter.h" | 11 #include "chrome/browser/browsing_data/cache_counter.h" |
10 #include "chrome/browser/browsing_data/history_counter.h" | 12 #include "chrome/browser/browsing_data/history_counter.h" |
13 #include "chrome/browser/browsing_data/hosted_apps_counter.h" | |
11 #include "chrome/browser/browsing_data/passwords_counter.h" | 14 #include "chrome/browser/browsing_data/passwords_counter.h" |
12 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
14 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
15 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
16 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/text/bytes_formatting.h" | 20 #include "ui/base/text/bytes_formatting.h" |
18 | 21 |
19 bool AreCountersEnabled() { | 22 bool AreCountersEnabled() { |
20 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 23 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 break; | 154 break; |
152 case 3: | 155 case 3: |
153 text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_THREE_TYPES, | 156 text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_THREE_TYPES, |
154 displayed_strings[0], | 157 displayed_strings[0], |
155 displayed_strings[1], | 158 displayed_strings[1], |
156 displayed_strings[2]); | 159 displayed_strings[2]); |
157 break; | 160 break; |
158 default: | 161 default: |
159 NOTREACHED(); | 162 NOTREACHED(); |
160 } | 163 } |
164 | |
165 } else if (pref_name == prefs::kDeleteHostedAppsData) { | |
166 // Hosted apps counter. | |
167 const HostedAppsCounter::HostedAppsResult* hosted_apps_result = | |
168 static_cast<const HostedAppsCounter::HostedAppsResult*>(result); | |
169 int hosted_apps_count = hosted_apps_result->Value(); | |
170 | |
171 DCHECK_GE((unsigned int)hosted_apps_result->Value(), | |
vabr (Chromium)
2016/06/20 13:51:43
Please do not use C-style casting. Consider using
msramek
2016/06/20 14:06:18
Done. Yeah, I just quickly added this to compile a
| |
172 hosted_apps_result->examples().size()); | |
173 | |
174 std::vector<base::string16> replacements; | |
175 if (hosted_apps_count > 0) { | |
176 replacements.push_back( // App1, | |
177 base::UTF8ToUTF16(hosted_apps_result->examples()[0])); | |
178 } | |
179 if (hosted_apps_count > 1) { | |
180 replacements.push_back( | |
181 base::UTF8ToUTF16(hosted_apps_result->examples()[1])); // App2, | |
182 } | |
183 if (hosted_apps_count > 2) { | |
184 replacements.push_back(l10n_util::GetPluralStringFUTF16( // and X-2 more. | |
185 IDS_DEL_HOSTED_APPS_COUNTER_AND_X_MORE, | |
186 hosted_apps_count - 2)); | |
187 } | |
188 | |
189 // The output string has both the number placeholder (#) and substitution | |
190 // placeholders ($1, $2, $3). First fetch the correct plural string first, | |
191 // then substitute the $ placeholders. | |
192 text = base::ReplaceStringPlaceholders( | |
193 l10n_util::GetPluralStringFUTF16( | |
194 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count), | |
195 replacements, | |
196 nullptr); | |
161 } | 197 } |
162 | 198 |
163 return text; | 199 return text; |
164 } | 200 } |
165 | 201 |
166 bool GetDeletionPreferenceFromDataType( | 202 bool GetDeletionPreferenceFromDataType( |
167 BrowsingDataType data_type, std::string* out_pref) { | 203 BrowsingDataType data_type, std::string* out_pref) { |
168 switch (data_type) { | 204 switch (data_type) { |
169 case HISTORY: | 205 case HISTORY: |
170 *out_pref = prefs::kDeleteBrowsingHistory; | 206 *out_pref = prefs::kDeleteBrowsingHistory; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 return new HistoryCounter(); | 238 return new HistoryCounter(); |
203 if (pref_name == prefs::kDeleteCache) | 239 if (pref_name == prefs::kDeleteCache) |
204 return new CacheCounter(); | 240 return new CacheCounter(); |
205 if (pref_name == prefs::kDeletePasswords) | 241 if (pref_name == prefs::kDeletePasswords) |
206 return new PasswordsCounter(); | 242 return new PasswordsCounter(); |
207 if (pref_name == prefs::kDeleteFormData) | 243 if (pref_name == prefs::kDeleteFormData) |
208 return new AutofillCounter(); | 244 return new AutofillCounter(); |
209 | 245 |
210 return nullptr; | 246 return nullptr; |
211 } | 247 } |
OLD | NEW |