Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_counter_utils.cc

Issue 2080283002: Implement GetCounterTextFromResult() for the hosted apps counter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed cast type. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/browsing_data/browsing_data_counter_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/browsing_data/autofill_counter.h" 8 #include "chrome/browser/browsing_data/autofill_counter.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/history_counter.h" 10 #include "chrome/browser/browsing_data/history_counter.h"
11 #include "chrome/browser/browsing_data/passwords_counter.h" 11 #include "chrome/browser/browsing_data/passwords_counter.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/prefs/pref_service.h" 15 #include "components/prefs/pref_service.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/text/bytes_formatting.h" 17 #include "ui/base/text/bytes_formatting.h"
18 18
19 #if defined(ENABLE_EXTENSIONS)
20 #include "base/numerics/safe_conversions.h"
21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h"
23 #include "chrome/browser/browsing_data/hosted_apps_counter.h"
24 #endif
25
19 bool AreCountersEnabled() { 26 bool AreCountersEnabled() {
20 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 27 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
21 switches::kEnableClearBrowsingDataCounters)) { 28 switches::kEnableClearBrowsingDataCounters)) {
22 return true; 29 return true;
23 } 30 }
24 31
25 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 32 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
26 switches::kDisableClearBrowsingDataCounters)) { 33 switches::kDisableClearBrowsingDataCounters)) {
27 return false; 34 return false;
28 } 35 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 break; 158 break;
152 case 3: 159 case 3:
153 text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_THREE_TYPES, 160 text = l10n_util::GetStringFUTF16(IDS_DEL_AUTOFILL_COUNTER_THREE_TYPES,
154 displayed_strings[0], 161 displayed_strings[0],
155 displayed_strings[1], 162 displayed_strings[1],
156 displayed_strings[2]); 163 displayed_strings[2]);
157 break; 164 break;
158 default: 165 default:
159 NOTREACHED(); 166 NOTREACHED();
160 } 167 }
168
169 #if defined(ENABLE_EXTENSIONS)
170 } else if (pref_name == prefs::kDeleteHostedAppsData) {
171 // Hosted apps counter.
172 const HostedAppsCounter::HostedAppsResult* hosted_apps_result =
173 static_cast<const HostedAppsCounter::HostedAppsResult*>(result);
174 int hosted_apps_count = hosted_apps_result->Value();
175
176 DCHECK_GE(hosted_apps_result->Value(),
177 base::checked_cast<BrowsingDataCounter::ResultInt>(
178 hosted_apps_result->examples().size()));
179
180 std::vector<base::string16> replacements;
181 if (hosted_apps_count > 0) {
182 replacements.push_back( // App1,
183 base::UTF8ToUTF16(hosted_apps_result->examples()[0]));
184 }
185 if (hosted_apps_count > 1) {
186 replacements.push_back(
187 base::UTF8ToUTF16(hosted_apps_result->examples()[1])); // App2,
188 }
189 if (hosted_apps_count > 2) {
190 replacements.push_back(l10n_util::GetPluralStringFUTF16( // and X-2 more.
191 IDS_DEL_HOSTED_APPS_COUNTER_AND_X_MORE,
192 hosted_apps_count - 2));
193 }
194
195 // The output string has both the number placeholder (#) and substitution
196 // placeholders ($1, $2, $3). First fetch the correct plural string first,
197 // then substitute the $ placeholders.
198 text = base::ReplaceStringPlaceholders(
199 l10n_util::GetPluralStringFUTF16(
200 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count),
201 replacements,
202 nullptr);
203 #endif
204
161 } 205 }
162 206
163 return text; 207 return text;
164 } 208 }
165 209
166 bool GetDeletionPreferenceFromDataType( 210 bool GetDeletionPreferenceFromDataType(
167 BrowsingDataType data_type, std::string* out_pref) { 211 BrowsingDataType data_type, std::string* out_pref) {
168 switch (data_type) { 212 switch (data_type) {
169 case HISTORY: 213 case HISTORY:
170 *out_pref = prefs::kDeleteBrowsingHistory; 214 *out_pref = prefs::kDeleteBrowsingHistory;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return new HistoryCounter(); 246 return new HistoryCounter();
203 if (pref_name == prefs::kDeleteCache) 247 if (pref_name == prefs::kDeleteCache)
204 return new CacheCounter(); 248 return new CacheCounter();
205 if (pref_name == prefs::kDeletePasswords) 249 if (pref_name == prefs::kDeletePasswords)
206 return new PasswordsCounter(); 250 return new PasswordsCounter();
207 if (pref_name == prefs::kDeleteFormData) 251 if (pref_name == prefs::kDeleteFormData)
208 return new AutofillCounter(); 252 return new AutofillCounter();
209 253
210 return nullptr; 254 return nullptr;
211 } 255 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browsing_data/browsing_data_counter_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698