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

Unified Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 2190353002: 📰Fix SnippetsService's status reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusListItem.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a2cf72c8713c9943f2b19b92e1ee1fe5a8e6b008..ff447c08ba4c31e589d26876ba7cc0d2ccc7391e 100644
--- a/components/ntp_snippets/ntp_snippets_service.cc
+++ b/components/ntp_snippets/ntp_snippets_service.cc
@@ -259,6 +259,8 @@ void NTPSnippetsService::FetchSnippetsFromHosts(
bool force_request) {
if (!ready())
return;
+ LOG(INFO) << "DGN - Initiating fetch";
+ EnterState(state_, ContentSuggestionsCategoryStatus::AVAILABLE_LOADING);
Marc Treib 2016/07/29 10:19:47 I don't think this is right. AVAILABLE_LOADING is
dgn 2016/07/29 10:42:48 Ah ok I didn't understand AVAILABLE_LOADING proper
Marc Treib 2016/07/29 10:45:46 Also while we're waiting for results from the DB (
dgn 2016/07/29 16:37:46 What about when the service was disabled, so we cl
Marc Treib 2016/08/01 09:03:31 Yes, that sounds right.
snippets_fetcher_->FetchSnippetsFromHosts(hosts, application_language_code_,
kMaxSnippetCount, force_request);
}
@@ -416,6 +418,8 @@ void NTPSnippetsService::OnDatabaseError() {
EnterState(State::SHUT_DOWN, ContentSuggestionsCategoryStatus::LOADING_ERROR);
}
+// TODO(dgn): name clash between content suggestions and suggestions hosts.
+// method name should be changed.
void NTPSnippetsService::OnSuggestionsChanged(
const SuggestionsProfile& suggestions) {
DCHECK(initialized());
@@ -439,6 +443,7 @@ void NTPSnippetsService::OnSuggestionsChanged(
StoreSnippetHostsToPrefs(hosts);
+ // TODO(dgn) Why do we do that BEFORE fetching?
NotifyNewSuggestions();
dgn 2016/07/29 09:58:36 Why do we do that BEFORE fetching?
Marc Treib 2016/07/29 10:19:47 We potentially deleted some snippets above, so we
dgn 2016/07/29 10:42:48 Wouldn't they be notified of the new list when the
Marc Treib 2016/07/29 10:45:46 True, but that might take any amount of time, and
dgn 2016/07/29 16:37:46 Added a comment about this.
FetchSnippetsFromHosts(hosts, /*force_request=*/false);
@@ -705,6 +710,15 @@ void NTPSnippetsService::FinishInitialization() {
snippets_status_service_->Init(base::Bind(
&NTPSnippetsService::OnDisabledReasonChanged, base::Unretained(this)));
+ // TODO(dgn): If we started a fetch as a result of the state being updated
+ // and not having snippets from the DB, because of the call below we would
+ // still notify the client with no snippets and force the "AVAILABLE" status.
+ // WAI?
+ // IMO that seems wrong. Skipping this call will put us either:
+ // - in AVAILABLE_LOADING: because of the pending fetch started above.
+ // - in INITIALIZING status: If it's right on startup and because we don't
+ // have sync data, the fetch can't start. We appropriately report that we
+ // are still initializing.
NotifyNewSuggestions();
dgn 2016/07/29 09:58:36 If we started a fetch as a result of the state bei
Marc Treib 2016/07/29 10:19:47 I guess this is here because we "probably" loaded
dgn 2016/07/29 10:42:48 So the intent is that while a fetch is pending and
Marc Treib 2016/07/29 10:45:46 I think so, yes. We should also be in _LOADING if
}
@@ -714,9 +728,13 @@ void NTPSnippetsService::OnDisabledReasonChanged(
NTPSnippetsServiceDisabledReasonChanged(disabled_reason));
switch (disabled_reason) {
- case DisabledReason::NONE:
- EnterState(State::READY, ContentSuggestionsCategoryStatus::AVAILABLE);
+ case DisabledReason::NONE: {
+ // Do not change the status. As the service becomes enabled, it will
+ // either start a new fetch (and transition to |AVAILABLE_LOADING|), or
+ // send cached suggestions (and transition to |AVAILABLE|).
+ EnterState(State::READY, category_status_);
break;
+ }
case DisabledReason::HISTORY_SYNC_STATE_UNKNOWN:
// HistorySync is not initialized yet, so we don't know what the actual
@@ -757,6 +775,8 @@ void NTPSnippetsService::OnDisabledReasonChanged(
void NTPSnippetsService::EnterState(State state,
ContentSuggestionsCategoryStatus status) {
+ LOG(INFO) << "DGN - EnterState(" << (int)state << ", " << (int)status << ")";
+
if (status != category_status_) {
category_status_ = status;
NotifyCategoryStatusChanged();
@@ -799,6 +819,8 @@ void NTPSnippetsService::EnterState(State state,
}
void NTPSnippetsService::NotifyNewSuggestions() {
+ EnterState(state_, ContentSuggestionsCategoryStatus::AVAILABLE);
Marc Treib 2016/07/29 10:19:47 Huh, seems like we should already be in this state
+
// TODO(pke): Remove this as soon as this becomes a pure provider.
FOR_EACH_OBSERVER(NTPSnippetsServiceObserver, observers_,
NTPSnippetsServiceLoaded());
@@ -826,6 +848,7 @@ void NTPSnippetsService::NotifyNewSuggestions() {
}
void NTPSnippetsService::NotifyCategoryStatusChanged() {
+ LOG(INFO) << "DGN - NotifyCategoryStatusChanged " << (int)category_status_;
if (observer_) {
observer_->OnCategoryStatusChanged(ContentSuggestionsCategory::ARTICLES,
category_status_);
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/StatusListItem.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698