OLD | NEW |
---|---|
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 16 matching lines...) Expand all Loading... | |
27 PrefService* pref_service) | 27 PrefService* pref_service) |
28 : snippets_status_(SnippetsStatus::EXPLICITLY_DISABLED), | 28 : snippets_status_(SnippetsStatus::EXPLICITLY_DISABLED), |
29 require_signin_(false), | 29 require_signin_(false), |
30 signin_manager_(signin_manager), | 30 signin_manager_(signin_manager), |
31 pref_service_(pref_service), | 31 pref_service_(pref_service), |
32 signin_observer_(this) { | 32 signin_observer_(this) { |
33 std::string param_value_str = variations::GetVariationParamValueByFeature( | 33 std::string param_value_str = variations::GetVariationParamValueByFeature( |
34 kArticleSuggestionsFeature, kFetchingRequiresSignin); | 34 kArticleSuggestionsFeature, kFetchingRequiresSignin); |
35 if (param_value_str == kFetchingRequiresSigninEnabled) { | 35 if (param_value_str == kFetchingRequiresSigninEnabled) { |
36 require_signin_ = true; | 36 require_signin_ = true; |
37 } else if (!param_value_str.empty() && | 37 } else { |
vitaliii
2016/11/21 08:50:49
We have not explicitly considered this case, but m
Marc Treib
2016/11/21 09:41:22
No, "else if" is a very common pattern, and I'd le
| |
38 param_value_str != kFetchingRequiresSigninDisabled) { | 38 if (!param_value_str.empty() && |
39 DLOG(WARNING) << "Unknow value for the variations parameter " | 39 param_value_str != kFetchingRequiresSigninDisabled) { |
40 << kFetchingRequiresSignin << ": " << param_value_str; | 40 DLOG(WARNING) << "Unknow value for the variations parameter " |
41 << kFetchingRequiresSignin << ": " << param_value_str; | |
42 } | |
41 } | 43 } |
42 } | 44 } |
43 | 45 |
44 NTPSnippetsStatusService::~NTPSnippetsStatusService() = default; | 46 NTPSnippetsStatusService::~NTPSnippetsStatusService() = default; |
45 | 47 |
46 // static | 48 // static |
47 void NTPSnippetsStatusService::RegisterProfilePrefs( | 49 void NTPSnippetsStatusService::RegisterProfilePrefs( |
48 PrefRegistrySimple* registry) { | 50 PrefRegistrySimple* registry) { |
49 registry->RegisterBooleanPref(prefs::kEnableSnippets, true); | 51 registry->RegisterBooleanPref(prefs::kEnableSnippets, true); |
50 } | 52 } |
(...skipping 18 matching lines...) Expand all Loading... | |
69 base::Bind(&NTPSnippetsStatusService::OnSnippetsEnabledChanged, | 71 base::Bind(&NTPSnippetsStatusService::OnSnippetsEnabledChanged, |
70 base::Unretained(this))); | 72 base::Unretained(this))); |
71 } | 73 } |
72 | 74 |
73 void NTPSnippetsStatusService::OnSnippetsEnabledChanged() { | 75 void NTPSnippetsStatusService::OnSnippetsEnabledChanged() { |
74 OnStateChanged(GetSnippetsStatusFromDeps()); | 76 OnStateChanged(GetSnippetsStatusFromDeps()); |
75 } | 77 } |
76 | 78 |
77 void NTPSnippetsStatusService::OnStateChanged( | 79 void NTPSnippetsStatusService::OnStateChanged( |
78 SnippetsStatus new_snippets_status) { | 80 SnippetsStatus new_snippets_status) { |
79 if (new_snippets_status == snippets_status_) | 81 if (new_snippets_status == snippets_status_) { |
80 return; | 82 return; |
83 } | |
81 | 84 |
82 snippets_status_change_callback_.Run(snippets_status_, new_snippets_status); | 85 snippets_status_change_callback_.Run(snippets_status_, new_snippets_status); |
83 snippets_status_ = new_snippets_status; | 86 snippets_status_ = new_snippets_status; |
84 } | 87 } |
85 | 88 |
86 bool NTPSnippetsStatusService::IsSignedIn() const { | 89 bool NTPSnippetsStatusService::IsSignedIn() const { |
87 return signin_manager_ && signin_manager_->IsAuthenticated(); | 90 return signin_manager_ && signin_manager_->IsAuthenticated(); |
88 } | 91 } |
89 | 92 |
90 void NTPSnippetsStatusService::GoogleSigninSucceeded( | 93 void NTPSnippetsStatusService::GoogleSigninSucceeded( |
(...skipping 19 matching lines...) Expand all Loading... | |
110 return SnippetsStatus::SIGNED_OUT_AND_DISABLED; | 113 return SnippetsStatus::SIGNED_OUT_AND_DISABLED; |
111 } | 114 } |
112 | 115 |
113 DVLOG(1) << "[GetNewSnippetsStatus] Enabled, signed " | 116 DVLOG(1) << "[GetNewSnippetsStatus] Enabled, signed " |
114 << (IsSignedIn() ? "in" : "out"); | 117 << (IsSignedIn() ? "in" : "out"); |
115 return IsSignedIn() ? SnippetsStatus::ENABLED_AND_SIGNED_IN | 118 return IsSignedIn() ? SnippetsStatus::ENABLED_AND_SIGNED_IN |
116 : SnippetsStatus::ENABLED_AND_SIGNED_OUT; | 119 : SnippetsStatus::ENABLED_AND_SIGNED_OUT; |
117 } | 120 } |
118 | 121 |
119 } // namespace ntp_snippets | 122 } // namespace ntp_snippets |
OLD | NEW |