| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/browsing_data/core/browsing_data_utils.h" | 5 #include "components/browsing_data/core/browsing_data_utils.h" |
| 6 | 6 |
| 7 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
| 8 #include "components/browsing_data/core/counters/autofill_counter.h" | 8 #include "components/browsing_data/core/counters/autofill_counter.h" |
| 9 #include "components/browsing_data/core/counters/history_counter.h" | 9 #include "components/browsing_data/core/counters/history_counter.h" |
| 10 #include "components/browsing_data/core/counters/passwords_counter.h" | 10 #include "components/browsing_data/core/counters/passwords_counter.h" |
| 11 #include "components/browsing_data/core/pref_names.h" | 11 #include "components/browsing_data/core/pref_names.h" |
| 12 #include "components/prefs/pref_service.h" |
| 12 #include "grit/components_strings.h" | 13 #include "grit/components_strings.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 14 | 15 |
| 15 namespace browsing_data { | 16 namespace browsing_data { |
| 16 | 17 |
| 17 base::Time CalculateBeginDeleteTime(TimePeriod time_period) { | 18 base::Time CalculateBeginDeleteTime(TimePeriod time_period) { |
| 18 base::TimeDelta diff; | 19 base::TimeDelta diff; |
| 19 base::Time delete_begin_time = base::Time::Now(); | 20 base::Time delete_begin_time = base::Time::Now(); |
| 20 switch (time_period) { | 21 switch (time_period) { |
| 21 case LAST_HOUR: | 22 case LAST_HOUR: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // Counters with trivially formatted result: passwords and downloads. | 79 // Counters with trivially formatted result: passwords and downloads. |
| 79 browsing_data::BrowsingDataCounter::ResultInt count = | 80 browsing_data::BrowsingDataCounter::ResultInt count = |
| 80 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( | 81 static_cast<const browsing_data::BrowsingDataCounter::FinishedResult*>( |
| 81 result) | 82 result) |
| 82 ->Value(); | 83 ->Value(); |
| 83 text = l10n_util::GetPluralStringFUTF16( | 84 text = l10n_util::GetPluralStringFUTF16( |
| 84 pref_name == browsing_data::prefs::kDeletePasswords | 85 pref_name == browsing_data::prefs::kDeletePasswords |
| 85 ? IDS_DEL_PASSWORDS_COUNTER | 86 ? IDS_DEL_PASSWORDS_COUNTER |
| 86 : IDS_DEL_DOWNLOADS_COUNTER, | 87 : IDS_DEL_DOWNLOADS_COUNTER, |
| 87 count); | 88 count); |
| 88 } else if (pref_name == browsing_data::prefs::kDeleteBrowsingHistory) { | 89 } else if (pref_name == browsing_data::prefs::kDeleteBrowsingHistory || |
| 90 pref_name == browsing_data::prefs::kDeleteBrowsingHistoryBasic) { |
| 89 // History counter. | 91 // History counter. |
| 90 const browsing_data::HistoryCounter::HistoryResult* history_result = | 92 const browsing_data::HistoryCounter::HistoryResult* history_result = |
| 91 static_cast<const browsing_data::HistoryCounter::HistoryResult*>( | 93 static_cast<const browsing_data::HistoryCounter::HistoryResult*>( |
| 92 result); | 94 result); |
| 93 browsing_data::BrowsingDataCounter::ResultInt local_item_count = | 95 browsing_data::BrowsingDataCounter::ResultInt local_item_count = |
| 94 history_result->Value(); | 96 history_result->Value(); |
| 95 bool has_synced_visits = history_result->has_synced_visits(); | 97 bool has_synced_visits = history_result->has_synced_visits(); |
| 96 | 98 |
| 97 text = has_synced_visits | 99 text = has_synced_visits |
| 98 ? l10n_util::GetPluralStringFUTF16( | 100 ? l10n_util::GetPluralStringFUTF16( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 displayed_strings[1], displayed_strings[2]); | 164 displayed_strings[1], displayed_strings[2]); |
| 163 break; | 165 break; |
| 164 default: | 166 default: |
| 165 NOTREACHED(); | 167 NOTREACHED(); |
| 166 } | 168 } |
| 167 } | 169 } |
| 168 | 170 |
| 169 return text; | 171 return text; |
| 170 } | 172 } |
| 171 | 173 |
| 174 const char* GetTimePeriodPreferenceName( |
| 175 ClearBrowsingDataPreferenceType pref_type) { |
| 176 return pref_type == ClearBrowsingDataPreferenceType::BASIC |
| 177 ? prefs::kDeleteTimePeriodBasic |
| 178 : prefs::kDeleteTimePeriod; |
| 179 } |
| 180 |
| 172 bool GetDeletionPreferenceFromDataType( | 181 bool GetDeletionPreferenceFromDataType( |
| 173 BrowsingDataType data_type, | 182 BrowsingDataType data_type, |
| 183 ClearBrowsingDataPreferenceType pref_type, |
| 174 std::string* out_pref) { | 184 std::string* out_pref) { |
| 185 if (pref_type == ClearBrowsingDataPreferenceType::BASIC) { |
| 186 switch (data_type) { |
| 187 case HISTORY: |
| 188 *out_pref = prefs::kDeleteBrowsingHistoryBasic; |
| 189 return true; |
| 190 case CACHE: |
| 191 *out_pref = prefs::kDeleteCacheBasic; |
| 192 return true; |
| 193 case COOKIES: |
| 194 *out_pref = prefs::kDeleteCookiesBasic; |
| 195 return true; |
| 196 default: |
| 197 // This is not a valid type for the basic tab. |
| 198 NOTREACHED(); |
| 199 return false; |
| 200 } |
| 201 } |
| 175 switch (data_type) { | 202 switch (data_type) { |
| 176 case HISTORY: | 203 case HISTORY: |
| 177 *out_pref = prefs::kDeleteBrowsingHistory; | 204 *out_pref = prefs::kDeleteBrowsingHistory; |
| 178 return true; | 205 return true; |
| 179 case CACHE: | 206 case CACHE: |
| 180 *out_pref = prefs::kDeleteCache; | 207 *out_pref = prefs::kDeleteCache; |
| 181 return true; | 208 return true; |
| 182 case COOKIES: | 209 case COOKIES: |
| 183 *out_pref = prefs::kDeleteCookies; | 210 *out_pref = prefs::kDeleteCookies; |
| 184 return true; | 211 return true; |
| 185 case PASSWORDS: | 212 case PASSWORDS: |
| 186 *out_pref = prefs::kDeletePasswords; | 213 *out_pref = prefs::kDeletePasswords; |
| 187 return true; | 214 return true; |
| 188 case FORM_DATA: | 215 case FORM_DATA: |
| 189 *out_pref = prefs::kDeleteFormData; | 216 *out_pref = prefs::kDeleteFormData; |
| 190 return true; | 217 return true; |
| 191 case BOOKMARKS: | 218 case BOOKMARKS: |
| 192 // Bookmarks are deleted on the Android side. No corresponding deletion | 219 // Bookmarks are deleted on the Android side. No corresponding deletion |
| 193 // preference. | 220 // preference. |
| 194 return false; | 221 return false; |
| 195 case NUM_TYPES: | 222 case NUM_TYPES: |
| 196 // This is not an actual type. | 223 // This is not an actual type. |
| 197 NOTREACHED(); | 224 NOTREACHED(); |
| 198 return false; | 225 return false; |
| 199 } | 226 } |
| 200 NOTREACHED(); | 227 NOTREACHED(); |
| 201 return false; | 228 return false; |
| 202 } | 229 } |
| 203 | 230 |
| 231 void MigratePreferencesToBasic(PrefService* prefs) { |
| 232 if (!prefs->GetBoolean(prefs::kPreferencesMigratedToBasic)) { |
| 233 prefs->SetBoolean(prefs::kDeleteBrowsingHistoryBasic, |
| 234 prefs->GetBoolean(prefs::kDeleteBrowsingHistory)); |
| 235 prefs->SetBoolean(prefs::kDeleteCacheBasic, |
| 236 prefs->GetBoolean(prefs::kDeleteCache)); |
| 237 prefs->SetBoolean(prefs::kDeleteCookiesBasic, |
| 238 prefs->GetBoolean(prefs::kDeleteCookies)); |
| 239 prefs->SetInteger(prefs::kDeleteTimePeriodBasic, |
| 240 prefs->GetInteger(prefs::kDeleteTimePeriod)); |
| 241 prefs->SetBoolean(prefs::kPreferencesMigratedToBasic, true); |
| 242 } |
| 243 } |
| 244 |
| 204 } // namespace browsing_data | 245 } // namespace browsing_data |
| OLD | NEW |