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

Unified Diff: components/ntp_snippets/content_suggestions_service.cc

Issue 2520853002: [NTP] Cleanup: add brackets in components/ntp_snippets. [2/2] (Closed)
Patch Set: "else if". Created 4 years, 1 month 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/category_factory.cc ('k') | components/ntp_snippets/features.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ntp_snippets/content_suggestions_service.cc
diff --git a/components/ntp_snippets/content_suggestions_service.cc b/components/ntp_snippets/content_suggestions_service.cc
index 42890a7e6afb4d416fbc15452641a2b84d81cce1..3a55707b6af3f815b8641546d0ee7e917d966389 100644
--- a/components/ntp_snippets/content_suggestions_service.cc
+++ b/components/ntp_snippets/content_suggestions_service.cc
@@ -31,8 +31,9 @@ ContentSuggestionsService::ContentSuggestionsService(
pref_service_(pref_service),
user_classifier_(pref_service) {
// Can be null in tests.
- if (history_service)
+ if (history_service) {
history_service_observer_.Add(history_service);
+ }
RestoreDismissedCategoriesFromPrefs();
}
@@ -46,8 +47,9 @@ void ContentSuggestionsService::Shutdown() {
categories_.clear();
providers_.clear();
state_ = State::DISABLED;
- for (Observer& observer : observers_)
+ for (Observer& observer : observers_) {
observer.ContentSuggestionsServiceShutdown();
+ }
}
// static
@@ -63,8 +65,9 @@ CategoryStatus ContentSuggestionsService::GetCategoryStatus(
}
auto iterator = providers_by_category_.find(category);
- if (iterator == providers_by_category_.end())
+ if (iterator == providers_by_category_.end()) {
return CategoryStatus::NOT_PROVIDED;
+ }
return iterator->second->GetCategoryStatus(category);
}
@@ -72,16 +75,18 @@ CategoryStatus ContentSuggestionsService::GetCategoryStatus(
base::Optional<CategoryInfo> ContentSuggestionsService::GetCategoryInfo(
Category category) const {
auto iterator = providers_by_category_.find(category);
- if (iterator == providers_by_category_.end())
+ if (iterator == providers_by_category_.end()) {
return base::Optional<CategoryInfo>();
+ }
return iterator->second->GetCategoryInfo(category);
}
const std::vector<ContentSuggestion>&
ContentSuggestionsService::GetSuggestionsForCategory(Category category) const {
auto iterator = suggestions_by_category_.find(category);
- if (iterator == suggestions_by_category_.end())
+ if (iterator == suggestions_by_category_.end()) {
return no_suggestions_;
+ }
return iterator->second;
}
@@ -113,33 +118,37 @@ void ContentSuggestionsService::ClearAllCachedSuggestions() {
for (const auto& category_provider_pair : providers_by_category_) {
category_provider_pair.second->ClearCachedSuggestions(
category_provider_pair.first);
- for (Observer& observer : observers_)
+ for (Observer& observer : observers_) {
observer.OnNewSuggestions(category_provider_pair.first);
+ }
}
}
void ContentSuggestionsService::ClearCachedSuggestions(Category category) {
suggestions_by_category_[category].clear();
auto iterator = providers_by_category_.find(category);
- if (iterator != providers_by_category_.end())
+ if (iterator != providers_by_category_.end()) {
iterator->second->ClearCachedSuggestions(category);
+ }
}
void ContentSuggestionsService::GetDismissedSuggestionsForDebugging(
Category category,
const DismissedSuggestionsCallback& callback) {
auto iterator = providers_by_category_.find(category);
- if (iterator != providers_by_category_.end())
+ if (iterator != providers_by_category_.end()) {
iterator->second->GetDismissedSuggestionsForDebugging(category, callback);
- else
+ } else {
callback.Run(std::vector<ContentSuggestion>());
+ }
}
void ContentSuggestionsService::ClearDismissedSuggestionsForDebugging(
Category category) {
auto iterator = providers_by_category_.find(category);
- if (iterator != providers_by_category_.end())
+ if (iterator != providers_by_category_.end()) {
iterator->second->ClearDismissedSuggestionsForDebugging(category);
+ }
}
void ContentSuggestionsService::DismissSuggestion(
@@ -161,8 +170,9 @@ void ContentSuggestionsService::DismissSuggestion(
void ContentSuggestionsService::DismissCategory(Category category) {
auto providers_it = providers_by_category_.find(category);
- if (providers_it == providers_by_category_.end())
+ if (providers_it == providers_by_category_.end()) {
return;
+ }
ContentSuggestionsProvider* provider = providers_it->second;
UnregisterCategory(category, provider);
@@ -201,8 +211,9 @@ void ContentSuggestionsService::Fetch(
const std::set<std::string>& known_suggestion_ids,
const FetchDoneCallback& callback) {
auto providers_it = providers_by_category_.find(category);
- if (providers_it == providers_by_category_.end())
+ if (providers_it == providers_by_category_.end()) {
return;
+ }
providers_it->second->Fetch(category, known_suggestion_ids, callback);
}
@@ -223,8 +234,9 @@ void ContentSuggestionsService::OnNewSuggestions(
} else if (IsCategoryDismissed(category)) {
// The category has been registered as a dismissed one. We need to
// check if the dismissal can be cleared now that we received new data.
- if (suggestions.empty())
+ if (suggestions.empty()) {
return;
+ }
RestoreDismissedCategory(category);
StoreDismissedCategoriesToPrefs();
@@ -240,8 +252,9 @@ void ContentSuggestionsService::OnNewSuggestions(
suggestions_by_category_[category] = std::move(suggestions);
- for (Observer& observer : observers_)
+ for (Observer& observer : observers_) {
observer.OnNewSuggestions(category);
+ }
}
void ContentSuggestionsService::OnCategoryStatusChanged(
@@ -251,22 +264,25 @@ void ContentSuggestionsService::OnCategoryStatusChanged(
if (new_status == CategoryStatus::NOT_PROVIDED) {
UnregisterCategory(category, provider);
} else {
- if (!IsCategoryStatusAvailable(new_status))
+ if (!IsCategoryStatusAvailable(new_status)) {
suggestions_by_category_.erase(category);
+ }
TryRegisterProviderForCategory(provider, category);
DCHECK_EQ(new_status, provider->GetCategoryStatus(category));
}
- if (!IsCategoryDismissed(category))
+ if (!IsCategoryDismissed(category)) {
NotifyCategoryStatusChanged(category);
+ }
}
void ContentSuggestionsService::OnSuggestionInvalidated(
ContentSuggestionsProvider* provider,
const ContentSuggestion::ID& suggestion_id) {
RemoveSuggestionByID(suggestion_id);
- for (Observer& observer : observers_)
+ for (Observer& observer : observers_) {
observer.OnSuggestionInvalidated(suggestion_id);
+ }
}
// history::HistoryServiceObserver implementation.
@@ -277,8 +293,9 @@ void ContentSuggestionsService::OnURLsDeleted(
const history::URLRows& deleted_rows,
const std::set<GURL>& favicon_urls) {
// We don't care about expired entries.
- if (expired)
+ if (expired) {
return;
+ }
// Redirect to ClearHistory().
if (all_history) {
@@ -288,17 +305,20 @@ void ContentSuggestionsService::OnURLsDeleted(
base::Bind([](const GURL& url) { return true; });
ClearHistory(begin, end, filter);
} else {
- if (deleted_rows.empty())
+ if (deleted_rows.empty()) {
return;
+ }
base::Time begin = deleted_rows[0].last_visit();
base::Time end = deleted_rows[0].last_visit();
std::set<GURL> deleted_urls;
for (const history::URLRow& row : deleted_rows) {
- if (row.last_visit() < begin)
+ if (row.last_visit() < begin) {
begin = row.last_visit();
- if (row.last_visit() > end)
+ }
+ if (row.last_visit() > end) {
end = row.last_visit();
+ }
deleted_urls.insert(row.url());
}
base::Callback<bool(const GURL& url)> filter = base::Bind(
@@ -381,16 +401,18 @@ bool ContentSuggestionsService::RemoveSuggestionByID(
[&suggestion_id](const ContentSuggestion& suggestion) {
return suggestion_id == suggestion.id();
});
- if (position == suggestions->end())
+ if (position == suggestions->end()) {
return false;
+ }
suggestions->erase(position);
return true;
}
void ContentSuggestionsService::NotifyCategoryStatusChanged(Category category) {
- for (Observer& observer : observers_)
+ for (Observer& observer : observers_) {
observer.OnCategoryStatusChanged(category, GetCategoryStatus(category));
+ }
}
void ContentSuggestionsService::SortCategories() {
@@ -413,8 +435,9 @@ void ContentSuggestionsService::RestoreDismissedCategory(Category category) {
ContentSuggestionsProvider* provider = dismissed_it->second;
dismissed_providers_by_category_.erase(dismissed_it);
- if (provider)
+ if (provider) {
RegisterCategory(category, provider);
+ }
}
void ContentSuggestionsService::RestoreDismissedCategoriesFromPrefs() {
« no previous file with comments | « components/ntp_snippets/category_factory.cc ('k') | components/ntp_snippets/features.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698