Chromium Code Reviews| 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 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 | 709 |
| 710 auto content_restricts = base::MakeUnique<base::ListValue>(); | 710 auto content_restricts = base::MakeUnique<base::ListValue>(); |
| 711 for (const auto* metadata : {"TITLE", "SNIPPET", "THUMBNAIL"}) { | 711 for (const auto* metadata : {"TITLE", "SNIPPET", "THUMBNAIL"}) { |
| 712 auto entry = base::MakeUnique<base::DictionaryValue>(); | 712 auto entry = base::MakeUnique<base::DictionaryValue>(); |
| 713 entry->SetString("type", "METADATA"); | 713 entry->SetString("type", "METADATA"); |
| 714 entry->SetString("value", metadata); | 714 entry->SetString("value", metadata); |
| 715 content_restricts->Append(std::move(entry)); | 715 content_restricts->Append(std::move(entry)); |
| 716 } | 716 } |
| 717 | 717 |
| 718 auto content_selectors = base::MakeUnique<base::ListValue>(); | 718 auto content_selectors = base::MakeUnique<base::ListValue>(); |
| 719 for (const auto& host : params_.hosts) { | |
| 720 auto entry = base::MakeUnique<base::DictionaryValue>(); | |
| 721 entry->SetString("type", "HOST_RESTRICT"); | |
| 722 entry->SetString("value", host); | |
| 723 content_selectors->Append(std::move(entry)); | |
| 724 } | |
| 725 | 719 |
| 726 auto local_scoring_params = base::MakeUnique<base::DictionaryValue>(); | 720 auto local_scoring_params = base::MakeUnique<base::DictionaryValue>(); |
| 727 local_scoring_params->Set("content_params", std::move(content_params)); | 721 local_scoring_params->Set("content_params", std::move(content_params)); |
| 728 local_scoring_params->Set("content_restricts", | 722 local_scoring_params->Set("content_restricts", |
| 729 std::move(content_restricts)); | 723 std::move(content_restricts)); |
| 730 local_scoring_params->Set("content_selectors", | 724 local_scoring_params->Set("content_selectors", |
| 731 std::move(content_selectors)); | 725 std::move(content_selectors)); |
|
Marc Treib
2016/12/13 13:27:49
I think this can now be removed?
sfiera
2016/12/13 13:41:57
Done.
| |
| 732 | 726 |
| 733 auto global_scoring_params = base::MakeUnique<base::DictionaryValue>(); | 727 auto global_scoring_params = base::MakeUnique<base::DictionaryValue>(); |
| 734 global_scoring_params->SetInteger("num_to_return", | 728 global_scoring_params->SetInteger("num_to_return", |
| 735 params_.count_to_fetch); | 729 params_.count_to_fetch); |
| 736 global_scoring_params->SetInteger("sort_type", 1); | 730 global_scoring_params->SetInteger("sort_type", 1); |
| 737 | 731 |
| 738 auto advanced = base::MakeUnique<base::DictionaryValue>(); | 732 auto advanced = base::MakeUnique<base::DictionaryValue>(); |
| 739 advanced->Set("local_scoring_params", std::move(local_scoring_params)); | 733 advanced->Set("local_scoring_params", std::move(local_scoring_params)); |
| 740 advanced->Set("global_scoring_params", std::move(global_scoring_params)); | 734 advanced->Set("global_scoring_params", std::move(global_scoring_params)); |
| 741 | 735 |
| 742 request->SetString("response_detail_level", "STANDARD"); | 736 request->SetString("response_detail_level", "STANDARD"); |
| 743 request->Set("advanced_options", std::move(advanced)); | 737 request->Set("advanced_options", std::move(advanced)); |
| 744 if (!obfuscated_gaia_id_.empty()) { | 738 if (!obfuscated_gaia_id_.empty()) { |
| 745 request->SetString("obfuscated_gaia_id", obfuscated_gaia_id_); | 739 request->SetString("obfuscated_gaia_id", obfuscated_gaia_id_); |
| 746 } | 740 } |
| 747 if (!user_locale.empty()) { | 741 if (!user_locale.empty()) { |
| 748 request->SetString("user_locale", user_locale); | 742 request->SetString("user_locale", user_locale); |
| 749 } | 743 } |
| 750 break; | 744 break; |
| 751 } | 745 } |
| 752 | 746 |
| 753 case NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API: { | 747 case NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API: { |
| 754 if (!user_locale.empty()) { | 748 if (!user_locale.empty()) { |
| 755 request->SetString("uiLanguage", user_locale); | 749 request->SetString("uiLanguage", user_locale); |
| 756 } | 750 } |
| 757 | 751 |
| 758 auto regular_hosts = base::MakeUnique<base::ListValue>(); | |
| 759 for (const auto& host : params_.hosts) { | |
| 760 regular_hosts->AppendString(host); | |
| 761 } | |
| 762 request->Set("regularlyVisitedHostNames", std::move(regular_hosts)); | |
| 763 request->SetString("priority", params_.interactive_request | 752 request->SetString("priority", params_.interactive_request |
| 764 ? "USER_ACTION" | 753 ? "USER_ACTION" |
| 765 : "BACKGROUND_PREFETCH"); | 754 : "BACKGROUND_PREFETCH"); |
| 766 | 755 |
| 767 auto excluded = base::MakeUnique<base::ListValue>(); | 756 auto excluded = base::MakeUnique<base::ListValue>(); |
| 768 for (const auto& id : params_.excluded_ids) { | 757 for (const auto& id : params_.excluded_ids) { |
| 769 excluded->AppendString(id); | 758 excluded->AppendString(id); |
| 770 if (excluded->GetSize() >= kMaxExcludedIds) { | 759 if (excluded->GetSize() >= kMaxExcludedIds) { |
| 771 break; | 760 break; |
| 772 } | 761 } |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1110 NOTREACHED(); | 1099 NOTREACHED(); |
| 1111 return false; | 1100 return false; |
| 1112 } | 1101 } |
| 1113 | 1102 |
| 1114 bool NTPSnippetsFetcher::NeedsAuthentication() const { | 1103 bool NTPSnippetsFetcher::NeedsAuthentication() const { |
| 1115 return (personalization_ == Personalization::kPersonal || | 1104 return (personalization_ == Personalization::kPersonal || |
| 1116 personalization_ == Personalization::kBoth); | 1105 personalization_ == Personalization::kBoth); |
| 1117 } | 1106 } |
| 1118 | 1107 |
| 1119 } // namespace ntp_snippets | 1108 } // namespace ntp_snippets |
| OLD | NEW |