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

Side by Side Diff: components/ntp_snippets/ntp_snippets_status_service.cc

Issue 2165983002: [NTP Snippets] Replace the "DisableSnippets" pref by an "Enable" one (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 unified diff | Download patch
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_status_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ntp_snippets/ntp_snippets_status_service.h" 5 #include "components/ntp_snippets/ntp_snippets_status_service.h"
6 6
7 #include "components/ntp_snippets/pref_names.h" 7 #include "components/ntp_snippets/pref_names.h"
8 #include "components/prefs/pref_registry_simple.h" 8 #include "components/prefs/pref_registry_simple.h"
9 #include "components/prefs/pref_service.h" 9 #include "components/prefs/pref_service.h"
10 #include "components/signin/core/browser/signin_manager.h" 10 #include "components/signin/core/browser/signin_manager.h"
11 #include "components/sync_driver/sync_service.h" 11 #include "components/sync_driver/sync_service.h"
12 12
13 namespace ntp_snippets { 13 namespace ntp_snippets {
14 14
15 NTPSnippetsStatusService::NTPSnippetsStatusService( 15 NTPSnippetsStatusService::NTPSnippetsStatusService(
16 SigninManagerBase* signin_manager, 16 SigninManagerBase* signin_manager,
17 sync_driver::SyncService* sync_service, 17 sync_driver::SyncService* sync_service,
18 PrefService* pref_service) 18 PrefService* pref_service)
19 : disabled_reason_(DisabledReason::EXPLICITLY_DISABLED), 19 : disabled_reason_(DisabledReason::EXPLICITLY_DISABLED),
20 signin_manager_(signin_manager), 20 signin_manager_(signin_manager),
21 sync_service_(sync_service), 21 sync_service_(sync_service),
22 pref_service_(pref_service), 22 pref_service_(pref_service),
23 sync_service_observer_(this) {} 23 sync_service_observer_(this) {}
24 24
25 NTPSnippetsStatusService::~NTPSnippetsStatusService() {} 25 NTPSnippetsStatusService::~NTPSnippetsStatusService() {}
26 26
27 // static 27 // static
28 void NTPSnippetsStatusService::RegisterProfilePrefs( 28 void NTPSnippetsStatusService::RegisterProfilePrefs(
29 PrefRegistrySimple* registry) { 29 PrefRegistrySimple* registry) {
30 registry->RegisterBooleanPref(prefs::kDisableSnippets, false); 30 registry->RegisterBooleanPref(prefs::kEnableSnippets, true);
31 } 31 }
32 32
33 void NTPSnippetsStatusService::Init( 33 void NTPSnippetsStatusService::Init(
34 const DisabledReasonChangeCallback& callback) { 34 const DisabledReasonChangeCallback& callback) {
35 DCHECK(disabled_reason_change_callback_.is_null()); 35 DCHECK(disabled_reason_change_callback_.is_null());
36 36
37 disabled_reason_change_callback_ = callback; 37 disabled_reason_change_callback_ = callback;
38 38
39 // Notify about the current state before registering the observer, to make 39 // Notify about the current state before registering the observer, to make
40 // sure we don't get a double notification due to an undefined start state. 40 // sure we don't get a double notification due to an undefined start state.
41 disabled_reason_ = GetDisabledReasonFromDeps(); 41 disabled_reason_ = GetDisabledReasonFromDeps();
42 disabled_reason_change_callback_.Run(disabled_reason_); 42 disabled_reason_change_callback_.Run(disabled_reason_);
43 43
44 sync_service_observer_.Add(sync_service_); 44 sync_service_observer_.Add(sync_service_);
45 45
46 pref_change_registrar_.Init(pref_service_); 46 pref_change_registrar_.Init(pref_service_);
47 pref_change_registrar_.Add( 47 pref_change_registrar_.Add(
48 prefs::kDisableSnippets, 48 prefs::kEnableSnippets,
49 base::Bind(&NTPSnippetsStatusService::OnStateChanged, 49 base::Bind(&NTPSnippetsStatusService::OnStateChanged,
50 base::Unretained(this))); 50 base::Unretained(this)));
51 } 51 }
52 52
53 void NTPSnippetsStatusService::OnStateChanged() { 53 void NTPSnippetsStatusService::OnStateChanged() {
54 DisabledReason new_disabled_reason = GetDisabledReasonFromDeps(); 54 DisabledReason new_disabled_reason = GetDisabledReasonFromDeps();
55 55
56 if (new_disabled_reason == disabled_reason_) 56 if (new_disabled_reason == disabled_reason_)
57 return; 57 return;
58 58
59 disabled_reason_ = new_disabled_reason; 59 disabled_reason_ = new_disabled_reason;
60 disabled_reason_change_callback_.Run(disabled_reason_); 60 disabled_reason_change_callback_.Run(disabled_reason_);
61 } 61 }
62 62
63 DisabledReason NTPSnippetsStatusService::GetDisabledReasonFromDeps() const { 63 DisabledReason NTPSnippetsStatusService::GetDisabledReasonFromDeps() const {
64 if (pref_service_->GetBoolean(prefs::kDisableSnippets)) { 64 if (!pref_service_->GetBoolean(prefs::kEnableSnippets)) {
65 DVLOG(1) << "[GetNewDisabledReason] Disabled via pref"; 65 DVLOG(1) << "[GetNewDisabledReason] Disabled via pref";
66 return DisabledReason::EXPLICITLY_DISABLED; 66 return DisabledReason::EXPLICITLY_DISABLED;
67 } 67 }
68 68
69 if (!signin_manager_ || !signin_manager_->IsAuthenticated()) { 69 if (!signin_manager_ || !signin_manager_->IsAuthenticated()) {
70 DVLOG(1) << "[GetNewDisabledReason] Signed out"; 70 DVLOG(1) << "[GetNewDisabledReason] Signed out";
71 return DisabledReason::SIGNED_OUT; 71 return DisabledReason::SIGNED_OUT;
72 } 72 }
73 73
74 if (!sync_service_ || !sync_service_->CanSyncStart()) { 74 if (!sync_service_ || !sync_service_->CanSyncStart()) {
(...skipping 19 matching lines...) Expand all
94 syncer::HISTORY_DELETE_DIRECTIVES)) { 94 syncer::HISTORY_DELETE_DIRECTIVES)) {
95 DVLOG(1) << "[GetNewDisabledReason] History sync disabled"; 95 DVLOG(1) << "[GetNewDisabledReason] History sync disabled";
96 return DisabledReason::HISTORY_SYNC_DISABLED; 96 return DisabledReason::HISTORY_SYNC_DISABLED;
97 } 97 }
98 98
99 DVLOG(1) << "[GetNewDisabledReason] Enabled"; 99 DVLOG(1) << "[GetNewDisabledReason] Enabled";
100 return DisabledReason::NONE; 100 return DisabledReason::NONE;
101 } 101 }
102 102
103 } // namespace ntp_snippets 103 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_status_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698