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..affc6e29c1dfae08025f3b17365203c0a0c68439 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,21 @@ const char kHtmlHeader[] = |
const char kHtmlBody[] = "</head>\n<body>\n"; |
const char kHtmlFooter[] = "</body>\n</html>\n"; |
+std::string FormatTimeDelta(int64 time_delta_usec){ |
Mathieu
2014/08/04 14:39:10
I searched and found this class, which may contain
gayane -on leave until 09-2017
2014/08/04 16:34:57
With this class I can only show the two values(e.g
|
+ int milliseconds = (time_delta_usec / Time.kMicrosecondsPerMillisecond) % |
+ Time.KMillisecondsPerSecond; |
+ int seconds = (time_delta_usec / Time.KMicrosecondsPerSecond) % |
+ Time.kSecondsPerMinute; |
+ int minutes = (time_delta_usec / Time.kMicrosecondsPerMinute) % |
+ Time.KMinutesPerHour; |
+ int hours = (time_delta_usec / Time.kMicrosecondsPerHour); |
+ std::string formatted = base::StringPrintf( |
+ "%dh %dm %ds %dms", |
+ hours, minutes, seconds, milliseconds); |
+ |
+ 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 +60,14 @@ 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(); |
+ |
size_t size = profile.suggestions_size(); |
for (size_t i = 0; i < size; ++i) { |
const ChromeSuggestion& suggestion = profile.suggestions(i); |
+ int64 diff = (suggestion.expiry_ts()-now); |
Mathieu
2014/08/04 14:39:10
no () around the expression, add one space each si
gayane -on leave until 09-2017
2014/08/04 16:34:57
Done.
|
+ |
std::string line; |
line += "<li><a href=\""; |
line += net::EscapeForHTML(suggestion.url()); |
@@ -57,7 +80,10 @@ void RenderOutputHtml(const SuggestionsProfile& profile, |
line += it->second; |
line += "'>"; |
} |
- line += "</a></li>\n"; |
+ line += "</a> Expires in "; |
+ line += FormatTimeDelta(diff); |
+ |
Mathieu
2014/08/04 14:39:10
remove extra line
gayane -on leave until 09-2017
2014/08/04 16:34:57
Done.
|
+ line += "</li>\n"; |
out.push_back(line); |
} |
out.push_back("</ul>"); |