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

Unified Diff: components/suggestions/suggestions_store.cc

Issue 423133003: [Suggestions Service] Add support for expiring the SuggestionsStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Coding style fixes and refactoring Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: components/suggestions/suggestions_store.cc
diff --git a/components/suggestions/suggestions_store.cc b/components/suggestions/suggestions_store.cc
index 1d1147b342c12650cbc15f65bbd86cb5c32bb16d..16f42ff88a9ff5c8deb8e298151a05cd139d2e74 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,37 @@ 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.
Mathieu 2014/08/04 14:39:11 move as many words to previous line as you can.
gayane -on leave until 09-2017 2014/08/04 16:34:58 Done.
+ int unfiltered_size = suggestions->suggestions_size();
+ FilterExpiredSuggestions(suggestions);
+ if (suggestions->suggestions_size() != unfiltered_size){
+ StoreSuggestions(*suggestions);
+ }
+ if (suggestions->suggestions_size() == 0){
Mathieu 2014/08/04 14:39:11 if (!suggestions->suggesitons_size())
gayane -on leave until 09-2017 2014/08/04 16:34:59 Done.
+ suggestions->Clear();
+ return false;
+ }
+
return true;
}
+void SuggestionsStore::FilterExpiredSuggestions(
+ SuggestionsProfile* suggestions) {
+ SuggestionsProfile* filteredSuggestions = new SuggestionsProfile();
Mathieu 2014/08/04 14:39:11 to construct easily: SuggestionsProfile filtered_
gayane -on leave until 09-2017 2014/08/04 16:34:58 Done.
+ 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) {
+ ChromeSuggestion* tmp = filteredSuggestions->add_suggestions();
Mathieu 2014/08/04 14:39:10 Can probably do filteredSuggestions->add_suggestio
gayane -on leave until 09-2017 2014/08/04 16:34:58 Done.
+ tmp->Swap(suggestion);
+ }
+ }
+ suggestions->Swap(filteredSuggestions);
+}
+
bool SuggestionsStore::StoreSuggestions(const SuggestionsProfile& suggestions) {
std::string suggestions_data;
if (!suggestions.SerializeToString(&suggestions_data)) return false;

Powered by Google App Engine
This is Rietveld 408576698