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 "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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 result)->Value(); | 65 result)->Value(); |
66 text = l10n_util::GetPluralStringFUTF16( | 66 text = l10n_util::GetPluralStringFUTF16( |
67 IDS_DEL_PASSWORDS_COUNTER, passwords_count); | 67 IDS_DEL_PASSWORDS_COUNTER, passwords_count); |
68 | 68 |
69 } else if (pref_name == prefs::kDeleteCache) { | 69 } else if (pref_name == prefs::kDeleteCache) { |
70 // Cache counter. | 70 // Cache counter. |
71 BrowsingDataCounter::ResultInt cache_size_bytes = | 71 BrowsingDataCounter::ResultInt cache_size_bytes = |
72 static_cast<const BrowsingDataCounter::FinishedResult*>( | 72 static_cast<const BrowsingDataCounter::FinishedResult*>( |
73 result)->Value(); | 73 result)->Value(); |
74 | 74 |
75 PrefService* prefs = result->source()->GetProfile()->GetPrefs(); | 75 PrefService* prefs = result->source()->GetPrefs(); |
76 BrowsingDataRemover::TimePeriod time_period = | 76 TimePeriod time_period = |
77 static_cast<BrowsingDataRemover::TimePeriod>( | 77 static_cast<TimePeriod>(prefs->GetInteger(prefs::kDeleteTimePeriod)); |
78 prefs->GetInteger(prefs::kDeleteTimePeriod)); | |
79 | 78 |
80 // Three cases: Nonzero result for the entire cache, nonzero result for | 79 // Three cases: Nonzero result for the entire cache, nonzero result for |
81 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). | 80 // a subset of cache (i.e. a finite time interval), and almost zero (< 1MB). |
82 static const int kBytesInAMegabyte = 1024 * 1024; | 81 static const int kBytesInAMegabyte = 1024 * 1024; |
83 if (cache_size_bytes >= kBytesInAMegabyte) { | 82 if (cache_size_bytes >= kBytesInAMegabyte) { |
84 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); | 83 base::string16 formatted_size = FormatBytesMBOrHigher(cache_size_bytes); |
85 text = time_period == BrowsingDataRemover::EVERYTHING | 84 text = time_period == EVERYTHING |
86 ? formatted_size | 85 ? formatted_size |
87 : l10n_util::GetStringFUTF16(IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, | 86 : l10n_util::GetStringFUTF16( |
88 formatted_size); | 87 IDS_DEL_CACHE_COUNTER_UPPER_ESTIMATE, formatted_size); |
89 } else { | 88 } else { |
90 text = l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); | 89 text = l10n_util::GetStringUTF16(IDS_DEL_CACHE_COUNTER_ALMOST_EMPTY); |
91 } | 90 } |
92 | 91 |
93 } else if (pref_name == prefs::kDeleteBrowsingHistory) { | 92 } else if (pref_name == prefs::kDeleteBrowsingHistory) { |
94 // History counter. | 93 // History counter. |
95 const HistoryCounter::HistoryResult* history_result = | 94 const HistoryCounter::HistoryResult* history_result = |
96 static_cast<const HistoryCounter::HistoryResult*>(result); | 95 static_cast<const HistoryCounter::HistoryResult*>(result); |
97 BrowsingDataCounter::ResultInt local_item_count = history_result->Value(); | 96 BrowsingDataCounter::ResultInt local_item_count = history_result->Value(); |
98 bool has_synced_visits = history_result->has_synced_visits(); | 97 bool has_synced_visits = history_result->has_synced_visits(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 return false; | 230 return false; |
232 case NUM_TYPES: | 231 case NUM_TYPES: |
233 // This is not an actual type. | 232 // This is not an actual type. |
234 NOTREACHED(); | 233 NOTREACHED(); |
235 return false; | 234 return false; |
236 } | 235 } |
237 NOTREACHED(); | 236 NOTREACHED(); |
238 return false; | 237 return false; |
239 } | 238 } |
240 | 239 |
241 BrowsingDataCounter* CreateCounterForPreference(std::string pref_name) { | 240 BrowsingDataCounter* CreateCounterForPreference(std::string pref_name, |
| 241 Profile* profile) { |
242 if (!AreCountersEnabled()) | 242 if (!AreCountersEnabled()) |
243 return nullptr; | 243 return nullptr; |
244 | 244 |
245 if (pref_name == prefs::kDeleteBrowsingHistory) | 245 if (pref_name == prefs::kDeleteBrowsingHistory) |
246 return new HistoryCounter(); | 246 return new HistoryCounter(profile); |
247 if (pref_name == prefs::kDeleteCache) | 247 if (pref_name == prefs::kDeleteCache) |
248 return new CacheCounter(); | 248 return new CacheCounter(profile); |
249 if (pref_name == prefs::kDeletePasswords) | 249 if (pref_name == prefs::kDeletePasswords) |
250 return new PasswordsCounter(); | 250 return new PasswordsCounter(profile); |
251 if (pref_name == prefs::kDeleteFormData) | 251 if (pref_name == prefs::kDeleteFormData) |
252 return new AutofillCounter(); | 252 return new AutofillCounter(profile); |
253 | 253 |
254 return nullptr; | 254 return nullptr; |
255 } | 255 } |
OLD | NEW |