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" | |
24 #include "components/ntp_snippets/status.h" | 23 #include "components/ntp_snippets/status.h" |
25 #include "components/translate/core/browser/language_model.h" | 24 #include "components/translate/core/browser/language_model.h" |
26 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
27 | 26 |
28 class PrefService; | 27 class PrefService; |
29 class SigninManagerBase; | 28 class SigninManagerBase; |
30 | 29 |
31 namespace base { | 30 namespace base { |
32 class Value; | 31 class Value; |
33 } // namespace base | 32 } // namespace base |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 const std::string& error_details); | 153 const std::string& error_details); |
155 void FetchFinished(OptionalFetchedCategories categories, | 154 void FetchFinished(OptionalFetchedCategories categories, |
156 SnippetsAvailableCallback callback, | 155 SnippetsAvailableCallback callback, |
157 internal::FetchResult status_code, | 156 internal::FetchResult status_code, |
158 const std::string& error_details); | 157 const std::string& error_details); |
159 | 158 |
160 bool JsonToSnippets(const base::Value& parsed, | 159 bool JsonToSnippets(const base::Value& parsed, |
161 FetchedCategoriesVector* categories, | 160 FetchedCategoriesVector* categories, |
162 const base::Time& fetch_time); | 161 const base::Time& fetch_time); |
163 | 162 |
164 bool DemandQuotaForRequest(bool interactive_request); | |
165 | |
166 // Authentication for signed-in users. | 163 // Authentication for signed-in users. |
167 SigninManagerBase* signin_manager_; | 164 SigninManagerBase* signin_manager_; |
168 OAuth2TokenService* token_service_; | 165 OAuth2TokenService* token_service_; |
169 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; | 166 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; |
170 bool waiting_for_refresh_token_ = false; | 167 bool waiting_for_refresh_token_ = false; |
171 | 168 |
172 // When a token request gets canceled, we want to retry once. | 169 // When a token request gets canceled, we want to retry once. |
173 bool oauth_token_retried_ = false; | 170 bool oauth_token_retried_ = false; |
174 | 171 |
175 // Holds the URL request context. | 172 // Holds the URL request context. |
(...skipping 16 matching lines...) Expand all Loading... |
192 | 189 |
193 // API key to use for non-authenticated requests. | 190 // API key to use for non-authenticated requests. |
194 const std::string api_key_; | 191 const std::string api_key_; |
195 | 192 |
196 // Allow for an injectable clock for testing. | 193 // Allow for an injectable clock for testing. |
197 std::unique_ptr<base::Clock> clock_; | 194 std::unique_ptr<base::Clock> clock_; |
198 | 195 |
199 // Classifier that tells us how active the user is. Not owned. | 196 // Classifier that tells us how active the user is. Not owned. |
200 const UserClassifier* user_classifier_; | 197 const UserClassifier* user_classifier_; |
201 | 198 |
202 // Request throttlers for limiting requests for different classes of users. | |
203 RequestThrottler request_throttler_rare_ntp_user_; | |
204 RequestThrottler request_throttler_active_ntp_user_; | |
205 RequestThrottler request_throttler_active_suggestions_consumer_; | |
206 | |
207 // Info on the last finished fetch. | 199 // Info on the last finished fetch. |
208 std::string last_status_; | 200 std::string last_status_; |
209 std::string last_fetch_json_; | 201 std::string last_fetch_json_; |
210 | 202 |
211 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcher); | 203 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcher); |
212 }; | 204 }; |
213 | 205 |
214 } // namespace ntp_snippets | 206 } // namespace ntp_snippets |
215 | 207 |
216 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ | 208 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ |
OLD | NEW |