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

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

Powered by Google App Engine
This is Rietveld 408576698