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_fetcher.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 using internal::JsonRequest; | 43 using internal::JsonRequest; |
44 using internal::FetchResult; | 44 using internal::FetchResult; |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 const char kContentSuggestionsApiScope[] = | 48 const char kContentSuggestionsApiScope[] = |
49 "https://www.googleapis.com/auth/chrome-content-suggestions"; | 49 "https://www.googleapis.com/auth/chrome-content-suggestions"; |
50 const char kSnippetsServerNonAuthorizedFormat[] = "%s?key=%s"; | 50 const char kSnippetsServerNonAuthorizedFormat[] = "%s?key=%s"; |
51 const char kAuthorizationRequestHeaderFormat[] = "Bearer %s"; | 51 const char kAuthorizationRequestHeaderFormat[] = "Bearer %s"; |
52 | 52 |
53 // Variation parameter for chrome-content-suggestions backend. | 53 constexpr base::FeatureParam<std::string> kContentSuggestionsBackend{ |
54 const char kContentSuggestionsBackend[] = "content_suggestions_backend"; | 54 &kArticleSuggestionsFeature, "content_suggestions_backend", |
| 55 kContentSuggestionsServer}; |
55 | 56 |
56 const int kFetchTimeHistogramResolution = 5; | 57 const int kFetchTimeHistogramResolution = 5; |
57 | 58 |
58 std::string FetchResultToString(FetchResult result) { | 59 std::string FetchResultToString(FetchResult result) { |
59 switch (result) { | 60 switch (result) { |
60 case FetchResult::SUCCESS: | 61 case FetchResult::SUCCESS: |
61 return "OK"; | 62 return "OK"; |
62 case FetchResult::URL_REQUEST_STATUS_ERROR: | 63 case FetchResult::URL_REQUEST_STATUS_ERROR: |
63 return "URLRequestStatus error"; | 64 return "URLRequestStatus error"; |
64 case FetchResult::HTTP_ERROR: | 65 case FetchResult::HTTP_ERROR: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return; | 167 return; |
167 } | 168 } |
168 RemoteSuggestionsFetcher::FetchedCategory category = std::move(*category_it); | 169 RemoteSuggestionsFetcher::FetchedCategory category = std::move(*category_it); |
169 categories->clear(); | 170 categories->clear(); |
170 categories->push_back(std::move(category)); | 171 categories->push_back(std::move(category)); |
171 } | 172 } |
172 | 173 |
173 } // namespace | 174 } // namespace |
174 | 175 |
175 GURL GetFetchEndpoint(version_info::Channel channel) { | 176 GURL GetFetchEndpoint(version_info::Channel channel) { |
176 std::string endpoint = variations::GetVariationParamValueByFeature( | 177 std::string endpoint = kContentSuggestionsBackend.Get(); |
177 ntp_snippets::kArticleSuggestionsFeature, kContentSuggestionsBackend); | |
178 if (!endpoint.empty()) { | 178 if (!endpoint.empty()) { |
179 return GURL{endpoint}; | 179 return GURL{endpoint}; |
180 } | 180 } |
181 | 181 |
182 switch (channel) { | 182 switch (channel) { |
183 case version_info::Channel::STABLE: | 183 case version_info::Channel::STABLE: |
184 case version_info::Channel::BETA: | 184 case version_info::Channel::BETA: |
185 return GURL{kContentSuggestionsServer}; | 185 return GURL{kContentSuggestionsServer}; |
186 | 186 |
187 case version_info::Channel::DEV: | 187 case version_info::Channel::DEV: |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 category, BuildRemoteCategoryInfo(base::UTF8ToUTF16(utf8_title), | 490 category, BuildRemoteCategoryInfo(base::UTF8ToUTF16(utf8_title), |
491 allow_fetching_more_results))); | 491 allow_fetching_more_results))); |
492 } | 492 } |
493 categories->back().suggestions = std::move(suggestions); | 493 categories->back().suggestions = std::move(suggestions); |
494 } | 494 } |
495 | 495 |
496 return true; | 496 return true; |
497 } | 497 } |
498 | 498 |
499 } // namespace ntp_snippets | 499 } // namespace ntp_snippets |
OLD | NEW |