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

Unified Diff: components/ntp_snippets/ntp_snippets_service.cc

Issue 2083533002: [NTP Snippets] Shut down the service on database failure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@image_db_tests
Patch Set: comments Created 4 years, 6 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
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 bf55467f307a661ea0b5c57667e600a0080cc465..48b3f0b11128729b6bde2273f06ad6b2b9e3d658 100644
--- a/components/ntp_snippets/ntp_snippets_service.cc
+++ b/components/ntp_snippets/ntp_snippets_service.cc
@@ -203,7 +203,7 @@ NTPSnippetsService::NTPSnippetsService(
image_decoder_(std::move(image_decoder)),
database_(std::move(database)),
fetch_after_load_(false) {
- // TODO(dgn) should be removed after branch point (https:://crbug.com/617585).
+ // TODO(dgn) should be removed after branch point (https://crbug.com/617585).
ClearDeprecatedPrefs();
if (explicitly_disabled_) {
@@ -211,6 +211,14 @@ NTPSnippetsService::NTPSnippetsService(
return;
}
+ if (database_->IsErrorState()) {
+ EnterState(State::SHUT_DOWN);
+ return;
+ }
+
+ database_->SetErrorCallback(base::Bind(&NTPSnippetsService::OnDatabaseError,
+ base::Unretained(this)));
+
// We transition to other states while finalizing the initialization, when the
// database is done loading.
database_->LoadSnippets(base::Bind(&NTPSnippetsService::OnDatabaseLoaded,
@@ -325,6 +333,9 @@ void NTPSnippetsService::ClearDiscardedSnippets() {
if (!initialized())
return;
+ if (discarded_snippets_.empty())
+ return;
+
database_->DeleteSnippets(discarded_snippets_);
discarded_snippets_.clear();
}
@@ -422,6 +433,10 @@ void NTPSnippetsService::OnDatabaseLoaded(NTPSnippet::PtrVector snippets) {
FinishInitialization();
}
+void NTPSnippetsService::OnDatabaseError() {
+ EnterState(State::SHUT_DOWN);
+}
+
void NTPSnippetsService::OnSuggestionsChanged(
const SuggestionsProfile& suggestions) {
DCHECK(initialized());

Powered by Google App Engine
This is Rietveld 408576698