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

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

Issue 2594723002: Count number of origins with data affected by clearing "cookies and site data". (Closed)
Patch Set: improve string description Created 3 years, 9 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/feature_list.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browsing_data/cache_counter.h" 10 #include "chrome/browser/browsing_data/cache_counter.h"
10 #include "chrome/browser/browsing_data/media_licenses_counter.h" 11 #include "chrome/browser/browsing_data/media_licenses_counter.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
15 #include "components/browsing_data/core/pref_names.h" 16 #include "components/browsing_data/core/pref_names.h"
16 #include "components/prefs/pref_service.h" 17 #include "components/prefs/pref_service.h"
17 #include "components/strings/grit/components_strings.h" 18 #include "components/strings/grit/components_strings.h"
18 #include "extensions/features/features.h" 19 #include "extensions/features/features.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/text/bytes_formatting.h" 21 #include "ui/base/text/bytes_formatting.h"
21 22
22 #if BUILDFLAG(ENABLE_EXTENSIONS) 23 #if BUILDFLAG(ENABLE_EXTENSIONS)
23 #include "base/numerics/safe_conversions.h" 24 #include "base/numerics/safe_conversions.h"
24 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
25 #include "chrome/browser/browsing_data/hosted_apps_counter.h" 26 #include "chrome/browser/browsing_data/hosted_apps_counter.h"
26 #endif 27 #endif
27 28
29 #if defined(OS_ANDROID)
30 #include "chrome/browser/android/chrome_feature_list.h"
31 #endif
32
28 bool AreCountersEnabled() { 33 bool AreCountersEnabled() {
29 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 34 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
30 switches::kEnableClearBrowsingDataCounters)) { 35 switches::kEnableClearBrowsingDataCounters)) {
31 return true; 36 return true;
32 } 37 }
33 38
34 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 39 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kDisableClearBrowsingDataCounters)) { 40 switches::kDisableClearBrowsingDataCounters)) {
36 return false; 41 return false;
37 } 42 }
38 43
39 // Enabled by default. 44 // Enabled by default.
40 return true; 45 return true;
41 } 46 }
42 47
48 bool IsCookieCounterEnabled() {
49 #if defined(OS_ANDROID)
50 // Only use the cookie counter for the new CBD ui.
51 return base::FeatureList::IsEnabled(chrome::android::kTabsInCBD);
52 #else
53 // Don't use the counter on other platforms that don't yet have the new ui.
54 return false;
55 #endif
56 }
57
43 // A helper function to display the size of cache in units of MB or higher. 58 // A helper function to display the size of cache in units of MB or higher.
44 // We need this, as 1 MB is the lowest nonzero cache size displayed by the 59 // We need this, as 1 MB is the lowest nonzero cache size displayed by the
45 // counter. 60 // counter.
46 base::string16 FormatBytesMBOrHigher( 61 base::string16 FormatBytesMBOrHigher(
47 browsing_data::BrowsingDataCounter::ResultInt bytes) { 62 browsing_data::BrowsingDataCounter::ResultInt bytes) {
48 if (ui::GetByteDisplayUnits(bytes) >= ui::DataUnits::DATA_UNITS_MEBIBYTE) 63 if (ui::GetByteDisplayUnits(bytes) >= ui::DataUnits::DATA_UNITS_MEBIBYTE)
49 return ui::FormatBytes(bytes); 64 return ui::FormatBytes(bytes);
50 65
51 return ui::FormatBytesWithUnits( 66 return ui::FormatBytesWithUnits(
52 bytes, ui::DataUnits::DATA_UNITS_MEBIBYTE, true); 67 bytes, ui::DataUnits::DATA_UNITS_MEBIBYTE, true);
(...skipping 22 matching lines...) Expand all
75 if (cache_size_bytes >= kBytesInAMegabyte) { 90 if (cache_size_bytes >= kBytesInAMegabyte) {
76 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); 91 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes);
77 return !is_upper_limit 92 return !is_upper_limit
78 ? formatted_size 93 ? formatted_size
79 : l10n_util::GetStringFUTF16( 94 : l10n_util::GetStringFUTF16(
80 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size); 95 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size);
81 } 96 }
82 return l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); 97 return l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY);
83 } 98 }
84 99
100 if (pref_name == browsing_data::prefs::kDeleteCookies) {
101 // Cookie counter.
msramek 2017/03/06 09:40:57 DCHECK(IsCookieCounterEnabled())
dullweber 2017/03/06 10:44:53 Done.
102 browsing_data::BrowsingDataCounter::ResultInt origins =
103 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>(
104 result)
105 ->Value();
106 return l10n_util::GetPluralStringFUTF16(IDS_DEL_COOKIES_COUNTER_ADVANCED,
107 origins);
108 }
109
85 if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) { 110 if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) {
86 const MediaLicensesCounter::MediaLicenseResult* media_license_result = 111 const MediaLicensesCounter::MediaLicenseResult* media_license_result =
87 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result); 112 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result);
88 if (media_license_result->Value() > 0) { 113 if (media_license_result->Value() > 0) {
89 return l10n_util::GetStringFUTF16( 114 return l10n_util::GetStringFUTF16(
90 IDS_DEL_MEDIA_LICENSES_COUNTER_SITE_COMMENT, 115 IDS_DEL_MEDIA_LICENSES_COUNTER_SITE_COMMENT,
91 base::UTF8ToUTF16(media_license_result->GetOneOrigin())); 116 base::UTF8ToUTF16(media_license_result->GetOneOrigin()));
92 } 117 }
93 return l10n_util::GetStringUTF16( 118 return l10n_util::GetStringUTF16(
94 IDS_DEL_MEDIA_LICENSES_COUNTER_GENERAL_COMMENT); 119 IDS_DEL_MEDIA_LICENSES_COUNTER_GENERAL_COMMENT);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return base::ReplaceStringPlaceholders( 151 return base::ReplaceStringPlaceholders(
127 l10n_util::GetPluralStringFUTF16( 152 l10n_util::GetPluralStringFUTF16(
128 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count), 153 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count),
129 replacements, 154 replacements,
130 nullptr); 155 nullptr);
131 } 156 }
132 #endif 157 #endif
133 158
134 return browsing_data::GetCounterTextFromResult(result); 159 return browsing_data::GetCounterTextFromResult(result);
135 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698