| 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_fetcher.h" | 5 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 ReturnOnlyPersonalizedResults()); | 711 ReturnOnlyPersonalizedResults()); |
| 712 | 712 |
| 713 auto content_restricts = base::MakeUnique<base::ListValue>(); | 713 auto content_restricts = base::MakeUnique<base::ListValue>(); |
| 714 for (const auto* metadata : {"TITLE", "SNIPPET", "THUMBNAIL"}) { | 714 for (const auto* metadata : {"TITLE", "SNIPPET", "THUMBNAIL"}) { |
| 715 auto entry = base::MakeUnique<base::DictionaryValue>(); | 715 auto entry = base::MakeUnique<base::DictionaryValue>(); |
| 716 entry->SetString("type", "METADATA"); | 716 entry->SetString("type", "METADATA"); |
| 717 entry->SetString("value", metadata); | 717 entry->SetString("value", metadata); |
| 718 content_restricts->Append(std::move(entry)); | 718 content_restricts->Append(std::move(entry)); |
| 719 } | 719 } |
| 720 | 720 |
| 721 auto content_selectors = base::MakeUnique<base::ListValue>(); | |
| 722 for (const auto& host : params_.hosts) { | |
| 723 auto entry = base::MakeUnique<base::DictionaryValue>(); | |
| 724 entry->SetString("type", "HOST_RESTRICT"); | |
| 725 entry->SetString("value", host); | |
| 726 content_selectors->Append(std::move(entry)); | |
| 727 } | |
| 728 | |
| 729 auto local_scoring_params = base::MakeUnique<base::DictionaryValue>(); | 721 auto local_scoring_params = base::MakeUnique<base::DictionaryValue>(); |
| 730 local_scoring_params->Set("content_params", std::move(content_params)); | 722 local_scoring_params->Set("content_params", std::move(content_params)); |
| 731 local_scoring_params->Set("content_restricts", | 723 local_scoring_params->Set("content_restricts", |
| 732 std::move(content_restricts)); | 724 std::move(content_restricts)); |
| 733 local_scoring_params->Set("content_selectors", | |
| 734 std::move(content_selectors)); | |
| 735 | 725 |
| 736 auto global_scoring_params = base::MakeUnique<base::DictionaryValue>(); | 726 auto global_scoring_params = base::MakeUnique<base::DictionaryValue>(); |
| 737 global_scoring_params->SetInteger("num_to_return", | 727 global_scoring_params->SetInteger("num_to_return", |
| 738 params_.count_to_fetch); | 728 params_.count_to_fetch); |
| 739 global_scoring_params->SetInteger("sort_type", 1); | 729 global_scoring_params->SetInteger("sort_type", 1); |
| 740 | 730 |
| 741 auto advanced = base::MakeUnique<base::DictionaryValue>(); | 731 auto advanced = base::MakeUnique<base::DictionaryValue>(); |
| 742 advanced->Set("local_scoring_params", std::move(local_scoring_params)); | 732 advanced->Set("local_scoring_params", std::move(local_scoring_params)); |
| 743 advanced->Set("global_scoring_params", std::move(global_scoring_params)); | 733 advanced->Set("global_scoring_params", std::move(global_scoring_params)); |
| 744 | 734 |
| 745 request->SetString("response_detail_level", "STANDARD"); | 735 request->SetString("response_detail_level", "STANDARD"); |
| 746 request->Set("advanced_options", std::move(advanced)); | 736 request->Set("advanced_options", std::move(advanced)); |
| 747 if (!obfuscated_gaia_id_.empty()) { | 737 if (!obfuscated_gaia_id_.empty()) { |
| 748 request->SetString("obfuscated_gaia_id", obfuscated_gaia_id_); | 738 request->SetString("obfuscated_gaia_id", obfuscated_gaia_id_); |
| 749 } | 739 } |
| 750 if (!user_locale.empty()) { | 740 if (!user_locale.empty()) { |
| 751 request->SetString("user_locale", user_locale); | 741 request->SetString("user_locale", user_locale); |
| 752 } | 742 } |
| 753 break; | 743 break; |
| 754 } | 744 } |
| 755 | 745 |
| 756 case NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API: { | 746 case NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API: { |
| 757 if (!user_locale.empty()) { | 747 if (!user_locale.empty()) { |
| 758 request->SetString("uiLanguage", user_locale); | 748 request->SetString("uiLanguage", user_locale); |
| 759 } | 749 } |
| 760 | 750 |
| 761 auto regular_hosts = base::MakeUnique<base::ListValue>(); | |
| 762 for (const auto& host : params_.hosts) { | |
| 763 regular_hosts->AppendString(host); | |
| 764 } | |
| 765 request->Set("regularlyVisitedHostNames", std::move(regular_hosts)); | |
| 766 request->SetString("priority", params_.interactive_request | 751 request->SetString("priority", params_.interactive_request |
| 767 ? "USER_ACTION" | 752 ? "USER_ACTION" |
| 768 : "BACKGROUND_PREFETCH"); | 753 : "BACKGROUND_PREFETCH"); |
| 769 | 754 |
| 770 auto excluded = base::MakeUnique<base::ListValue>(); | 755 auto excluded = base::MakeUnique<base::ListValue>(); |
| 771 for (const auto& id : params_.excluded_ids) { | 756 for (const auto& id : params_.excluded_ids) { |
| 772 excluded->AppendString(id); | 757 excluded->AppendString(id); |
| 773 if (excluded->GetSize() >= kMaxExcludedIds) { | 758 if (excluded->GetSize() >= kMaxExcludedIds) { |
| 774 break; | 759 break; |
| 775 } | 760 } |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 NOTREACHED(); | 1098 NOTREACHED(); |
| 1114 return false; | 1099 return false; |
| 1115 } | 1100 } |
| 1116 | 1101 |
| 1117 bool NTPSnippetsFetcher::NeedsAuthentication() const { | 1102 bool NTPSnippetsFetcher::NeedsAuthentication() const { |
| 1118 return (personalization_ == Personalization::kPersonal || | 1103 return (personalization_ == Personalization::kPersonal || |
| 1119 personalization_ == Personalization::kBoth); | 1104 personalization_ == Personalization::kBoth); |
| 1120 } | 1105 } |
| 1121 | 1106 |
| 1122 } // namespace ntp_snippets | 1107 } // namespace ntp_snippets |
| OLD | NEW |