| 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 af047ac3af7da517dda41c378aa711cfd3cecd9c..384c1449d936bff1b7b7b7bb7d470942028c3ff8 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/sparse_histogram.h"
|
| #include "base/path_service.h"
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/stringprintf.h"
|
| @@ -128,10 +129,14 @@ std::set<std::string> GetSuggestionsHostsImpl(
|
|
|
| const char kContentInfo[] = "contentInfo";
|
|
|
| -// Parses snippets from |list| and adds them to |snippets|. Returns true on
|
| -// success, false if anything went wrong.
|
| +// Parses snippets from |list| and adds them to |snippets|. |downloaded| should
|
| +// be true if we are adding snippets that have been freshly downloaded, and
|
| +// false if we are loading from prefs. Returns true on success, false if
|
| +// anything went wrong.
|
| bool AddSnippetsFromListValue(const base::ListValue& list,
|
| - NTPSnippetsService::NTPSnippetStorage* snippets) {
|
| + NTPSnippetsService::NTPSnippetStorage* snippets,
|
| + bool downloaded) {
|
| + int num_incomplete_snippets = 0;
|
| for (const base::Value* const value : list) {
|
| const base::DictionaryValue* dict = nullptr;
|
| if (!value->GetAsDictionary(&dict))
|
| @@ -145,8 +150,20 @@ bool AddSnippetsFromListValue(const base::ListValue& list,
|
| if (!snippet)
|
| return false;
|
|
|
| - snippets->push_back(std::move(snippet));
|
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kAddIncompleteSnippets)) {
|
| + snippets->push_back(std::move(snippet));
|
| + } else if (snippet->is_complete()) {
|
| + snippets->push_back(std::move(snippet));
|
| + } else {
|
| + ++num_incomplete_snippets;
|
| + }
|
| }
|
| +
|
| + if (num_incomplete_snippets > 0)
|
| + UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.IncompleteSnippets",
|
| + num_incomplete_snippets);
|
| +
|
| return true;
|
| }
|
|
|
| @@ -394,7 +411,7 @@ bool NTPSnippetsService::LoadFromValue(const base::Value& value) {
|
|
|
| bool NTPSnippetsService::LoadFromListValue(const base::ListValue& list) {
|
| NTPSnippetStorage new_snippets;
|
| - if (!AddSnippetsFromListValue(list, &new_snippets))
|
| + if (!AddSnippetsFromListValue(list, &new_snippets, true))
|
| return false;
|
|
|
| // Remove new snippets that we already have, or that have been discarded.
|
| @@ -444,8 +461,8 @@ 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_,
|
| + false);
|
| DCHECK(success) << "Failed to parse discarded snippets from prefs";
|
| }
|
|
|
|
|