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

Unified Diff: components/ntp_snippets/ntp_snippets_status_service.cc

Issue 2158373002: [NTP Snippets] Add a pref to disable the NTPSnippetsService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
Index: components/ntp_snippets/ntp_snippets_status_service.cc
diff --git a/components/ntp_snippets/ntp_snippets_status_service.cc b/components/ntp_snippets/ntp_snippets_status_service.cc
index 5c279991b1ebb34975ac2d27fd65f4a6e0ad0f53..6adcd350e42a7999e8e1dc1f2c4a390f1b0ce1c0 100644
--- a/components/ntp_snippets/ntp_snippets_status_service.cc
+++ b/components/ntp_snippets/ntp_snippets_status_service.cc
@@ -3,6 +3,10 @@
// found in the LICENSE file.
#include "components/ntp_snippets/ntp_snippets_status_service.h"
+
+#include "components/ntp_snippets/pref_names.h"
+#include "components/prefs/pref_registry_simple.h"
+#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync_driver/sync_service.h"
@@ -10,14 +14,22 @@ namespace ntp_snippets {
NTPSnippetsStatusService::NTPSnippetsStatusService(
SigninManagerBase* signin_manager,
- sync_driver::SyncService* sync_service)
+ sync_driver::SyncService* sync_service,
+ PrefService* pref_service)
: disabled_reason_(DisabledReason::EXPLICITLY_DISABLED),
signin_manager_(signin_manager),
sync_service_(sync_service),
+ pref_service_(pref_service),
sync_service_observer_(this) {}
NTPSnippetsStatusService::~NTPSnippetsStatusService() {}
+// static
+void NTPSnippetsStatusService::RegisterProfilePrefs(
+ PrefRegistrySimple* registry) {
+ registry->RegisterBooleanPref(prefs::kDisableSnippets, false);
+}
+
void NTPSnippetsStatusService::Init(
const DisabledReasonChangeCallback& callback) {
DCHECK(disabled_reason_change_callback_.is_null());
@@ -30,6 +42,12 @@ void NTPSnippetsStatusService::Init(
disabled_reason_change_callback_.Run(disabled_reason_);
sync_service_observer_.Add(sync_service_);
+
+ pref_change_registrar_.Init(pref_service_);
+ pref_change_registrar_.Add(
+ prefs::kDisableSnippets,
+ base::Bind(&NTPSnippetsStatusService::OnStateChanged,
+ base::Unretained(this)));
}
void NTPSnippetsStatusService::OnStateChanged() {
@@ -43,6 +61,11 @@ void NTPSnippetsStatusService::OnStateChanged() {
}
DisabledReason NTPSnippetsStatusService::GetDisabledReasonFromDeps() const {
+ if (pref_service_->GetBoolean(prefs::kDisableSnippets)) {
+ DVLOG(1) << "[GetNewDisabledReason] Disabled via pref";
+ return DisabledReason::EXPLICITLY_DISABLED;
+ }
+
if (!signin_manager_ || !signin_manager_->IsAuthenticated()) {
DVLOG(1) << "[GetNewDisabledReason] Signed out";
return DisabledReason::SIGNED_OUT;

Powered by Google App Engine
This is Rietveld 408576698