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

Unified Diff: components/suggestions/suggestions_service.cc

Issue 423133003: [Suggestions Service] Add support for expiring the SuggestionsStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test improvement: scoped_ptr for SuggestionsStore object in unittests 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_service.cc
diff --git a/components/suggestions/suggestions_service.cc b/components/suggestions/suggestions_service.cc
index 181a3d8c8c1865239df5419da5fb104e94db52ea..13a95045d2da70ccaece4087c9edb934cf9e6738 100644
--- a/components/suggestions/suggestions_service.cc
+++ b/components/suggestions/suggestions_service.cc
@@ -101,6 +101,9 @@ const char kSuggestionsFieldTrialControlParam[] = "control";
const char kSuggestionsFieldTrialStateEnabled[] = "enabled";
const char kSuggestionsFieldTrialTimeoutMs[] = "timeout_ms";
+// The default expiry timeout it 72 hours.
Mathieu 2014/08/06 15:23:53 *is
gayane -on leave until 09-2017 2014/08/06 21:12:20 Done.
+const int64 kDefaultExpiryUsec = 72 * base::Time::kMicrosecondsPerHour;
+
namespace {
std::string GetBlacklistUrlPrefix() {
@@ -304,7 +307,7 @@ void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) {
bool success = request->GetResponseAsString(&suggestions_data);
DCHECK(success);
- // Compute suggestions, and dispatch then to requestors. On error still
+ // Compute suggestions, and dispatch them to requestors. On error still
// dispatch empty suggestions.
SuggestionsProfile suggestions;
if (suggestions_data.empty()) {
@@ -313,6 +316,10 @@ void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) {
} else if (suggestions.ParseFromString(suggestions_data)) {
LogResponseState(RESPONSE_VALID);
thumbnail_manager_->Initialize(suggestions);
+
+ int64 now_usec = (base::Time::NowFromSystemTime() - base::Time::UnixEpoch())
+ .ToInternalValue();
+ SetDefaultExpiryTimestamp(&suggestions, now_usec + kDefaultExpiryUsec);
suggestions_store_->StoreSuggestions(suggestions);
} else {
LogResponseState(RESPONSE_INVALID);
@@ -323,6 +330,18 @@ void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) {
ScheduleBlacklistUpload(true);
}
+void SuggestionsService::SetDefaultExpiryTimestamp(
+ SuggestionsProfile* suggestions, int64 default_timestamp_usec) {
+ for (int i = 0; i < suggestions->suggestions_size(); ++i) {
+ ChromeSuggestion* suggestion = suggestions->mutable_suggestions(i);
+ // Do not set expiry if the server has already provided a more specific
+ // expiry time for this suggestion.
+ if (!suggestion->has_expiry_ts()) {
+ suggestion->set_expiry_ts(default_timestamp_usec);
+ }
+ }
+}
+
void SuggestionsService::Shutdown() {
// Cancel pending request and timeout closure, then serve existing requestors
// from cache.

Powered by Google App Engine
This is Rietveld 408576698