Commit e3584d26 authored by vitaliii's avatar vitaliii Committed by Commit Bot

[NTP::Push] Delete obsolete provider.

This is a followup to https://chromium-
review.googlesource.com/c/chromium/src/+/601790. There I delete the
provider code from BUILD.gn as well as its tests, but did not delete the
provider files themselves.

This CL just deletes provider's .h and .cc. I've checked and everything
else seems to be deleted in the previous CL.

AFAIK this code was always behind a feature, which was not enabled in
M61. It was not used (removed from BUILD.gn) in M62.

Bug: 770059
Change-Id: I07939d75157200c0dbe0374bc18d36f4de4f7e49
Reviewed-on: https://chromium-review.googlesource.com/691657Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: vitaliii <vitaliii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505328}
parent d5830561
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/ntp_snippets/breaking_news/breaking_news_suggestions_provider.h"
#include "base/bind.h"
#include "base/time/clock.h"
#include "components/ntp_snippets/breaking_news/breaking_news_listener.h"
#include "components/ntp_snippets/category.h"
#include "components/ntp_snippets/pref_names.h"
#include "components/ntp_snippets/remote/json_to_categories.h"
#include "components/strings/grit/components_strings.h"
namespace ntp_snippets {
BreakingNewsSuggestionsProvider::BreakingNewsSuggestionsProvider(
ContentSuggestionsProvider::Observer* observer,
std::unique_ptr<BreakingNewsListener> breaking_news_raw_data_provider,
std::unique_ptr<base::Clock> clock,
std::unique_ptr<RemoteSuggestionsDatabase> database)
: ContentSuggestionsProvider(observer),
breaking_news_raw_data_provider_(
std::move(breaking_news_raw_data_provider)),
clock_(std::move(clock)),
database_(std::move(database)),
provided_category_(
Category::FromKnownCategory(KnownCategories::BREAKING_NEWS)),
category_status_(CategoryStatus::INITIALIZING) {
database_->SetErrorCallback(
base::Bind(&BreakingNewsSuggestionsProvider::OnDatabaseError,
base::Unretained(this)));
database_->LoadSnippets(
base::Bind(&BreakingNewsSuggestionsProvider::OnDatabaseLoaded,
base::Unretained(this)));
// Unretained because |this| owns |breaking_news_listener_|.
breaking_news_raw_data_provider_->StartListening(
base::Bind(&BreakingNewsSuggestionsProvider::OnNewRemoteSuggestion,
base::Unretained(this)));
}
BreakingNewsSuggestionsProvider::~BreakingNewsSuggestionsProvider() {
breaking_news_raw_data_provider_->StopListening();
}
void BreakingNewsSuggestionsProvider::OnNewRemoteSuggestion(
std::unique_ptr<RemoteSuggestion> remote_suggestion) {
std::vector<std::unique_ptr<RemoteSuggestion>> suggestions;
suggestions.push_back(std::move(remote_suggestion));
if (database_->IsInitialized()) {
database_->SaveSnippets(suggestions);
} else {
// TODO(mamir): Check how often a breaking news is received before DB is
// initialized.
LOG(WARNING) << "Cannot store breaking news, database is not initialized.";
}
NotifyNewSuggestions(std::move(suggestions));
}
////////////////////////////////////////////////////////////////////////////////
// Private methods
CategoryStatus BreakingNewsSuggestionsProvider::GetCategoryStatus(
Category category) {
DCHECK_EQ(category, provided_category_);
return category_status_;
}
CategoryInfo BreakingNewsSuggestionsProvider::GetCategoryInfo(
Category category) {
// TODO(mamir): needs to be corrected, just a placeholer
return CategoryInfo(base::string16(),
ContentSuggestionsCardLayout::MINIMAL_CARD,
ContentSuggestionsAdditionalAction::VIEW_ALL,
/*show_if_empty=*/false, base::string16());
}
void BreakingNewsSuggestionsProvider::DismissSuggestion(
const ContentSuggestion::ID& suggestion_id) {
// TODO(mamir): implement.
}
void BreakingNewsSuggestionsProvider::FetchSuggestionImage(
const ContentSuggestion::ID& suggestion_id,
ImageFetchedCallback callback) {
// TODO(mamir): implement.
}
void BreakingNewsSuggestionsProvider::Fetch(
const Category& category,
const std::set<std::string>& known_suggestion_ids,
FetchDoneCallback callback) {
// TODO(jkrcal): Make Fetch method optional.
}
void BreakingNewsSuggestionsProvider::ClearHistory(
base::Time begin,
base::Time end,
const base::Callback<bool(const GURL& url)>& filter) {
observer()->OnNewSuggestions(this, provided_category_,
std::vector<ContentSuggestion>());
}
void BreakingNewsSuggestionsProvider::ClearCachedSuggestions(
Category category) {
DCHECK_EQ(category, provided_category_);
// TODO(mamir): clear the cached suggestions.
}
void BreakingNewsSuggestionsProvider::GetDismissedSuggestionsForDebugging(
Category category,
DismissedSuggestionsCallback callback) {
// TODO(mamir): implement.
}
void BreakingNewsSuggestionsProvider::ClearDismissedSuggestionsForDebugging(
Category category) {
// TODO(mamir): implement.
}
void BreakingNewsSuggestionsProvider::OnDatabaseLoaded(
std::vector<std::unique_ptr<RemoteSuggestion>> suggestions) {
// TODO(mamir): check and update DB status.
NotifyNewSuggestions(std::move(suggestions));
}
void BreakingNewsSuggestionsProvider::OnDatabaseError() {
// TODO(mamir): implement.
}
void BreakingNewsSuggestionsProvider::NotifyNewSuggestions(
std::vector<std::unique_ptr<RemoteSuggestion>> suggestions) {
std::vector<ContentSuggestion> result;
for (const std::unique_ptr<RemoteSuggestion>& suggestion : suggestions) {
result.emplace_back(suggestion->ToContentSuggestion(provided_category_));
}
DVLOG(1) << "NotifyNewSuggestions(): " << result.size()
<< " items in category " << provided_category_;
observer()->OnNewSuggestions(this, provided_category_, std::move(result));
}
} // namespace ntp_snippets
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_BREAKING_NEWS_SUGGESTIONS_PROVIDER_H_
#define COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_BREAKING_NEWS_SUGGESTIONS_PROVIDER_H_
#include "components/ntp_snippets/category.h"
#include "components/ntp_snippets/content_suggestions_provider.h"
#include "components/ntp_snippets/remote/json_to_categories.h"
#include "components/ntp_snippets/remote/remote_suggestions_database.h"
#include "components/prefs/pref_registry_simple.h"
namespace ntp_snippets {
class BreakingNewsListener;
}
namespace base {
class Clock;
}
namespace ntp_snippets {
// Receives breaking news suggestions asynchronously via BreakingNewsListener,
// stores them and provides them as content suggestions.
// This class is final because it does things in its constructor which make it
// unsafe to derive from it.
class BreakingNewsSuggestionsProvider final
: public ContentSuggestionsProvider {
public:
BreakingNewsSuggestionsProvider(
ContentSuggestionsProvider::Observer* observer,
std::unique_ptr<BreakingNewsListener> breaking_news_raw_data_provider,
std::unique_ptr<base::Clock> clock,
std::unique_ptr<RemoteSuggestionsDatabase> database);
~BreakingNewsSuggestionsProvider() override;
// ContentSuggestionsProvider implementation.
CategoryStatus GetCategoryStatus(Category category) override;
CategoryInfo GetCategoryInfo(Category category) override;
void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
ImageFetchedCallback callback) override;
void Fetch(const Category& category,
const std::set<std::string>& known_suggestion_ids,
FetchDoneCallback callback) override;
void ClearHistory(
base::Time begin,
base::Time end,
const base::Callback<bool(const GURL& url)>& filter) override;
void ClearCachedSuggestions(Category category) override;
void GetDismissedSuggestionsForDebugging(
Category category,
DismissedSuggestionsCallback callback) override;
void ClearDismissedSuggestionsForDebugging(Category category) override;
private:
// Callback called from the breaking news listener when new content has been
// pushed from the server.
void OnNewRemoteSuggestion(
std::unique_ptr<RemoteSuggestion> remote_suggestion);
// Callbacks for the RemoteSuggestionsDatabase.
void OnDatabaseLoaded(
std::vector<std::unique_ptr<RemoteSuggestion>> suggestions);
void OnDatabaseError();
void NotifyNewSuggestions(
std::vector<std::unique_ptr<RemoteSuggestion>> suggestions);
std::unique_ptr<BreakingNewsListener> breaking_news_raw_data_provider_;
std::unique_ptr<base::Clock> clock_;
// The database for persisting suggestions.
std::unique_ptr<RemoteSuggestionsDatabase> database_;
const Category provided_category_;
CategoryStatus category_status_;
DISALLOW_COPY_AND_ASSIGN(BreakingNewsSuggestionsProvider);
};
} // namespace ntp_snippets
#endif // COMPONENTS_NTP_SNIPPETS_BREAKING_NEWS_BREAKING_NEWS_SUGGESTIONS_PROVIDER_H_
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