| 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/remote_suggestions_status_service.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_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" |
| 11 #include "components/prefs/pref_registry_simple.h" | 11 #include "components/prefs/pref_registry_simple.h" |
| 12 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 13 #include "components/signin/core/browser/signin_manager.h" | 13 #include "components/signin/core/browser/signin_manager.h" |
| 14 #include "components/variations/variations_associated_data.h" | 14 #include "components/variations/variations_associated_data.h" |
| 15 | 15 |
| 16 namespace ntp_snippets { | 16 namespace ntp_snippets { |
| 17 | 17 |
| 18 namespace { | |
| 19 | |
| 20 const char kFetchingRequiresSignin[] = "fetching_requires_signin"; | |
| 21 const char kFetchingRequiresSigninEnabled[] = "true"; | |
| 22 const char kFetchingRequiresSigninDisabled[] = "false"; | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 RemoteSuggestionsStatusService::RemoteSuggestionsStatusService( | 18 RemoteSuggestionsStatusService::RemoteSuggestionsStatusService( |
| 27 SigninManagerBase* signin_manager, | 19 SigninManagerBase* signin_manager, |
| 28 PrefService* pref_service) | 20 PrefService* pref_service) |
| 29 : status_(RemoteSuggestionsStatus::EXPLICITLY_DISABLED), | 21 : status_(RemoteSuggestionsStatus::EXPLICITLY_DISABLED), |
| 30 require_signin_(false), | |
| 31 signin_manager_(signin_manager), | 22 signin_manager_(signin_manager), |
| 32 pref_service_(pref_service) { | 23 pref_service_(pref_service) {} |
| 33 std::string param_value_str = variations::GetVariationParamValueByFeature( | |
| 34 kArticleSuggestionsFeature, kFetchingRequiresSignin); | |
| 35 if (param_value_str == kFetchingRequiresSigninEnabled) { | |
| 36 require_signin_ = true; | |
| 37 } else if (!param_value_str.empty() && | |
| 38 param_value_str != kFetchingRequiresSigninDisabled) { | |
| 39 DLOG(WARNING) << "Unknow value for the variations parameter " | |
| 40 << kFetchingRequiresSignin << ": " << param_value_str; | |
| 41 } | |
| 42 } | |
| 43 | 24 |
| 44 RemoteSuggestionsStatusService::~RemoteSuggestionsStatusService() = default; | 25 RemoteSuggestionsStatusService::~RemoteSuggestionsStatusService() = default; |
| 45 | 26 |
| 46 // static | 27 // static |
| 47 void RemoteSuggestionsStatusService::RegisterProfilePrefs( | 28 void RemoteSuggestionsStatusService::RegisterProfilePrefs( |
| 48 PrefRegistrySimple* registry) { | 29 PrefRegistrySimple* registry) { |
| 49 registry->RegisterBooleanPref(prefs::kEnableSnippets, true); | 30 registry->RegisterBooleanPref(prefs::kEnableSnippets, true); |
| 50 } | 31 } |
| 51 | 32 |
| 52 void RemoteSuggestionsStatusService::Init( | 33 void RemoteSuggestionsStatusService::Init( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 OnStateChanged(GetStatusFromDeps()); | 73 OnStateChanged(GetStatusFromDeps()); |
| 93 } | 74 } |
| 94 | 75 |
| 95 RemoteSuggestionsStatus RemoteSuggestionsStatusService::GetStatusFromDeps() | 76 RemoteSuggestionsStatus RemoteSuggestionsStatusService::GetStatusFromDeps() |
| 96 const { | 77 const { |
| 97 if (!pref_service_->GetBoolean(prefs::kEnableSnippets)) { | 78 if (!pref_service_->GetBoolean(prefs::kEnableSnippets)) { |
| 98 DVLOG(1) << "[GetStatusFromDeps] Disabled via pref"; | 79 DVLOG(1) << "[GetStatusFromDeps] Disabled via pref"; |
| 99 return RemoteSuggestionsStatus::EXPLICITLY_DISABLED; | 80 return RemoteSuggestionsStatus::EXPLICITLY_DISABLED; |
| 100 } | 81 } |
| 101 | 82 |
| 102 if (require_signin_ && !IsSignedIn()) { | |
| 103 DVLOG(1) << "[GetStatusFromDeps] Signed out and disabled due to this."; | |
| 104 return RemoteSuggestionsStatus::SIGNED_OUT_AND_DISABLED; | |
| 105 } | |
| 106 | |
| 107 DVLOG(1) << "[GetStatusFromDeps] Enabled, signed " | 83 DVLOG(1) << "[GetStatusFromDeps] Enabled, signed " |
| 108 << (IsSignedIn() ? "in" : "out"); | 84 << (IsSignedIn() ? "in" : "out"); |
| 109 return IsSignedIn() ? RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN | 85 return IsSignedIn() ? RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN |
| 110 : RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT; | 86 : RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT; |
| 111 } | 87 } |
| 112 | 88 |
| 113 } // namespace ntp_snippets | 89 } // namespace ntp_snippets |
| OLD | NEW |