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 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/optional.h" | 15 #include "base/optional.h" |
16 #include "base/time/clock.h" | 16 #include "base/time/clock.h" |
17 #include "base/time/tick_clock.h" | 17 #include "base/time/tick_clock.h" |
18 #include "components/ntp_snippets/category.h" | 18 #include "components/ntp_snippets/category.h" |
19 #include "components/ntp_snippets/category_info.h" | 19 #include "components/ntp_snippets/category_info.h" |
20 #include "components/ntp_snippets/remote/json_request.h" | 20 #include "components/ntp_snippets/remote/json_request.h" |
21 #include "components/ntp_snippets/remote/remote_suggestion.h" | 21 #include "components/ntp_snippets/remote/remote_suggestion.h" |
22 #include "components/ntp_snippets/remote/request_params.h" | 22 #include "components/ntp_snippets/remote/request_params.h" |
23 #include "components/ntp_snippets/remote/request_throttler.h" | 23 #include "components/ntp_snippets/remote/request_throttler.h" |
24 #include "components/ntp_snippets/status.h" | 24 #include "components/ntp_snippets/status.h" |
25 #include "components/translate/core/browser/language_model.h" | 25 #include "components/translate/core/browser/language_model.h" |
| 26 #include "components/version_info/version_info.h" |
26 #include "net/url_request/url_request_context_getter.h" | 27 #include "net/url_request/url_request_context_getter.h" |
27 | 28 |
28 class PrefService; | 29 class PrefService; |
29 class SigninManagerBase; | 30 class SigninManagerBase; |
30 | 31 |
31 namespace base { | 32 namespace base { |
32 class Value; | 33 class Value; |
33 } // namespace base | 34 } // namespace base |
34 | 35 |
35 namespace ntp_snippets { | 36 namespace ntp_snippets { |
36 | 37 |
37 class UserClassifier; | 38 class UserClassifier; |
38 | 39 |
| 40 // Returns the appropriate API endpoint for the fetcher, in consideration of |
| 41 // the channel and variation parameters. |
| 42 GURL GetFetchEndpoint(version_info::Channel channel); |
| 43 |
39 // TODO(tschumann): BuildArticleCategoryInfo() and BuildRemoteCategoryInfo() | 44 // TODO(tschumann): BuildArticleCategoryInfo() and BuildRemoteCategoryInfo() |
40 // don't really belong into this library. However, as the fetcher is | 45 // don't really belong into this library. However, as the fetcher is |
41 // providing this data for server-defined remote sections it's a good starting | 46 // providing this data for server-defined remote sections it's a good starting |
42 // point. Candiates to add to such a library would be persisting categories | 47 // point. Candiates to add to such a library would be persisting categories |
43 // (have all category managment in one place) or turning parsed JSON into | 48 // (have all category managment in one place) or turning parsed JSON into |
44 // FetchedCategory objects (all domain-specific logic in one place). | 49 // FetchedCategory objects (all domain-specific logic in one place). |
45 | 50 |
46 // Provides the CategoryInfo data for article suggestions. If |title| is | 51 // Provides the CategoryInfo data for article suggestions. If |title| is |
47 // nullopt, then the default, hard-coded title will be used. | 52 // nullopt, then the default, hard-coded title will be used. |
48 CategoryInfo BuildArticleCategoryInfo( | 53 CategoryInfo BuildArticleCategoryInfo( |
(...skipping 27 matching lines...) Expand all Loading... |
76 base::OnceCallback<void(Status status, | 81 base::OnceCallback<void(Status status, |
77 OptionalFetchedCategories fetched_categories)>; | 82 OptionalFetchedCategories fetched_categories)>; |
78 | 83 |
79 RemoteSuggestionsFetcher( | 84 RemoteSuggestionsFetcher( |
80 SigninManagerBase* signin_manager, | 85 SigninManagerBase* signin_manager, |
81 OAuth2TokenService* token_service, | 86 OAuth2TokenService* token_service, |
82 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 87 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
83 PrefService* pref_service, | 88 PrefService* pref_service, |
84 translate::LanguageModel* language_model, | 89 translate::LanguageModel* language_model, |
85 const ParseJSONCallback& parse_json_callback, | 90 const ParseJSONCallback& parse_json_callback, |
| 91 const GURL& api_endpoint, |
86 const std::string& api_key, | 92 const std::string& api_key, |
87 const UserClassifier* user_classifier); | 93 const UserClassifier* user_classifier); |
88 ~RemoteSuggestionsFetcher() override; | 94 ~RemoteSuggestionsFetcher() override; |
89 | 95 |
90 // Initiates a fetch from the server. When done (successfully or not), calls | 96 // Initiates a fetch from the server. When done (successfully or not), calls |
91 // the callback. | 97 // the callback. |
92 // | 98 // |
93 // If an ongoing fetch exists, both fetches won't influence each other (i.e. | 99 // If an ongoing fetch exists, both fetches won't influence each other (i.e. |
94 // every callback will be called exactly once). | 100 // every callback will be called exactly once). |
95 void FetchSnippets(const RequestParams& params, | 101 void FetchSnippets(const RequestParams& params, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // Info on the last finished fetch. | 213 // Info on the last finished fetch. |
208 std::string last_status_; | 214 std::string last_status_; |
209 std::string last_fetch_json_; | 215 std::string last_fetch_json_; |
210 | 216 |
211 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcher); | 217 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcher); |
212 }; | 218 }; |
213 | 219 |
214 } // namespace ntp_snippets | 220 } // namespace ntp_snippets |
215 | 221 |
216 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ | 222 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ |
OLD | NEW |