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

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

Issue 2378323002: 📰 Show the Sign In promo as a separate card from the section (Closed)
Patch Set: fix compilation Created 4 years, 2 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 | « components/ntp_snippets/remote/ntp_snippets_status_service.h ('k') | no next file » | 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/remote/ntp_snippets_status_service.h" 5 #include "components/ntp_snippets/remote/ntp_snippets_status_service.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "components/ntp_snippets/features.h" 9 #include "components/ntp_snippets/features.h"
10 #include "components/ntp_snippets/pref_names.h" 10 #include "components/ntp_snippets/pref_names.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // Notify about the current state before registering the observer, to make 58 // Notify about the current state before registering the observer, to make
59 // sure we don't get a double notification due to an undefined start state. 59 // sure we don't get a double notification due to an undefined start state.
60 disabled_reason_ = GetDisabledReasonFromDeps(); 60 disabled_reason_ = GetDisabledReasonFromDeps();
61 disabled_reason_change_callback_.Run(disabled_reason_); 61 disabled_reason_change_callback_.Run(disabled_reason_);
62 62
63 signin_observer_.Add(signin_manager_); 63 signin_observer_.Add(signin_manager_);
64 64
65 pref_change_registrar_.Init(pref_service_); 65 pref_change_registrar_.Init(pref_service_);
66 pref_change_registrar_.Add( 66 pref_change_registrar_.Add(
67 prefs::kEnableSnippets, 67 prefs::kEnableSnippets,
68 base::Bind(&NTPSnippetsStatusService::OnStateChanged, 68 base::Bind(&NTPSnippetsStatusService::OnSnippetsEnabledChanged,
69 base::Unretained(this))); 69 base::Unretained(this)));
70 } 70 }
71 71
72 void NTPSnippetsStatusService::OnStateChanged() { 72 void NTPSnippetsStatusService::OnSnippetsEnabledChanged() {
73 DisabledReason new_disabled_reason = GetDisabledReasonFromDeps(); 73 OnStateChanged(GetDisabledReasonFromDeps());
74 }
74 75
76 void NTPSnippetsStatusService::OnStateChanged(
77 DisabledReason new_disabled_reason) {
75 if (new_disabled_reason == disabled_reason_) 78 if (new_disabled_reason == disabled_reason_)
76 return; 79 return;
77 80
78 disabled_reason_ = new_disabled_reason; 81 disabled_reason_ = new_disabled_reason;
79 disabled_reason_change_callback_.Run(disabled_reason_); 82 disabled_reason_change_callback_.Run(disabled_reason_);
80 } 83 }
81 84
82 void NTPSnippetsStatusService::GoogleSigninSucceeded( 85 void NTPSnippetsStatusService::GoogleSigninSucceeded(
83 const std::string& account_id, 86 const std::string& account_id,
84 const std::string& username, 87 const std::string& username,
85 const std::string& password) { 88 const std::string& password) {
86 OnStateChanged(); 89 // TODO(dgn): The snippets should be refetched: https://crbug.com/650666
90 OnStateChanged(GetDisabledReasonFromDeps());
87 } 91 }
88 92
89 void NTPSnippetsStatusService::GoogleSignedOut(const std::string& account_id, 93 void NTPSnippetsStatusService::GoogleSignedOut(const std::string& account_id,
90 const std::string& username) { 94 const std::string& username) {
91 if (!require_signin_ && disabled_reason_ == DisabledReason::NONE) { 95 if (!require_signin_ && disabled_reason_ == DisabledReason::NONE) {
92 // Temporary enter |SIGNED_OUT| state to clear all personalised suggestions. 96 // Temporary enter |SIGNED_OUT| state to clear all personalised suggestions.
93 disabled_reason_change_callback_.Run(DisabledReason::SIGNED_OUT); 97 OnStateChanged(DisabledReason::SIGNED_OUT);
94 disabled_reason_change_callback_.Run(disabled_reason_);
95 } 98 }
96 OnStateChanged(); 99
100 // Depending on |require_signin_|, will still report as SIGNED_OUT or switch
101 // back to |DisabledReason::NONE|
102 OnStateChanged(GetDisabledReasonFromDeps());
97 } 103 }
98 104
99 DisabledReason NTPSnippetsStatusService::GetDisabledReasonFromDeps() const { 105 DisabledReason NTPSnippetsStatusService::GetDisabledReasonFromDeps() const {
100 if (!pref_service_->GetBoolean(prefs::kEnableSnippets)) { 106 if (!pref_service_->GetBoolean(prefs::kEnableSnippets)) {
101 DVLOG(1) << "[GetNewDisabledReason] Disabled via pref"; 107 DVLOG(1) << "[GetNewDisabledReason] Disabled via pref";
102 return DisabledReason::EXPLICITLY_DISABLED; 108 return DisabledReason::EXPLICITLY_DISABLED;
103 } 109 }
104 110
105 if (require_signin_ && 111 if (require_signin_ &&
106 (!signin_manager_ || !signin_manager_->IsAuthenticated())) { 112 (!signin_manager_ || !signin_manager_->IsAuthenticated())) {
107 DVLOG(1) << "[GetNewDisabledReason] Signed out"; 113 DVLOG(1) << "[GetNewDisabledReason] Signed out";
108 return DisabledReason::SIGNED_OUT; 114 return DisabledReason::SIGNED_OUT;
109 } 115 }
110 116
111 DVLOG(1) << "[GetNewDisabledReason] Enabled"; 117 DVLOG(1) << "[GetNewDisabledReason] Enabled";
112 return DisabledReason::NONE; 118 return DisabledReason::NONE;
113 } 119 }
114 120
115 } // namespace ntp_snippets 121 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/ntp_snippets_status_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698