Chromium Code Reviews| Index: components/ntp_snippets/remote/ntp_snippets_fetcher.h |
| diff --git a/components/ntp_snippets/remote/ntp_snippets_fetcher.h b/components/ntp_snippets/remote/ntp_snippets_fetcher.h |
| index df4e28ab9a757130c16bbfd66fc7af397e4c62ce..70e40fa90e443b6cfcb76b4792047c35f0f0576d 100644 |
| --- a/components/ntp_snippets/remote/ntp_snippets_fetcher.h |
| +++ b/components/ntp_snippets/remote/ntp_snippets_fetcher.h |
| @@ -26,9 +26,14 @@ class PrefService; |
| class SigninManagerBase; |
| namespace base { |
| +class ListValue; |
| class Value; |
| } // namespace base |
| +namespace translate { |
| +class LanguageModel; |
| +} // namespace translate |
| + |
| namespace ntp_snippets { |
| // Fetches snippet data for the NTP from the server. |
| @@ -91,6 +96,7 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, |
| scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| PrefService* pref_service, |
| CategoryFactory* category_factory, |
| + translate::LanguageModel* language_model, |
| const ParseJSONCallback& parse_json_callback, |
| const std::string& api_key); |
| ~NTPSnippetsFetcher() override; |
| @@ -148,12 +154,31 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, |
| FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestAuthenticated); |
| FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestUnauthenticated); |
| FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, BuildRequestExcludedIds); |
| + FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, |
| + BuildRequestWithTwoLanguages); |
| + FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, |
| + BuildRequestWithUILanguageOnly); |
| + FRIEND_TEST_ALL_PREFIXES(NTPSnippetsFetcherTest, |
| + BuildRequestWithOtherLanguageOnly); |
| enum FetchAPI { |
| CHROME_READER_API, |
| CHROME_CONTENT_SUGGESTIONS_API, |
| }; |
| + struct ContentLanguageInfo { |
|
Bernhard Bauer
2016/10/07 12:26:13
Why don't we just use LanguageModel::LanguageInfo
jkrcal
2016/10/07 12:58:43
Good point. Done.
|
| + // ISO 639 code. |
| + std::string language_code; |
| + |
| + // The frequency of the given language |
| + float frequency; |
| + |
| + ContentLanguageInfo(); |
| + ~ContentLanguageInfo() = default; |
| + |
| + void AppendToList(base::ListValue* list); |
| + }; |
| + |
| struct RequestParams { |
| FetchAPI fetch_api; |
| std::string obfuscated_gaia_id; |
| @@ -163,6 +188,8 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, |
| std::set<std::string> excluded_ids; |
| int count_to_fetch; |
| bool interactive_request; |
| + ContentLanguageInfo ui_language; |
| + ContentLanguageInfo other_top_language; |
| RequestParams(); |
| ~RequestParams(); |
| @@ -173,6 +200,7 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, |
| void FetchSnippetsImpl(const GURL& url, |
| const std::string& auth_header, |
| const std::string& request); |
| + void SetUpCommonFetchingParameters(RequestParams* params) const; |
| void FetchSnippetsNonAuthenticated(); |
| void FetchSnippetsAuthenticated(const std::string& account_id, |
| const std::string& oauth_access_token); |
| @@ -208,7 +236,10 @@ class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, |
| // Holds the URL request context. |
| scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| + // Weak references, not owned. |
| CategoryFactory* const category_factory_; |
| + translate::LanguageModel* const language_model_; |
| + |
| const ParseJSONCallback parse_json_callback_; |
| base::TimeTicks fetch_start_time_; |
| std::string last_status_; |