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

Unified Diff: components/ntp_snippets/remote/remote_suggestions_fetcher.cc

Issue 2686063003: [remote suggestions] Attach the fetch time to RemoteSnippets, ContentSnippets and SnippetArticle (Closed)
Patch Set: Address time related comments Created 3 years, 10 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/ntp_snippets/remote/remote_suggestions_fetcher.cc
diff --git a/components/ntp_snippets/remote/remote_suggestions_fetcher.cc b/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
index 3722a2faa8ca7a0974ea70c28e3c0b3aaa91a902..aaf62363636a124ce811644b82fd0df14c2bd6d5 100644
--- a/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
+++ b/components/ntp_snippets/remote/remote_suggestions_fetcher.cc
@@ -136,7 +136,8 @@ bool UsesChromeContentSuggestionsAPI(const GURL& endpoint) {
bool AddSuggestionsFromListValue(bool content_suggestions_api,
int remote_category_id,
const base::ListValue& list,
- RemoteSuggestion::PtrVector* suggestions) {
+ RemoteSuggestion::PtrVector* suggestions,
+ const base::Time& fetch_time) {
for (const auto& value : list) {
const base::DictionaryValue* dict = nullptr;
if (!value->GetAsDictionary(&dict)) {
@@ -146,9 +147,10 @@ bool AddSuggestionsFromListValue(bool content_suggestions_api,
std::unique_ptr<RemoteSuggestion> suggestion;
if (content_suggestions_api) {
suggestion = RemoteSuggestion::CreateFromContentSuggestionsDictionary(
- *dict, remote_category_id);
+ *dict, remote_category_id, fetch_time);
} else {
- suggestion = RemoteSuggestion::CreateFromChromeReaderDictionary(*dict);
+ suggestion =
+ RemoteSuggestion::CreateFromChromeReaderDictionary(*dict, fetch_time);
}
if (!suggestion) {
return false;
@@ -442,6 +444,10 @@ void RemoteSuggestionsFetcher::JsonRequestDone(
FetchResult status_code,
const std::string& error_details) {
DCHECK(request);
+ // Record the time when request for fetching remote content snippets finished.
+ const base::Time fetch_time = base::Time::FromInternalValue(
+ tick_clock_->NowTicks().ToInternalValue());
Marc Treib 2017/02/13 10:24:49 Hrm, this is a bit ugly, and I'm not entirely conv
markusheintz_ 2017/02/13 11:19:16 I share your concerns and I fully agree. I'm actua
+
last_fetch_json_ = request->GetResponseString();
UMA_HISTOGRAM_TIMES("NewTabPage.Snippets.FetchTime",
@@ -453,7 +459,8 @@ void RemoteSuggestionsFetcher::JsonRequestDone(
return;
}
FetchedCategoriesVector categories;
- if (!JsonToSnippets(*result, &categories)) {
+
+ if (!JsonToSnippets(*result, &categories, fetch_time)) {
LOG(WARNING) << "Received invalid snippets: " << last_fetch_json_;
FetchFinished(OptionalFetchedCategories(), std::move(callback),
FetchResult::INVALID_SNIPPET_CONTENT_ERROR, std::string());
@@ -489,7 +496,8 @@ void RemoteSuggestionsFetcher::FetchFinished(
bool RemoteSuggestionsFetcher::JsonToSnippets(
const base::Value& parsed,
- FetchedCategoriesVector* categories) {
+ FetchedCategoriesVector* categories,
+ const base::Time& fetch_time) {
const base::DictionaryValue* top_dict = nullptr;
if (!parsed.GetAsDictionary(&top_dict)) {
return false;
@@ -504,9 +512,9 @@ bool RemoteSuggestionsFetcher::JsonToSnippets(
const base::ListValue* recos = nullptr;
return top_dict->GetList("recos", &recos) &&
- AddSuggestionsFromListValue(/*content_suggestions_api=*/false,
- kUnusedRemoteCategoryId, *recos,
- &categories->back().suggestions);
+ AddSuggestionsFromListValue(
+ /*content_suggestions_api=*/false, kUnusedRemoteCategoryId,
+ *recos, &categories->back().suggestions, fetch_time);
}
case FetchAPI::CHROME_CONTENT_SUGGESTIONS_API: {
@@ -533,7 +541,7 @@ bool RemoteSuggestionsFetcher::JsonToSnippets(
if (category_value->GetList("suggestions", &suggestions_list)) {
if (!AddSuggestionsFromListValue(
/*content_suggestions_api=*/true, remote_category_id,
- *suggestions_list, &suggestions)) {
+ *suggestions_list, &suggestions, fetch_time)) {
return false;
}
}

Powered by Google App Engine
This is Rietveld 408576698