Commit 2646c95b authored by pke's avatar pke Committed by Commit bot

Rename discard to dismiss for NTP snippets and content suggestions

We agreed to use the term 'dismiss' instead of 'discard' for the action
performed by the user to remove content suggestions from the NTP.
These changes are only for the non-Android part. The renaming for the
Android part will follow after or during the ongoing refactoring there.

BUG=None
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2167063003
Cr-Commit-Position: refs/heads/master@{#407456}
parent 1bd8b753
......@@ -106,7 +106,7 @@ void NTPSnippetsBridge::FetchImage(JNIEnv* env,
void NTPSnippetsBridge::DiscardSnippet(JNIEnv* env,
const JavaParamRef<jobject>& obj,
const JavaParamRef<jstring>& id) {
content_suggestions_service_->DiscardSuggestion(
content_suggestions_service_->DismissSuggestion(
ConvertJavaStringToUTF8(env, id));
}
......
......@@ -106,12 +106,12 @@ found in the LICENSE file.
</div>
</div>
<div id="discarded-snippets">
<h2>Discarded snippets <span class="detail">(click for details)</span></h2>
<div id="dismissed-snippets">
<h2>Dismissed snippets <span class="detail">(click for details)</span></h2>
<table class="section-details">
<tr jsselect="list" style="display:none">
<td class="title-link">
<span class="discarded-snippet-title" jsvalues="hidden-id:id">
<span class="dismissed-snippet-title" jsvalues="hidden-id:id">
<span jscontent="title"></span> &gt;&gt;</span>
<div jsvalues="id:id" class="snippet-detail hidden">
<table>
......@@ -140,9 +140,9 @@ found in the LICENSE file.
</table>
</div>
</table>
<div class="detail" id="discarded-snippets-empty"></div>
<div class="detail" id="dismissed-snippets-empty"></div>
<div class="forms">
<input id="discarded-snippets-clear" type="submit" value="Clear list">
<input id="dismissed-snippets-clear" type="submit" value="Clear list">
</div>
</div>
......@@ -205,8 +205,8 @@ found in the LICENSE file.
<div class="forms">
<input id="submit-clear-cached-suggestions" type="submit"
value="Clear cached suggestions">
<input id="submit-clear-discarded-suggestions" type="submit"
value="Clear discarded suggestions">
<input id="submit-clear-dismissed-suggestions" type="submit"
value="Clear dismissed suggestions">
</div>
</div>
</div>
......@@ -33,8 +33,8 @@ cr.define('chrome.SnippetsInternals', function() {
event.preventDefault();
});
$('discarded-snippets-clear').addEventListener('click', function(event) {
chrome.send('clearDiscarded');
$('dismissed-snippets-clear').addEventListener('click', function(event) {
chrome.send('clearDismissed');
event.preventDefault();
});
......@@ -44,9 +44,9 @@ cr.define('chrome.SnippetsInternals', function() {
event.preventDefault();
});
$('submit-clear-discarded-suggestions')
$('submit-clear-dismissed-suggestions')
.addEventListener('click', function(event) {
chrome.send('clearDiscardedSuggestions');
chrome.send('clearDismissedSuggestions');
event.preventDefault();
});
......@@ -79,9 +79,9 @@ cr.define('chrome.SnippetsInternals', function() {
displayList(snippets, 'snippets', 'snippet-title');
}
function receiveDiscardedSnippets(discardedSnippets) {
displayList(discardedSnippets, 'discarded-snippets',
'discarded-snippet-title');
function receiveDismissedSnippets(dismissedSnippets) {
displayList(dismissedSnippets, 'dismissed-snippets',
'dismissed-snippet-title');
}
function receiveContentSuggestions(categoriesList) {
......@@ -150,7 +150,7 @@ cr.define('chrome.SnippetsInternals', function() {
receiveProperty: receiveProperty,
receiveHosts: receiveHosts,
receiveSnippets: receiveSnippets,
receiveDiscardedSnippets: receiveDiscardedSnippets,
receiveDismissedSnippets: receiveDismissedSnippets,
receiveContentSuggestions: receiveContentSuggestions,
receiveJson: receiveJson,
};
......
......@@ -35,7 +35,7 @@ namespace {
std::unique_ptr<base::DictionaryValue> PrepareSnippet(
const ntp_snippets::NTPSnippet& snippet,
int index,
bool discarded) {
bool dismissed) {
std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
entry->SetString("snippetId", snippet.id());
entry->SetString("title", snippet.title());
......@@ -50,8 +50,8 @@ std::unique_ptr<base::DictionaryValue> PrepareSnippet(
entry->SetString("salientImageUrl", snippet.salient_image_url().spec());
entry->SetDouble("score", snippet.score());
if (discarded)
entry->SetString("id", "discarded-snippet-" + base::IntToString(index));
if (dismissed)
entry->SetString("id", "dismissed-snippet-" + base::IntToString(index));
else
entry->SetString("id", "snippet-" + base::IntToString(index));
......@@ -183,8 +183,8 @@ void SnippetsInternalsMessageHandler::RegisterMessages() {
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"clearDiscarded",
base::Bind(&SnippetsInternalsMessageHandler::HandleClearDiscarded,
"clearDismissed",
base::Bind(&SnippetsInternalsMessageHandler::HandleClearDismissed,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
......@@ -193,9 +193,9 @@ void SnippetsInternalsMessageHandler::RegisterMessages() {
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"clearDiscardedSuggestions",
"clearDismissedSuggestions",
base::Bind(
&SnippetsInternalsMessageHandler::HandleClearDiscardedSuggestions,
&SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions,
base::Unretained(this)));
}
......@@ -214,12 +214,12 @@ void SnippetsInternalsMessageHandler::HandleClear(const base::ListValue* args) {
ntp_snippets_service_->ClearCachedSuggestionsForDebugging();
}
void SnippetsInternalsMessageHandler::HandleClearDiscarded(
void SnippetsInternalsMessageHandler::HandleClearDismissed(
const base::ListValue* args) {
DCHECK_EQ(0u, args->GetSize());
ntp_snippets_service_->ClearDiscardedSuggestionsForDebugging();
SendDiscardedSnippets();
ntp_snippets_service_->ClearDismissedSuggestionsForDebugging();
SendDismissedSnippets();
}
void SnippetsInternalsMessageHandler::HandleDownload(
......@@ -245,11 +245,11 @@ void SnippetsInternalsMessageHandler::HandleClearCachedSuggestions(
content_suggestions_service_->ClearCachedSuggestionsForDebugging();
}
void SnippetsInternalsMessageHandler::HandleClearDiscardedSuggestions(
void SnippetsInternalsMessageHandler::HandleClearDismissedSuggestions(
const base::ListValue* args) {
DCHECK_EQ(0u, args->GetSize());
content_suggestions_service_->ClearDiscardedSuggestionsForDebugging();
content_suggestions_service_->ClearDismissedSuggestionsForDebugging();
}
void SnippetsInternalsMessageHandler::SendAllContent() {
......@@ -284,7 +284,7 @@ void SnippetsInternalsMessageHandler::SendAllContent() {
ntp_snippets_service_->snippets_fetcher()->fetch_url().spec());
SendSnippets();
SendDiscardedSnippets();
SendDismissedSnippets();
SendContentSuggestions();
}
......@@ -307,17 +307,17 @@ void SnippetsInternalsMessageHandler::SendSnippets() {
SendString("hosts-status", "Finished: " + status);
}
void SnippetsInternalsMessageHandler::SendDiscardedSnippets() {
void SnippetsInternalsMessageHandler::SendDismissedSnippets() {
std::unique_ptr<base::ListValue> snippets_list(new base::ListValue);
int index = 0;
for (const auto& snippet : ntp_snippets_service_->discarded_snippets())
for (const auto& snippet : ntp_snippets_service_->dismissed_snippets())
snippets_list->Append(PrepareSnippet(*snippet, index++, true));
base::DictionaryValue result;
result.Set("list", std::move(snippets_list));
web_ui()->CallJavascriptFunctionUnsafe(
"chrome.SnippetsInternals.receiveDiscardedSnippets", result);
"chrome.SnippetsInternals.receiveDismissedSnippets", result);
}
void SnippetsInternalsMessageHandler::SendHosts() {
......
......@@ -47,14 +47,14 @@ class SnippetsInternalsMessageHandler
void HandleRefreshContent(const base::ListValue* args);
void HandleClear(const base::ListValue* args);
void HandleClearDiscarded(const base::ListValue* args);
void HandleClearDismissed(const base::ListValue* args);
void HandleDownload(const base::ListValue* args);
void HandleClearCachedSuggestions(const base::ListValue* args);
void HandleClearDiscardedSuggestions(const base::ListValue* args);
void HandleClearDismissedSuggestions(const base::ListValue* args);
void SendAllContent();
void SendSnippets();
void SendDiscardedSnippets();
void SendDismissedSnippets();
void SendHosts();
void SendContentSuggestions();
void SendBoolean(const std::string& name, bool value);
......
......@@ -71,11 +71,11 @@ class ContentSuggestionsProvider {
virtual ContentSuggestionsCategoryStatus GetCategoryStatus(
ContentSuggestionsCategory category) = 0;
// Discards the suggestion with the given ID. A provider needs to ensure that
// a once-discarded suggestion is never delivered again (through the
// Dismisses the suggestion with the given ID. A provider needs to ensure that
// a once-dismissed suggestion is never delivered again (through the
// Observer). The provider must not call Observer::OnSuggestionsChanged if the
// removal of the discarded suggestion is the only change.
virtual void DiscardSuggestion(const std::string& suggestion_id) = 0;
// removal of the dismissed suggestion is the only change.
virtual void DismissSuggestion(const std::string& suggestion_id) = 0;
// Fetches the image for the suggestion with the given ID and returns it
// through the callback. This fetch may occur locally or from the internet.
......@@ -88,11 +88,11 @@ class ContentSuggestionsProvider {
// fetch starts from scratch.
virtual void ClearCachedSuggestionsForDebugging() = 0;
// Used only for debugging purposes. Clears the cache of discarded
// Used only for debugging purposes. Clears the cache of dismissed
// suggestions, if present, so that no suggestions are suppressed. This does
// not necessarily make previously discarded suggestions reappear, as they may
// not necessarily make previously dismissed suggestions reappear, as they may
// have been permanently deleted, depending on the provider implementation.
virtual void ClearDiscardedSuggestionsForDebugging() = 0;
virtual void ClearDismissedSuggestionsForDebugging() = 0;
const std::vector<ContentSuggestionsCategory>& provided_categories() const {
return provided_categories_;
......
......@@ -77,25 +77,25 @@ void ContentSuggestionsService::ClearCachedSuggestionsForDebugging() {
FOR_EACH_OBSERVER(Observer, observers_, OnNewSuggestions());
}
void ContentSuggestionsService::ClearDiscardedSuggestionsForDebugging() {
void ContentSuggestionsService::ClearDismissedSuggestionsForDebugging() {
for (auto& category_provider_pair : providers_) {
category_provider_pair.second->ClearDiscardedSuggestionsForDebugging();
category_provider_pair.second->ClearDismissedSuggestionsForDebugging();
}
}
void ContentSuggestionsService::DiscardSuggestion(
void ContentSuggestionsService::DismissSuggestion(
const std::string& suggestion_id) {
if (!id_category_map_.count(suggestion_id)) {
LOG(WARNING) << "Discarded unknown suggestion " << suggestion_id;
LOG(WARNING) << "Dismissed unknown suggestion " << suggestion_id;
return;
}
ContentSuggestionsCategory category = id_category_map_[suggestion_id];
if (!providers_.count(category)) {
LOG(WARNING) << "Discarded suggestion " << suggestion_id
LOG(WARNING) << "Dismissed suggestion " << suggestion_id
<< " for unavailable category " << static_cast<int>(category);
return;
}
providers_[category]->DiscardSuggestion(suggestion_id);
providers_[category]->DismissSuggestion(suggestion_id);
// Remove the suggestion locally.
id_category_map_.erase(suggestion_id);
......@@ -107,9 +107,9 @@ void ContentSuggestionsService::DiscardSuggestion(
return suggestion_id == suggestion.id();
});
DCHECK(position != suggestions->end())
<< "The discarded suggestion " << suggestion_id
<< "The dismissed suggestion " << suggestion_id
<< " has already been removed. Providers must not call OnNewSuggestions"
" in response to DiscardSuggestion.";
" in response to DismissSuggestion.";
suggestions->erase(position);
}
......
......@@ -92,9 +92,9 @@ class ContentSuggestionsService : public KeyedService,
void FetchSuggestionImage(const std::string& suggestion_id,
const ImageFetchedCallback& callback);
// Discards the suggestion with the given |suggestion_id|, if it exists.
// Dismisses the suggestion with the given |suggestion_id|, if it exists.
// This will not trigger an update through the observers.
void DiscardSuggestion(const std::string& suggestion_id);
void DismissSuggestion(const std::string& suggestion_id);
// Observer accessors.
void AddObserver(Observer* observer);
......@@ -110,14 +110,14 @@ class ContentSuggestionsService : public KeyedService,
// providers. It does, however, not remove any suggestions from the provider's
// sources, so if their configuration hasn't changed, they should return the
// same results when they fetch the next time. In particular, calling this
// method will not mark any suggestions as discarded.
// method will not mark any suggestions as dismissed.
void ClearCachedSuggestionsForDebugging();
// Only for debugging use through the internals page. Some providers
// internally store a list of discarded suggestions to prevent them from
// internally store a list of dismissed suggestions to prevent them from
// reappearing. This function clears all such lists in all providers, making
// discarded suggestions reappear (only for certain providers).
void ClearDiscardedSuggestionsForDebugging();
// dismissed suggestions reappear (only for certain providers).
void ClearDismissedSuggestionsForDebugging();
private:
friend class ContentSuggestionsServiceTest;
......
......@@ -86,8 +86,8 @@ class MockProvider : public ContentSuggestionsProvider {
}
MOCK_METHOD0(ClearCachedSuggestionsForDebugging, void());
MOCK_METHOD0(ClearDiscardedSuggestionsForDebugging, void());
MOCK_METHOD1(DiscardSuggestion, void(const std::string& suggestion_id));
MOCK_METHOD0(ClearDismissedSuggestionsForDebugging, void());
MOCK_METHOD1(DismissSuggestion, void(const std::string& suggestion_id));
MOCK_METHOD2(FetchSuggestionImage,
void(const std::string& suggestion_id,
const ImageFetchedCallback& callback));
......@@ -305,7 +305,7 @@ TEST_F(ContentSuggestionsServiceTest,
base::Unretained(this)));
}
TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDiscardSuggestion) {
TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDismissSuggestion) {
MockProvider provider1(ContentSuggestionsCategory::ARTICLES);
MockProvider provider2(ContentSuggestionsCategory::OFFLINE_PAGES);
service()->RegisterProvider(&provider1);
......@@ -315,9 +315,9 @@ TEST_F(ContentSuggestionsServiceTest, ShouldRedirectDiscardSuggestion) {
{11});
std::string suggestion_id = CreateSuggestion(11).id();
EXPECT_CALL(provider1, DiscardSuggestion(_)).Times(0);
EXPECT_CALL(provider2, DiscardSuggestion(suggestion_id)).Times(1);
service()->DiscardSuggestion(suggestion_id);
EXPECT_CALL(provider1, DismissSuggestion(_)).Times(0);
EXPECT_CALL(provider2, DismissSuggestion(suggestion_id)).Times(1);
service()->DismissSuggestion(suggestion_id);
provider1.FireShutdown();
provider2.FireShutdown();
}
......
......@@ -39,7 +39,7 @@ bool GetURLValue(const base::DictionaryValue& dict,
namespace ntp_snippets {
NTPSnippet::NTPSnippet(const std::string& id)
: id_(id), score_(0), is_discarded_(false), best_source_index_(0) {}
: id_(id), score_(0), is_dismissed_(false), best_source_index_(0) {}
NTPSnippet::~NTPSnippet() {}
......@@ -184,7 +184,7 @@ std::unique_ptr<NTPSnippet> NTPSnippet::CreateFromProto(
base::Time::FromInternalValue(proto.publish_date()));
snippet->set_expiry_date(base::Time::FromInternalValue(proto.expiry_date()));
snippet->set_score(proto.score());
snippet->set_discarded(proto.discarded());
snippet->set_dismissed(proto.dismissed());
for (int i = 0; i < proto.sources_size(); ++i) {
const SnippetSourceProto& source_proto = proto.sources(i);
......@@ -230,7 +230,7 @@ SnippetProto NTPSnippet::ToProto() const {
if (!expiry_date_.is_null())
result.set_expiry_date(expiry_date_.ToInternalValue());
result.set_score(score_);
result.set_discarded(is_discarded_);
result.set_dismissed(is_dismissed_);
for (const SnippetSource& source : sources_) {
SnippetSourceProto* source_proto = result.add_sources();
......
......@@ -122,8 +122,8 @@ class NTPSnippet {
float score() const { return score_; }
void set_score(float score) { score_ = score; }
bool is_discarded() const { return is_discarded_; }
void set_discarded(bool discarded) { is_discarded_ = discarded; }
bool is_dismissed() const { return is_dismissed_; }
void set_dismissed(bool dismissed) { is_dismissed_ = dismissed; }
// Public for testing.
static base::Time TimeFromJsonString(const std::string& timestamp_str);
......@@ -139,7 +139,7 @@ class NTPSnippet {
base::Time publish_date_;
base::Time expiry_date_;
float score_;
bool is_discarded_;
bool is_dismissed_;
size_t best_source_index_;
......
......@@ -37,7 +37,7 @@ bool operator==(const NTPSnippet& lhs, const NTPSnippet& rhs) {
lhs.expiry_date() == rhs.expiry_date() &&
lhs.source_index() == rhs.source_index() &&
lhs.sources() == rhs.sources() && lhs.score() == rhs.score() &&
lhs.is_discarded() == rhs.is_discarded();
lhs.is_dismissed() == rhs.is_dismissed();
}
namespace {
......
......@@ -310,7 +310,7 @@ std::set<std::string> NTPSnippetsService::GetSuggestionsHosts() const {
suggestions_service_->GetSuggestionsDataFromCache());
}
void NTPSnippetsService::DiscardSuggestion(const std::string& suggestion_id) {
void NTPSnippetsService::DismissSuggestion(const std::string& suggestion_id) {
if (!ready())
return;
......@@ -324,24 +324,24 @@ void NTPSnippetsService::DiscardSuggestion(const std::string& suggestion_id) {
if (it == snippets_.end())
return;
(*it)->set_discarded(true);
(*it)->set_dismissed(true);
database_->SaveSnippet(**it);
database_->DeleteImage((*it)->id());
discarded_snippets_.push_back(std::move(*it));
dismissed_snippets_.push_back(std::move(*it));
snippets_.erase(it);
}
void NTPSnippetsService::ClearDiscardedSuggestionsForDebugging() {
void NTPSnippetsService::ClearDismissedSuggestionsForDebugging() {
if (!initialized())
return;
if (discarded_snippets_.empty())
if (dismissed_snippets_.empty())
return;
database_->DeleteSnippets(discarded_snippets_);
discarded_snippets_.clear();
database_->DeleteSnippets(dismissed_snippets_);
dismissed_snippets_.clear();
}
void NTPSnippetsService::SetObserver(Observer* observer) {
......@@ -394,10 +394,10 @@ void NTPSnippetsService::OnDatabaseLoaded(NTPSnippet::PtrVector snippets) {
return;
DCHECK(snippets_.empty());
DCHECK(discarded_snippets_.empty());
DCHECK(dismissed_snippets_.empty());
for (std::unique_ptr<NTPSnippet>& snippet : snippets) {
if (snippet->is_discarded())
discarded_snippets_.emplace_back(std::move(snippet));
if (snippet->is_dismissed())
dismissed_snippets_.emplace_back(std::move(snippet));
else
snippets_.emplace_back(std::move(snippet));
}
......@@ -470,9 +470,9 @@ void NTPSnippetsService::OnFetchFinished(
UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumArticles",
snippets_.size());
if (snippets_.empty() && !discarded_snippets_.empty()) {
if (snippets_.empty() && !dismissed_snippets_.empty()) {
UMA_HISTOGRAM_COUNTS("NewTabPage.Snippets.NumArticlesZeroDueToDiscarded",
discarded_snippets_.size());
dismissed_snippets_.size());
}
NotifyNewSuggestions();
......@@ -481,9 +481,9 @@ void NTPSnippetsService::OnFetchFinished(
void NTPSnippetsService::MergeSnippets(NTPSnippet::PtrVector new_snippets) {
DCHECK(ready());
// Remove new snippets that we already have, or that have been discarded.
// Remove new snippets that we already have, or that have been dismissed.
std::set<std::string> old_snippet_ids;
InsertAllIDs(discarded_snippets_, &old_snippet_ids);
InsertAllIDs(dismissed_snippets_, &old_snippet_ids);
InsertAllIDs(snippets_, &old_snippet_ids);
new_snippets.erase(
std::remove_if(
......@@ -523,12 +523,12 @@ void NTPSnippetsService::MergeSnippets(NTPSnippet::PtrVector new_snippets) {
return !snippet->is_complete();
}),
new_snippets.end());
int num_snippets_discarded = num_new_snippets - new_snippets.size();
int num_snippets_dismissed = num_new_snippets - new_snippets.size();
UMA_HISTOGRAM_BOOLEAN("NewTabPage.Snippets.IncompleteSnippetsAfterFetch",
num_snippets_discarded > 0);
if (num_snippets_discarded > 0) {
num_snippets_dismissed > 0);
if (num_snippets_dismissed > 0) {
UMA_HISTOGRAM_SPARSE_SLOWLY("NewTabPage.Snippets.NumIncompleteSnippets",
num_snippets_discarded);
num_snippets_dismissed);
}
}
......@@ -572,18 +572,18 @@ void NTPSnippetsService::ClearExpiredSnippets() {
}
Compact(&snippets_);
// Move expired discarded snippets over into |to_delete| as well.
for (std::unique_ptr<NTPSnippet>& snippet : discarded_snippets_) {
// Move expired dismissed snippets over into |to_delete| as well.
for (std::unique_ptr<NTPSnippet>& snippet : dismissed_snippets_) {
if (snippet->expiry_date() <= expiry)
to_delete.emplace_back(std::move(snippet));
}
Compact(&discarded_snippets_);
Compact(&dismissed_snippets_);
// Finally, actually delete the removed snippets from the DB.
database_->DeleteSnippets(to_delete);
// If there are any snippets left, schedule a timer for the next expiry.
if (snippets_.empty() && discarded_snippets_.empty())
if (snippets_.empty() && dismissed_snippets_.empty())
return;
base::Time next_expiry = base::Time::Max();
......@@ -591,7 +591,7 @@ void NTPSnippetsService::ClearExpiredSnippets() {
if (snippet->expiry_date() < next_expiry)
next_expiry = snippet->expiry_date();
}
for (const auto& snippet : discarded_snippets_) {
for (const auto& snippet : dismissed_snippets_) {
if (snippet->expiry_date() < next_expiry)
next_expiry = snippet->expiry_date();
}
......@@ -670,7 +670,7 @@ void NTPSnippetsService::EnterStateEnabled(bool fetch_snippets) {
void NTPSnippetsService::EnterStateDisabled() {
ClearCachedSuggestionsForDebugging();
ClearDiscardedSuggestionsForDebugging();
ClearDismissedSuggestionsForDebugging();
expiry_timer_.Stop();
suggestions_service_subscription_.reset();
......
......@@ -92,7 +92,7 @@ class NTPSnippetsService : public KeyedService,
void Shutdown() override;
// Returns whether the service is ready. While this is false, the list of
// snippets will be empty, and all modifications to it (fetch, discard, etc)
// snippets will be empty, and all modifications to it (fetch, dismiss, etc)
// will be ignored.
bool ready() const { return state_ == State::READY; }
......@@ -111,10 +111,10 @@ class NTPSnippetsService : public KeyedService,
// Available snippets.
const NTPSnippet::PtrVector& snippets() const { return snippets_; }
// Returns the list of snippets previously discarded by the user (that are
// Returns the list of snippets previously dismissed by the user (that are
// not expired yet).
const NTPSnippet::PtrVector& discarded_snippets() const {
return discarded_snippets_;
const NTPSnippet::PtrVector& dismissed_snippets() const {
return dismissed_snippets_;
}
const NTPSnippetsFetcher* snippets_fetcher() const {
......@@ -137,11 +137,11 @@ class NTPSnippetsService : public KeyedService,
void SetObserver(Observer* observer) override;
ContentSuggestionsCategoryStatus GetCategoryStatus(
ContentSuggestionsCategory category) override;
void DiscardSuggestion(const std::string& suggestion_id) override;
void DismissSuggestion(const std::string& suggestion_id) override;
void FetchSuggestionImage(const std::string& suggestion_id,
const ImageFetchedCallback& callback) override;
void ClearCachedSuggestionsForDebugging() override;
void ClearDiscardedSuggestionsForDebugging() override;
void ClearDismissedSuggestionsForDebugging() override;
// Returns the lists of suggestion hosts the snippets are restricted to.
std::set<std::string> GetSuggestionsHosts() const;
......@@ -216,7 +216,7 @@ class NTPSnippetsService : public KeyedService,
std::set<std::string> GetSnippetHostsFromPrefs() const;
void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts);
// Removes the expired snippets (including discarded) from the service and the
// Removes the expired snippets (including dismissed) from the service and the
// database, and schedules another pass for the next expiration.
void ClearExpiredSnippets();
......@@ -272,12 +272,12 @@ class NTPSnippetsService : public KeyedService,
suggestions::SuggestionsService* suggestions_service_;
// All current suggestions (i.e. not discarded ones).
// All current suggestions (i.e. not dismissed ones).
NTPSnippet::PtrVector snippets_;
// Suggestions that the user discarded. We keep these around until they expire
// Suggestions that the user dismissed. We keep these around until they expire
// so we won't re-add them on the next fetch.
NTPSnippet::PtrVector discarded_snippets_;
NTPSnippet::PtrVector dismissed_snippets_;
// The ISO 639-1 code of the language used by the application.
const std::string application_language_code_;
......
......@@ -491,7 +491,7 @@ TEST_F(NTPSnippetsServiceTest, LoadIncompleteJsonWithExistingSnippets) {
EXPECT_THAT(service()->snippets(), SizeIs(1));
}
TEST_F(NTPSnippetsServiceTest, Discard) {
TEST_F(NTPSnippetsServiceTest, Dismiss) {
std::vector<std::string> source_urls, publishers, amp_urls;
source_urls.push_back(std::string("http://site.com"));
publishers.push_back(std::string("Source 1"));
......@@ -503,44 +503,44 @@ TEST_F(NTPSnippetsServiceTest, Discard) {
ASSERT_THAT(service()->snippets(), SizeIs(1));
// Discarding a non-existent snippet shouldn't do anything.
service()->DiscardSuggestion(MakeUniqueID("http://othersite.com"));
// Dismissing a non-existent snippet shouldn't do anything.
service()->DismissSuggestion(MakeUniqueID("http://othersite.com"));
EXPECT_THAT(service()->snippets(), SizeIs(1));
// Discard the snippet.
service()->DiscardSuggestion(MakeUniqueID(kSnippetUrl));
// Dismiss the snippet.
service()->DismissSuggestion(MakeUniqueID(kSnippetUrl));
EXPECT_THAT(service()->snippets(), IsEmpty());
// Make sure that fetching the same snippet again does not re-add it.
LoadFromJSONString(json_str);
EXPECT_THAT(service()->snippets(), IsEmpty());
// The snippet should stay discarded even after re-creating the service.
// The snippet should stay dismissed even after re-creating the service.
EXPECT_CALL(mock_scheduler(), Schedule(_, _, _, _)).Times(1);
CreateSnippetsService(/*enabled=*/true);
LoadFromJSONString(json_str);
EXPECT_THAT(service()->snippets(), IsEmpty());
// The snippet can be added again after clearing discarded snippets.
service()->ClearDiscardedSuggestionsForDebugging();
// The snippet can be added again after clearing dismissed snippets.
service()->ClearDismissedSuggestionsForDebugging();
EXPECT_THAT(service()->snippets(), IsEmpty());
LoadFromJSONString(json_str);
EXPECT_THAT(service()->snippets(), SizeIs(1));
}
TEST_F(NTPSnippetsServiceTest, GetDiscarded) {
TEST_F(NTPSnippetsServiceTest, GetDismissed) {
LoadFromJSONString(GetTestJson({GetSnippet()}));
service()->DiscardSuggestion(MakeUniqueID(kSnippetUrl));
const NTPSnippet::PtrVector& snippets = service()->discarded_snippets();
service()->DismissSuggestion(MakeUniqueID(kSnippetUrl));
const NTPSnippet::PtrVector& snippets = service()->dismissed_snippets();
EXPECT_EQ(1u, snippets.size());
for (auto& snippet : snippets) {
EXPECT_EQ(kSnippetUrl, snippet->id());
}
// There should be no discarded snippet after clearing the list.
service()->ClearDiscardedSuggestionsForDebugging();
EXPECT_EQ(0u, service()->discarded_snippets().size());
// There should be no dismissed snippet after clearing the list.
service()->ClearDismissedSuggestionsForDebugging();
EXPECT_EQ(0u, service()->dismissed_snippets().size());
}
TEST_F(NTPSnippetsServiceTest, CreationTimestampParseFail) {
......@@ -815,14 +815,14 @@ TEST_F(NTPSnippetsServiceTest, LogNumArticlesHistogram) {
EXPECT_THAT(
tester.GetAllSamples("NewTabPage.Snippets.NumArticlesZeroDueToDiscarded"),
IsEmpty());
// Discarding a snippet should decrease the list size. This will only be
// Dismissing a snippet should decrease the list size. This will only be
// logged after the next fetch.
service()->DiscardSuggestion(MakeUniqueID(kSnippetUrl));
service()->DismissSuggestion(MakeUniqueID(kSnippetUrl));
LoadFromJSONString(GetTestJson({GetSnippet()}));
EXPECT_THAT(tester.GetAllSamples("NewTabPage.Snippets.NumArticles"),
ElementsAre(base::Bucket(/*min=*/0, /*count=*/3),
base::Bucket(/*min=*/1, /*count=*/2)));
// Discarded snippets shouldn't influence NumArticlesFetched.
// Dismissed snippets shouldn't influence NumArticlesFetched.
EXPECT_THAT(tester.GetAllSamples("NewTabPage.Snippets.NumArticlesFetched"),
ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
base::Bucket(/*min=*/1, /*count=*/3)));
......@@ -836,7 +836,7 @@ TEST_F(NTPSnippetsServiceTest, LogNumArticlesHistogram) {
tester.ExpectTotalCount("NewTabPage.Snippets.NumArticlesFetched", 4);
}
TEST_F(NTPSnippetsServiceTest, DiscardShouldRespectAllKnownUrls) {
TEST_F(NTPSnippetsServiceTest, DismissShouldRespectAllKnownUrls) {
const std::string creation =
NTPSnippet::TimeToJsonString(GetDefaultCreationTime());
const std::string expiry =
......@@ -855,11 +855,11 @@ TEST_F(NTPSnippetsServiceTest, DiscardShouldRespectAllKnownUrls) {
LoadFromJSONString(GetTestJson({GetSnippetWithUrlAndTimesAndSources(
source_urls[0], creation, expiry, source_urls, publishers, amp_urls)}));
ASSERT_THAT(service()->snippets(), SizeIs(1));
// Discard the snippet via the mashable source corpus ID.
service()->DiscardSuggestion(MakeUniqueID(source_urls[0]));
// Dismiss the snippet via the mashable source corpus ID.
service()->DismissSuggestion(MakeUniqueID(source_urls[0]));
EXPECT_THAT(service()->snippets(), IsEmpty());
// The same article from the AOL domain should now be detected as discarded.
// The same article from the AOL domain should now be detected as dismissed.
LoadFromJSONString(GetTestJson({GetSnippetWithUrlAndTimesAndSources(
source_urls[1], creation, expiry, source_urls, publishers, amp_urls)}));
ASSERT_THAT(service()->snippets(), IsEmpty());
......
......@@ -46,10 +46,10 @@ OfflinePageSuggestionsProvider::GetCategoryStatus(
return category_status_;
}
void OfflinePageSuggestionsProvider::DiscardSuggestion(
void OfflinePageSuggestionsProvider::DismissSuggestion(
const std::string& suggestion_id) {
// TODO(pke): Implement some "dont show on NTP anymore" behaviour,
// then also implement ClearDiscardedSuggestionsForDebugging.
// then also implement ClearDismissedSuggestionsForDebugging.
}
void OfflinePageSuggestionsProvider::FetchSuggestionImage(
......@@ -62,8 +62,8 @@ void OfflinePageSuggestionsProvider::ClearCachedSuggestionsForDebugging() {
// Ignored.
}
void OfflinePageSuggestionsProvider::ClearDiscardedSuggestionsForDebugging() {
// TODO(pke): Implement when discarded suggestions are supported.
void OfflinePageSuggestionsProvider::ClearDismissedSuggestionsForDebugging() {
// TODO(pke): Implement when dismissed suggestions are supported.
}
void OfflinePageSuggestionsProvider::OfflinePageModelLoaded(
......
......@@ -43,11 +43,11 @@ class OfflinePageSuggestionsProvider
void SetObserver(ContentSuggestionsProvider::Observer* observer) override;
ContentSuggestionsCategoryStatus GetCategoryStatus(
ContentSuggestionsCategory category) override;
void DiscardSuggestion(const std::string& suggestion_id) override;
void DismissSuggestion(const std::string& suggestion_id) override;
void FetchSuggestionImage(const std::string& suggestion_id,
const ImageFetchedCallback& callback) override;
void ClearCachedSuggestionsForDebugging() override;
void ClearDiscardedSuggestionsForDebugging() override;
void ClearDismissedSuggestionsForDebugging() override;
// OfflinePageModel::Observer implementation.
void OfflinePageModelLoaded(offline_pages::OfflinePageModel* model) override;
......
......@@ -23,7 +23,7 @@ message SnippetProto {
optional int64 expiry_date = 6;
optional float score = 7;
repeated SnippetSourceProto sources = 8;
optional bool discarded = 9;
optional bool dismissed = 9;
}
message SnippetImageProto {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment