Chromium Code Reviews| Index: components/ntp_snippets/ntp_snippets_fetcher.cc |
| diff --git a/components/ntp_snippets/ntp_snippets_fetcher.cc b/components/ntp_snippets/ntp_snippets_fetcher.cc |
| index 90c0815a07fc567c7c4715e068af69e5bfc0bd0a..7b73e11a113d7c491ea3ec96dc39bc6318b5b008 100644 |
| --- a/components/ntp_snippets/ntp_snippets_fetcher.cc |
| +++ b/components/ntp_snippets/ntp_snippets_fetcher.cc |
| @@ -50,11 +50,16 @@ const char kAuthorizationRequestHeaderFormat[] = "Bearer %s"; |
| // Variation parameter for the variant of fetching to use. |
| const char kVariantName[] = "fetching_variant"; |
|
Marc Treib
2016/05/12 08:59:16
Also here: s/variant/personalization, or whatever
jkrcal
2016/05/12 09:57:29
Done.
|
| +const char kHostRestrictionName[] = "fetching_host_restrict"; |
| // Constants listing possible values of the "fetching_variant" parameter. |
| -const char kVariantRestrictedString[] = "restricted"; |
| const char kVariantPersonalizedString[] = "personalized"; |
| -const char kVariantRestrictedPersonalizedString[] = "restricted_personalized"; |
| +const char kVariantNonPersonalizedString[] = "non-personalized"; |
| +const char kVariantAllString[] = "all"; |
| + |
| +// Constants listing possible values of the "fetching_host_restrict" parameter. |
| +const char kHostRestrictionOnString[] = "on"; |
| +const char kHostRestrictionOffString[] = "off"; |
| const char kRequestParameterFormat[] = |
| "{" |
| @@ -63,7 +68,7 @@ const char kRequestParameterFormat[] = |
| " \"advanced_options\": {" |
| " \"local_scoring_params\": {" |
| " \"content_params\": {" |
| - " \"only_return_personalized_results\": false" |
| + " \"only_return_personalized_results\": %s" |
| "%s" // If authenticated - user segment (lang code) will be inserted here. |
| " }," |
| " \"content_restricts\": {" |
| @@ -94,6 +99,8 @@ const char kHostRestrictFormat[] = |
| " \"type\": \"HOST_RESTRICT\"," |
| " \"value\": \"%s\"" |
| " }"; |
| +const char kTrueString[] = "true"; |
| +const char kFalseString[] = "false"; |
| std::string FetchResultToString(NTPSnippetsFetcher::FetchResult result) { |
| switch (result) { |
| @@ -136,15 +143,25 @@ NTPSnippetsFetcher::NTPSnippetsFetcher( |
| // Parse the variation parameters and set the defaults if missing. |
| std::string variant = variations::GetVariationParamValue( |
| ntp_snippets::kStudyName, kVariantName); |
| - if (variant == kVariantRestrictedString) { |
| - variant_ = Variant::kRestricted; |
| + if (variant == kVariantNonPersonalizedString) { |
| + variant_ = Variant::kNonPersonalized; |
| } else if (variant == kVariantPersonalizedString) { |
| variant_ = Variant::kPersonalized; |
| } else { |
| - variant_ = Variant::kRestrictedPersonalized; |
| - LOG_IF(WARNING, |
| - !variant.empty() && variant != kVariantRestrictedPersonalizedString) |
| - << "Unknown fetching variant provided: " << variant; |
| + variant_ = Variant::kAll; |
| + LOG_IF(WARNING, !variant.empty() && variant != kVariantAllString) |
| + << "Unknown value for fetching_variant: " << variant; |
| + } |
| + |
| + std::string host_restriction = variations::GetVariationParamValue( |
| + ntp_snippets::kStudyName, kHostRestrictionName); |
| + if (host_restriction == kHostRestrictionOffString) { |
| + use_host_restriction_ = false; |
| + } else { |
| + use_host_restriction_ = true; |
| + LOG_IF(WARNING, !host_restriction.empty() && |
| + host_restriction != kHostRestrictionOnString) |
| + << "Unknown value for fetching_host_restrict: " << host_restriction; |
| } |
| } |
| @@ -236,15 +253,13 @@ std::string NTPSnippetsFetcher::GetHostRestricts() const { |
| } |
| bool NTPSnippetsFetcher::UseHostRestriction() const { |
| - return (variant_ == Variant::kRestricted || |
| - variant_ == Variant::kRestrictedPersonalized) && |
| + return use_host_restriction_ && |
| !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| switches::kDontRestrict); |
| } |
| bool NTPSnippetsFetcher::UseAuthentication() const { |
| - return (variant_ == Variant::kPersonalized || |
| - variant_ == Variant::kRestrictedPersonalized); |
| + return (variant_ == Variant::kPersonalized || variant_ == Variant::kAll); |
| } |
| void NTPSnippetsFetcher::FetchSnippetsNonAuthenticated() { |
| @@ -257,8 +272,10 @@ void NTPSnippetsFetcher::FetchSnippetsNonAuthenticated() { |
| FetchSnippetsImpl( |
| url, std::string(), |
| - base::StringPrintf(kRequestParameterFormat, "", "", |
| - GetHostRestricts().c_str(), count_to_fetch_)); |
| + base::StringPrintf(kRequestParameterFormat, /*obfuscated_gaia_id=*/"", |
| + /* only_return_personalized_results=*/kFalseString, |
| + /*user_segment=*/"", GetHostRestricts().c_str(), |
| + count_to_fetch_)); |
| } |
| void NTPSnippetsFetcher::FetchSnippetsAuthenticated( |
| @@ -273,6 +290,7 @@ void NTPSnippetsFetcher::FetchSnippetsAuthenticated( |
| base::StringPrintf(kAuthorizationRequestHeaderFormat, |
| oauth_access_token.c_str()), |
| base::StringPrintf(kRequestParameterFormat, auth.c_str(), |
|
Marc Treib
2016/05/12 08:59:16
Maybe make a BuildRequestParameter helper function
jkrcal
2016/05/12 09:57:28
Done.
|
| + variant_ == Variant::kAll ? kFalseString : kTrueString, |
|
Marc Treib
2016/05/12 08:59:16
Ah, so when we get here, the variant can't be kNon
jkrcal
2016/05/12 09:57:29
Done.
|
| user_segment.c_str(), GetHostRestricts().c_str(), |
| count_to_fetch_)); |
| } |