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

Unified Diff: chrome/browser/search/suggestions/suggestions_source.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, 5 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: chrome/browser/search/suggestions/suggestions_source.cc
diff --git a/chrome/browser/search/suggestions/suggestions_source.cc b/chrome/browser/search/suggestions/suggestions_source.cc
index cb0e17e3f798953121fa0a182c1efc7573b26710..a61c5cabde3f6a0d3d18cf1d784ffc6fabb459c7 100644
--- a/chrome/browser/search/suggestions/suggestions_source.cc
+++ b/chrome/browser/search/suggestions/suggestions_source.cc
@@ -11,8 +11,11 @@
#include "base/bind.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string16.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
+#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/suggestions/suggestions_service_factory.h"
#include "chrome/common/url_constants.h"
@@ -33,6 +36,22 @@ const char kHtmlHeader[] =
const char kHtmlBody[] = "</head>\n<body>\n";
const char kHtmlFooter[] = "</body>\n</html>\n";
+std::string FormatTimeDelta(int64 timedelta){
manzagop (departed) 2014/07/31 15:31:49 Include the unit in the name, eg time_delta_usec i
gayane -on leave until 09-2017 2014/08/04 13:46:29 Done.
+
manzagop (departed) 2014/07/31 15:31:49 No need for this empty line.
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
+ timedelta /= 1000;
manzagop (departed) 2014/07/31 15:31:49 I'd argue the code will be more readable / less er
gayane -on leave until 09-2017 2014/08/04 13:46:29 Done.
+ int milliseconds = timedelta % 1000;
manzagop (departed) 2014/07/31 15:31:49 int64?
gayane -on leave until 09-2017 2014/08/04 13:46:30 Isn't it always going to be less then 1000?
+ timedelta /= 1000;
+ int seconds = timedelta%60;
manzagop (departed) 2014/07/31 15:31:49 Put space around binary operators (timedelta % 60)
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
+ timedelta /= 60;
+ int minutes = timedelta%60;
+ timedelta /= 60;
+ int hours = timedelta;
+ std::string formatted = base::StringPrintf("%dh %dm %ds %dms",
+ hours, minutes, seconds, milliseconds);
manzagop (departed) 2014/07/31 15:31:49 Fixup the indentation as per: http://google-styleg
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
+
+ return formatted;
+}
+
// Fills |output| with the HTML needed to display the suggestions.
void RenderOutputHtml(const SuggestionsProfile& profile,
const std::map<GURL, std::string>& base64_encoded_pngs,
@@ -42,9 +61,15 @@ void RenderOutputHtml(const SuggestionsProfile& profile,
out.push_back(kHtmlBody);
out.push_back("<h1>Suggestions</h1>\n<ul>");
+ int64 now = (base::Time::NowFromSystemTime()
+ -base::Time::UnixEpoch()).ToInternalValue();
manzagop (departed) 2014/07/31 15:31:49 Indentation. I would go with: int64 now = (Time::N
gayane -on leave until 09-2017 2014/08/04 13:46:30 I am not sure I did this right. Should it be 4 spa
+
size_t size = profile.suggestions_size();
for (size_t i = 0; i < size; ++i) {
+
manzagop (departed) 2014/07/31 15:31:49 Remove empty line: http://google-styleguide.google
gayane -on leave until 09-2017 2014/08/04 13:46:30 Done.
const ChromeSuggestion& suggestion = profile.suggestions(i);
+ int64 diff = (suggestion.expiry_ts()-now);
+
std::string line;
line += "<li><a href=\"";
line += net::EscapeForHTML(suggestion.url());
@@ -57,7 +82,10 @@ void RenderOutputHtml(const SuggestionsProfile& profile,
line += it->second;
line += "'>";
}
- line += "</a></li>\n";
+ line += "</a> Expires in ";
+ line += FormatTimeDelta(diff);
+
+ line += "</li>\n";
out.push_back(line);
}
out.push_back("</ul>");
« no previous file with comments | « no previous file | components/suggestions/proto/suggestions.proto » ('j') | components/suggestions/suggestions_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698