Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Unified Diff: components/ntp_snippets/remote/json_request.cc

Issue 2771813002: RemoteSuggestionsFetcher: Remove ChromeReader integration (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/remote/json_request.cc
diff --git a/components/ntp_snippets/remote/json_request.cc b/components/ntp_snippets/remote/json_request.cc
index 3f3125996171fe0439f049125a1881e9a1f29ec4..b9e47d1a2bf01c4e2710f37613f6e79818966de6 100644
--- a/components/ntp_snippets/remote/json_request.cc
+++ b/components/ntp_snippets/remote/json_request.cc
@@ -218,9 +218,7 @@ void JsonRequest::OnJsonError(const std::string& error) {
/*error_details=*/base::StringPrintf(" (error %s)", error.c_str()));
}
-JsonRequest::Builder::Builder()
- : fetch_api_(CHROME_READER_API),
- language_model_(nullptr) {}
+JsonRequest::Builder::Builder() : language_model_(nullptr) {}
JsonRequest::Builder::Builder(JsonRequest::Builder&&) = default;
JsonRequest::Builder::~Builder() = default;
@@ -250,11 +248,6 @@ JsonRequest::Builder& JsonRequest::Builder::SetAuthentication(
return *this;
}
-JsonRequest::Builder& JsonRequest::Builder::SetFetchAPI(FetchAPI fetch_api) {
- fetch_api_ = fetch_api;
- return *this;
-}
-
JsonRequest::Builder& JsonRequest::Builder::SetLanguageModel(
const translate::LanguageModel* language_model) {
language_model_ = language_model;
@@ -317,84 +310,43 @@ std::string JsonRequest::Builder::BuildHeaders() const {
std::string JsonRequest::Builder::BuildBody() const {
auto request = base::MakeUnique<base::DictionaryValue>();
std::string user_locale = PosixLocaleFromBCP47Language(params_.language_code);
- switch (fetch_api_) {
- case CHROME_READER_API: {
- auto content_restricts = base::MakeUnique<base::ListValue>();
- for (const auto* metadata : {"TITLE", "SNIPPET", "THUMBNAIL"}) {
- auto entry = base::MakeUnique<base::DictionaryValue>();
- entry->SetString("type", "METADATA");
- entry->SetString("value", metadata);
- content_restricts->Append(std::move(entry));
- }
-
- auto local_scoring_params = base::MakeUnique<base::DictionaryValue>();
- local_scoring_params->Set("content_restricts",
- std::move(content_restricts));
-
- auto global_scoring_params = base::MakeUnique<base::DictionaryValue>();
- global_scoring_params->SetInteger("num_to_return",
- params_.count_to_fetch);
- global_scoring_params->SetInteger("sort_type", 1);
-
- auto advanced = base::MakeUnique<base::DictionaryValue>();
- advanced->Set("local_scoring_params", std::move(local_scoring_params));
- advanced->Set("global_scoring_params", std::move(global_scoring_params));
-
- request->SetString("response_detail_level", "STANDARD");
- request->Set("advanced_options", std::move(advanced));
- if (!obfuscated_gaia_id_.empty()) {
- request->SetString("obfuscated_gaia_id", obfuscated_gaia_id_);
- }
- if (!user_locale.empty()) {
- request->SetString("user_locale", user_locale);
- }
+ if (!user_locale.empty()) {
+ request->SetString("uiLanguage", user_locale);
+ }
+
+ request->SetString("priority", params_.interactive_request
+ ? "USER_ACTION"
+ : "BACKGROUND_PREFETCH");
+
+ auto excluded = base::MakeUnique<base::ListValue>();
+ for (const auto& id : params_.excluded_ids) {
+ excluded->AppendString(id);
+ if (excluded->GetSize() >= kMaxExcludedIds) {
break;
}
+ }
+ request->Set("excludedSuggestionIds", std::move(excluded));
- case CHROME_CONTENT_SUGGESTIONS_API: {
- if (!user_locale.empty()) {
- request->SetString("uiLanguage", user_locale);
- }
-
- request->SetString("priority", params_.interactive_request
- ? "USER_ACTION"
- : "BACKGROUND_PREFETCH");
+ if (!user_class_.empty()) {
+ request->SetString("userActivenessClass", user_class_);
+ }
- auto excluded = base::MakeUnique<base::ListValue>();
- for (const auto& id : params_.excluded_ids) {
- excluded->AppendString(id);
- if (excluded->GetSize() >= kMaxExcludedIds) {
- break;
- }
- }
- request->Set("excludedSuggestionIds", std::move(excluded));
-
- if (!user_class_.empty()) {
- request->SetString("userActivenessClass", user_class_);
- }
-
- translate::LanguageModel::LanguageInfo ui_language;
- translate::LanguageModel::LanguageInfo other_top_language;
- PrepareLanguages(&ui_language, &other_top_language);
-
- if (ui_language.frequency == 0 && other_top_language.frequency == 0) {
- break;
- }
-
- auto language_list = base::MakeUnique<base::ListValue>();
- if (ui_language.frequency > 0) {
- AppendLanguageInfoToList(language_list.get(), ui_language);
- }
- if (other_top_language.frequency > 0) {
- AppendLanguageInfoToList(language_list.get(), other_top_language);
- }
- request->Set("topLanguages", std::move(language_list));
-
- // TODO(sfiera): Support count_to_fetch.
- break;
+ translate::LanguageModel::LanguageInfo ui_language;
+ translate::LanguageModel::LanguageInfo other_top_language;
+ PrepareLanguages(&ui_language, &other_top_language);
+ if (ui_language.frequency != 0 || other_top_language.frequency != 0) {
+ auto language_list = base::MakeUnique<base::ListValue>();
+ if (ui_language.frequency > 0) {
+ AppendLanguageInfoToList(language_list.get(), ui_language);
+ }
+ if (other_top_language.frequency > 0) {
+ AppendLanguageInfoToList(language_list.get(), other_top_language);
}
+ request->Set("topLanguages", std::move(language_list));
}
+ // TODO(sfiera): Support count_to_fetch.
+
std::string request_json;
bool success = base::JSONWriter::WriteWithOptions(
*request, base::JSONWriter::OPTIONS_PRETTY_PRINT, &request_json);
« no previous file with comments | « components/ntp_snippets/remote/json_request.h ('k') | components/ntp_snippets/remote/json_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698