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

Unified Diff: components/ntp_snippets/ntp_snippets_service.h

Issue 2061803002: 📰 The Status card reports disabled sync states (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplifyBridge
Patch Set: fix compilation: origins 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.h
diff --git a/components/ntp_snippets/ntp_snippets_service.h b/components/ntp_snippets/ntp_snippets_service.h
index fad27ab7e665d649fbdd8dccb2234d728026a086..1ce509c5a38536fbea7282f2236805ec1eb94186 100644
--- a/components/ntp_snippets/ntp_snippets_service.h
+++ b/components/ntp_snippets/ntp_snippets_service.h
@@ -26,6 +26,7 @@
class PrefRegistrySimple;
class PrefService;
+class SigninManagerBase;
namespace base {
class Value;
@@ -49,11 +50,19 @@ class SyncService;
namespace ntp_snippets {
-enum class DisabledReason {
+// A Java counterpart will be generated for this enum.
+// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.ntp.snippets
+enum class DisabledReason : int {
// Snippets are enabled
NONE,
// Snippets have been disabled as part of the service configuration.
EXPLICITLY_DISABLED,
+ // The user is not signed in, and the service requires it to be enabled.
+ SIGNED_OUT,
+ // Sync is not enabled, and the service requires it to be enabled.
+ SYNC_DISABLED,
+ // The service requires passphrase encryption to be disabled.
+ PASSPHRASE_ENCRYPTION_ENABLED,
// History sync is not enabled, and the service requires it to be enabled.
HISTORY_SYNC_DISABLED,
// The sync service is not completely initialized, and the status is unknown.
@@ -76,6 +85,7 @@ class NTPSnippetsService : public KeyedService,
// (British English person in the US) are not language codes.
NTPSnippetsService(bool enabled,
PrefService* pref_service,
+ SigninManagerBase* signin_manager,
sync_driver::SyncService* sync_service,
suggestions::SuggestionsService* suggestions_service,
const std::string& application_language_code,
@@ -120,6 +130,10 @@ class NTPSnippetsService : public KeyedService,
return snippets_fetcher_.get();
}
+ // Returns a reason why the service is disabled, or DisabledReason::NONE
+ // if it's not.
+ DisabledReason disabled_reason() const { return disabled_reason_; }
+
// (Re)schedules the periodic fetching of snippets. This is necessary because
// the schedule depends on the time of day.
void RescheduleFetching();
@@ -147,10 +161,6 @@ class NTPSnippetsService : public KeyedService,
void AddObserver(NTPSnippetsServiceObserver* observer);
void RemoveObserver(NTPSnippetsServiceObserver* observer);
- // Returns a reason why the service could be disabled, or DisabledReason::NONE
- // if it's not.
- DisabledReason GetDisabledReason() const;
-
// Returns the maximum number of snippets that will be shown at once.
static int GetMaxSnippetCountForTesting();
@@ -222,6 +232,14 @@ class NTPSnippetsService : public KeyedService,
void LoadingSnippetsFinished();
+ // Updates |disabled_reason_| (see |GetNewDisabledReason()|) and notifies
+ // observers of changes if necessary.
+ void UpdateDisabledReason();
+
+ // Utility method that looks at the state of the service and its dependencies
+ // to determine if and why it should be disabled.
+ DisabledReason GetNewDisabledReason() const;
+
// Returns whether the service should be enabled or disable depending on its
// internal state and the state of its dependencies.
State GetStateForDependenciesStatus();
@@ -245,13 +263,12 @@ class NTPSnippetsService : public KeyedService,
State state_;
- // The service was set up to be disabled and should not be enabled by any
- // state change. We track this to make sure we clear scheduled tasks, which
- // persist even when Chrome is stopped.
- bool explicitly_disabled_;
+ DisabledReason disabled_reason_;
PrefService* pref_service_;
+ SigninManagerBase* signin_manager_;
+
sync_driver::SyncService* sync_service_;
// The observer for the SyncService. When the sync state changes,
@@ -309,9 +326,10 @@ class NTPSnippetsServiceObserver {
virtual void NTPSnippetsServiceLoaded() = 0;
// Sent when the service is shutting down.
virtual void NTPSnippetsServiceShutdown() = 0;
- // Sent when the service has been disabled. Can be from explicit user action
- // or because a requirement (e.g. History Sync) is not fulfilled anymore.
- virtual void NTPSnippetsServiceDisabled() = 0;
+ // Sent when the state of the service is changing. Something changed in its
+ // dependencies so it's notifying observers about incoming data changes.
+ // If the service might be enabled, DisabledReason::NONE will be provided.
+ virtual void NTPSnippetsServiceDisabledReasonChanged(DisabledReason) = 0;
protected:
virtual ~NTPSnippetsServiceObserver() {}

Powered by Google App Engine
This is Rietveld 408576698