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

Unified Diff: components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc

Issue 2205233002: Combine all suggestions factories into ContentSuggestionsServiceFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bernhard's comments Created 4 years, 4 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
« no previous file with comments | « components/ntp_snippets/offline_pages/offline_page_suggestions_provider.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc
diff --git a/components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc b/components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc
index d6cfe9ee00ee0a9321a9817949da3a3c43f4a89f..d2380c8677267a65e76a71518ba5cc167c0ac8ec 100644
--- a/components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc
+++ b/components/ntp_snippets/offline_pages/offline_page_suggestions_provider.cc
@@ -21,23 +21,20 @@ const int kMaxSuggestionsCount = 5;
} // namespace
OfflinePageSuggestionsProvider::OfflinePageSuggestionsProvider(
+ ContentSuggestionsProvider::Observer* observer,
CategoryFactory* category_factory,
OfflinePageModel* offline_page_model)
- : ContentSuggestionsProvider(category_factory),
+ : ContentSuggestionsProvider(observer, category_factory),
category_status_(CategoryStatus::AVAILABLE_LOADING),
- observer_(nullptr),
offline_page_model_(offline_page_model),
provided_category_(
category_factory->FromKnownCategory(KnownCategories::OFFLINE_PAGES)) {
offline_page_model_->AddObserver(this);
+ FetchOfflinePages();
}
-OfflinePageSuggestionsProvider::~OfflinePageSuggestionsProvider() {}
-
-// Inherited from KeyedService.
-void OfflinePageSuggestionsProvider::Shutdown() {
+OfflinePageSuggestionsProvider::~OfflinePageSuggestionsProvider() {
offline_page_model_->RemoveObserver(this);
- category_status_ = CategoryStatus::NOT_PROVIDED;
}
////////////////////////////////////////////////////////////////////////////////
@@ -47,13 +44,6 @@ std::vector<Category> OfflinePageSuggestionsProvider::GetProvidedCategories() {
return std::vector<Category>({provided_category_});
}
-void OfflinePageSuggestionsProvider::SetObserver(
- ContentSuggestionsProvider::Observer* observer) {
- observer_ = observer;
- if (observer)
- FetchOfflinePages();
-}
-
CategoryStatus OfflinePageSuggestionsProvider::GetCategoryStatus(
Category category) {
return category_status_;
@@ -105,8 +95,6 @@ void OfflinePageSuggestionsProvider::FetchOfflinePages() {
void OfflinePageSuggestionsProvider::OnOfflinePagesLoaded(
const MultipleOfflinePageItemResult& result) {
NotifyStatusChanged(CategoryStatus::AVAILABLE);
- if (!observer_)
- return;
std::vector<ContentSuggestion> suggestions;
for (const OfflinePageItem& item : result) {
@@ -129,7 +117,8 @@ void OfflinePageSuggestionsProvider::OnOfflinePagesLoaded(
break;
}
- observer_->OnNewSuggestions(this, provided_category_, std::move(suggestions));
+ observer()->OnNewSuggestions(this, provided_category_,
+ std::move(suggestions));
}
void OfflinePageSuggestionsProvider::NotifyStatusChanged(
@@ -138,9 +127,7 @@ void OfflinePageSuggestionsProvider::NotifyStatusChanged(
return;
category_status_ = new_status;
- if (!observer_)
- return;
- observer_->OnCategoryStatusChanged(this, provided_category_, new_status);
+ observer()->OnCategoryStatusChanged(this, provided_category_, new_status);
}
} // namespace ntp_snippets
« no previous file with comments | « components/ntp_snippets/offline_pages/offline_page_suggestions_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698