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

Unified Diff: components/ntp_snippets/ntp_snippets_status_service.h

Issue 2061803002: 📰 The Status card reports disabled sync states (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplifyBridge
Patch Set: yolo: another big bag of changes 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_status_service.h
diff --git a/components/ntp_snippets/ntp_snippets_status_service.h b/components/ntp_snippets/ntp_snippets_status_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..b5a73eea1c1deaec2c60cc911d690cc0f3b7a45e
--- /dev/null
+++ b/components/ntp_snippets/ntp_snippets_status_service.h
@@ -0,0 +1,82 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_
+#define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_
+
+#include "base/callback.h"
+#include "base/gtest_prod_util.h"
+#include "base/scoped_observer.h"
+#include "components/sync_driver/sync_service_observer.h"
+
+class SigninManagerBase;
+
+namespace sync_driver {
+class SyncService;
+}
+
+namespace ntp_snippets {
+
+// On Android builds, 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.
+ HISTORY_SYNC_STATE_UNKNOWN
+};
+
+// Aggregates data from sync and signin to notify the snippet service of
+// relevant changes in their states.
+class NTPSnippetsStatusService : public sync_driver::SyncServiceObserver {
+ public:
+ typedef base::Callback<void(DisabledReason)> DisabledReasonChangeCallback;
+
+ NTPSnippetsStatusService(SigninManagerBase* signin_manager,
+ sync_driver::SyncService* sync_service);
+
+ ~NTPSnippetsStatusService() override;
+
+ // Starts listening for changes from the dependencies. |callback| will be
+ // called when a significant change in state is detected.
+ void Init(const DisabledReasonChangeCallback& callback);
+
+ DisabledReason disabled_reason() const { return disabled_reason_; }
+
+ private:
+ FRIEND_TEST_ALL_PREFIXES(NTPSnippetsStatusServiceTest,
+ SyncStateCompatibility);
+
+ // sync_driver::SyncServiceObserver implementation
+ void OnStateChanged() override;
+
+ DisabledReason GetDisabledReasonFromDeps() const;
+
+ DisabledReason disabled_reason_;
+ DisabledReasonChangeCallback disabled_reason_change_callback_;
+
+ SigninManagerBase* signin_manager_;
+ sync_driver::SyncService* sync_service_;
+
+ // The observer for the SyncService. When the sync state changes,
+ // SyncService will call |OnStateChanged|.
+ ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver>
+ sync_service_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(NTPSnippetsStatusService);
+};
+
+} // namespace ntp_snippets
+
+#endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_STATUS_SERVICE_H_
« no previous file with comments | « components/ntp_snippets/ntp_snippets_service_unittest.cc ('k') | components/ntp_snippets/ntp_snippets_status_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698