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