Index: components/ntp_snippets/ntp_snippets_service.cc |
diff --git a/components/ntp_snippets/ntp_snippets_service.cc b/components/ntp_snippets/ntp_snippets_service.cc |
index 5eddd097b2b5b1d356165e4d25e213276f930d92..ab4ac9341d834a69ebc6bcb42dd73cf270bae224 100644 |
--- a/components/ntp_snippets/ntp_snippets_service.cc |
+++ b/components/ntp_snippets/ntp_snippets_service.cc |
@@ -13,6 +13,7 @@ |
#include "base/files/file_util.h" |
#include "base/json/json_reader.h" |
#include "base/location.h" |
+#include "base/metrics/histogram_macros.h" |
#include "base/metrics/sparse_histogram.h" |
#include "base/path_service.h" |
#include "base/strings/string_number_conversions.h" |
@@ -287,7 +288,8 @@ std::set<std::string> NTPSnippetsService::GetSuggestionsHosts() const { |
bool NTPSnippetsService::DiscardSnippet(const GURL& url) { |
auto it = std::find_if(snippets_.begin(), snippets_.end(), |
[&url](const std::unique_ptr<NTPSnippet>& snippet) { |
- return snippet->url() == url; |
+ return snippet->url() == url || |
+ snippet->best_source().url == url; |
}); |
if (it == snippets_.end()) |
return false; |
@@ -344,7 +346,6 @@ void NTPSnippetsService::OnSuggestionsChanged( |
void NTPSnippetsService::OnSnippetsDownloaded( |
const std::string& snippets_json, const std::string& status) { |
- |
if (!snippets_json.empty()) { |
DCHECK(status.empty()); |
@@ -420,6 +421,26 @@ bool NTPSnippetsService::LoadFromListValue(const base::ListValue& list) { |
} |
} |
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kAddIncompleteSnippets)) { |
+ int num_new_snippets = new_snippets.size(); |
+ // Remove snippets that do not have all the info we need to display it to |
+ // the user. |
+ new_snippets.erase( |
+ std::remove_if(new_snippets.begin(), new_snippets.end(), |
+ [](const std::unique_ptr<NTPSnippet>& snippet) { |
+ return !snippet->is_complete(); |
+ }), |
+ new_snippets.end()); |
+ int num_snippets_discarded = num_new_snippets - new_snippets.size(); |
+ UMA_HISTOGRAM_BOOLEAN("NewTabPage.Snippets.IncompleteSnippetsAfterFetch", |
+ num_snippets_discarded > 0); |
+ if (num_snippets_discarded > 0) { |
+ UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumIncompleteSnippets", |
+ num_snippets_discarded); |
+ } |
+ } |
+ |
// Insert the new snippets at the front. |
snippets_.insert(snippets_.begin(), |
std::make_move_iterator(new_snippets.begin()), |
@@ -442,8 +463,7 @@ void NTPSnippetsService::StoreSnippetsToPrefs() { |
void NTPSnippetsService::LoadDiscardedSnippetsFromPrefs() { |
discarded_snippets_.clear(); |
bool success = AddSnippetsFromListValue( |
- *pref_service_->GetList(prefs::kDiscardedSnippets), |
- &discarded_snippets_); |
+ *pref_service_->GetList(prefs::kDiscardedSnippets), &discarded_snippets_); |
DCHECK(success) << "Failed to parse discarded snippets from prefs"; |
} |