Chromium Code Reviews| Index: components/suggestions/suggestions_store.cc |
| diff --git a/components/suggestions/suggestions_store.cc b/components/suggestions/suggestions_store.cc |
| index 1d1147b342c12650cbc15f65bbd86cb5c32bb16d..3ed1d6e01807549d487956637d1124a2f33d3330 100644 |
| --- a/components/suggestions/suggestions_store.cc |
| +++ b/components/suggestions/suggestions_store.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/base64.h" |
| #include "base/prefs/pref_service.h" |
| +#include "base/time/time.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| #include "components/suggestions/suggestions_pref_names.h" |
| @@ -40,9 +41,36 @@ bool SuggestionsStore::LoadSuggestions(SuggestionsProfile* suggestions) { |
| return false; |
| } |
| + // Filter expired suggestions and update the stored suggestions if at least |
| + // one was filtered. Return false if all suggestions are filtered. |
| + int unfiltered_size = suggestions->suggestions_size(); |
| + FilterExpiredSuggestions(suggestions); |
| + if (suggestions->suggestions_size() != unfiltered_size){ |
|
manzagop (departed)
2014/08/04 19:50:26
nit: space before the curly bracket
gayane -on leave until 09-2017
2014/08/05 14:39:15
Done.
|
| + StoreSuggestions(*suggestions); |
| + } |
| + if (!suggestions->suggestions_size()){ |
|
manzagop (departed)
2014/08/04 19:50:26
Perhaps in this case we should call ClearSuggestio
manzagop (departed)
2014/08/04 19:50:26
nit: same here.
gayane -on leave until 09-2017
2014/08/05 14:39:15
Done.
gayane -on leave until 09-2017
2014/08/05 14:39:15
Done.
|
| + suggestions->Clear(); |
| + return false; |
| + } |
| + |
| return true; |
| } |
| +void SuggestionsStore::FilterExpiredSuggestions( |
| + SuggestionsProfile* suggestions) { |
| + SuggestionsProfile filtered_suggestions; |
| + int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch()) |
| + .ToInternalValue(); |
| + |
| + for (int i = 0; i < suggestions->suggestions_size(); ++i) { |
| + ChromeSuggestion* suggestion = suggestions->mutable_suggestions(i); |
| + if (!suggestion->has_expiry_ts() || suggestion->expiry_ts() > now_usec) { |
| + filtered_suggestions.add_suggestions()->Swap(suggestion); |
| + } |
| + } |
| + suggestions->Swap(&filtered_suggestions); |
| +} |
| + |
| bool SuggestionsStore::StoreSuggestions(const SuggestionsProfile& suggestions) { |
| std::string suggestions_data; |
| if (!suggestions.SerializeToString(&suggestions_data)) return false; |