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

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

Issue 2556363003: Refactor cache counting into a separate helper class (Closed)
Patch Set: Remove code depending on GetEntrySize() Created 3 years, 11 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/cache_counter.h » ('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 "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.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/media_licenses_counter.h" 10 #include "chrome/browser/browsing_data/media_licenses_counter.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 const browsing_data::BrowsingDataCounter::Result* result) { 56 const browsing_data::BrowsingDataCounter::Result* result) {
57 std::string pref_name = result->source()->GetPrefName(); 57 std::string pref_name = result->source()->GetPrefName();
58 58
59 if (!result->Finished()) { 59 if (!result->Finished()) {
60 // The counter is still counting. 60 // The counter is still counting.
61 return l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING); 61 return l10n_util::GetStringUTF16(IDS_CLEAR_BROWSING_DATA_CALCULATING);
62 } 62 }
63 63
64 if (pref_name == browsing_data::prefs::kDeleteCache) { 64 if (pref_name == browsing_data::prefs::kDeleteCache) {
65 // Cache counter. 65 // Cache counter.
66 browsing_data::BrowsingDataCounter::ResultInt cache_size_bytes = 66 const auto* cache_result =
67 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( 67 static_cast<const CacheCounter::CacheResult*>(result);
68 result) 68 int64_t cache_size_bytes = cache_result->cache_size();
69 ->Value(); 69 bool is_upper_limit = cache_result->is_upper_limit();
70
71 PrefService* prefs = result->source()->GetPrefs();
72 browsing_data::TimePeriod time_period =
73 static_cast<browsing_data::TimePeriod>(
74 prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod));
75 70
76 // Three cases: Nonzero result for the entire cache, nonzero result for 71 // Three cases: Nonzero result for the entire cache, nonzero result for
77 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). 72 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB).
78 static const int kBytesInAMegabyte = 1024 * 1024; 73 static const int kBytesInAMegabyte = 1024 * 1024;
79 if (cache_size_bytes >= kBytesInAMegabyte) { 74 if (cache_size_bytes >= kBytesInAMegabyte) {
80 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); 75 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes);
81 return time_period == browsing_data::ALL_TIME 76 return !is_upper_limit
82 ? formatted_size 77 ? formatted_size
83 : l10n_util::GetStringFUTF16( 78 : l10n_util::GetStringFUTF16(
84 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size); 79 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size);
85 } 80 }
86 return l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); 81 return l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY);
87 } 82 }
88 83
89 if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) { 84 if (pref_name == browsing_data::prefs::kDeleteMediaLicenses) {
90 const MediaLicensesCounter::MediaLicenseResult* media_license_result = 85 const MediaLicensesCounter::MediaLicenseResult* media_license_result =
91 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result); 86 static_cast<const MediaLicensesCounter::MediaLicenseResult*>(result);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return base::ReplaceStringPlaceholders( 125 return base::ReplaceStringPlaceholders(
131 l10n_util::GetPluralStringFUTF16( 126 l10n_util::GetPluralStringFUTF16(
132 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count), 127 IDS_DEL_HOSTED_APPS_COUNTER, hosted_apps_count),
133 replacements, 128 replacements,
134 nullptr); 129 nullptr);
135 } 130 }
136 #endif 131 #endif
137 132
138 return browsing_data::GetCounterTextFromResult(result); 133 return browsing_data::GetCounterTextFromResult(result);
139 } 134 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browsing_data/cache_counter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698