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

Side by Side 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: Expiry timestamps for suggestions 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/suggestions/suggestions_service.h" 5 #include "components/suggestions/suggestions_service.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 306
307 // Compute suggestions, and dispatch then to requestors. On error still 307 // Compute suggestions, and dispatch then to requestors. On error still
308 // dispatch empty suggestions. 308 // dispatch empty suggestions.
309 SuggestionsProfile suggestions; 309 SuggestionsProfile suggestions;
310 if (suggestions_data.empty()) { 310 if (suggestions_data.empty()) {
311 LogResponseState(RESPONSE_EMPTY); 311 LogResponseState(RESPONSE_EMPTY);
312 suggestions_store_->ClearSuggestions(); 312 suggestions_store_->ClearSuggestions();
313 } else if (suggestions.ParseFromString(suggestions_data)) { 313 } else if (suggestions.ParseFromString(suggestions_data)) {
314 LogResponseState(RESPONSE_VALID); 314 LogResponseState(RESPONSE_VALID);
315 thumbnail_manager_->Initialize(suggestions); 315 thumbnail_manager_->Initialize(suggestions);
316 AddDefaultExpiryTimestamps(&suggestions);
316 suggestions_store_->StoreSuggestions(suggestions); 317 suggestions_store_->StoreSuggestions(suggestions);
317 } else { 318 } else {
318 LogResponseState(RESPONSE_INVALID); 319 LogResponseState(RESPONSE_INVALID);
319 suggestions_store_->LoadSuggestions(&suggestions); 320 suggestions_store_->LoadSuggestions(&suggestions);
320 } 321 }
321 322
322 FilterAndServe(&suggestions); 323 FilterAndServe(&suggestions);
323 ScheduleBlacklistUpload(true); 324 ScheduleBlacklistUpload(true);
324 } 325 }
325 326
327
328 void SuggestionsService::AddDefaultExpiryTimestamps(
329 SuggestionsProfile* suggestions){
manzagop (departed) 2014/07/31 15:31:50 Indent is wrong. You also want a space between ){
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
330
331 // now + 72 hours
manzagop (departed) 2014/07/31 15:31:50 I don't think the comment adds much.
gayane -on leave until 09-2017 2014/08/04 13:46:30 I have removed the comments and renamed default_ex
332 int64 now = (base::Time::NowFromSystemTime()
manzagop (departed) 2014/07/31 15:31:50 now_usec?
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
333 -base::Time::UnixEpoch()).ToInternalValue();
334 int64 default_expiry = 72;
335 int64 timestamp = now + default_expiry * 60 * 60 * 1000 * 1000;
manzagop (departed) 2014/07/31 15:31:50 expiry_timestamp_usec?
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
336
337 for (int i = 0; i < suggestions->suggestions_size(); i++) {
manzagop (departed) 2014/07/31 15:31:50 Preincrement i. See the other comment for details.
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
338 auto* suggestion = suggestions->mutable_suggestions(i);
manzagop (departed) 2014/07/31 15:31:50 No auto in chromium afaik.
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
339
340 if (!suggestion->has_expiry_ts()){
341 suggestion->set_expiry_ts(timestamp);
342 }
343 }
344 }
345
326 void SuggestionsService::Shutdown() { 346 void SuggestionsService::Shutdown() {
327 // Cancel pending request and timeout closure, then serve existing requestors 347 // Cancel pending request and timeout closure, then serve existing requestors
328 // from cache. 348 // from cache.
329 pending_request_.reset(NULL); 349 pending_request_.reset(NULL);
330 pending_timeout_closure_.reset(NULL); 350 pending_timeout_closure_.reset(NULL);
331 ServeFromCache(); 351 ServeFromCache();
332 } 352 }
333 353
334 void SuggestionsService::ServeFromCache() { 354 void SuggestionsService::ServeFromCache() {
335 SuggestionsProfile suggestions; 355 SuggestionsProfile suggestions;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 if (last_request_successful) { 399 if (last_request_successful) {
380 blacklist_delay_sec_ = kBlacklistDefaultDelaySec; 400 blacklist_delay_sec_ = kBlacklistDefaultDelaySec;
381 } else { 401 } else {
382 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier; 402 int candidate_delay = blacklist_delay_sec_ * kBlacklistBackoffMultiplier;
383 if (candidate_delay < kBlacklistMaxDelaySec) 403 if (candidate_delay < kBlacklistMaxDelaySec)
384 blacklist_delay_sec_ = candidate_delay; 404 blacklist_delay_sec_ = candidate_delay;
385 } 405 }
386 } 406 }
387 407
388 } // namespace suggestions 408 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698