Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: components/ntp_snippets/remote/ntp_snippets_fetcher.h

Issue 2395123002: Connecting UserClassifier to NtpSnippetsFetcher (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_NTP_SNIPPETS_FETCHER_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 15 matching lines...) Expand all
26 class PrefService; 26 class PrefService;
27 class SigninManagerBase; 27 class SigninManagerBase;
28 28
29 namespace base { 29 namespace base {
30 class ListValue; 30 class ListValue;
31 class Value; 31 class Value;
32 } // namespace base 32 } // namespace base
33 33
34 namespace ntp_snippets { 34 namespace ntp_snippets {
35 35
36 class UserClassifier;
37
36 // Fetches snippet data for the NTP from the server. 38 // Fetches snippet data for the NTP from the server.
37 class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, 39 class NTPSnippetsFetcher : public OAuth2TokenService::Consumer,
38 public OAuth2TokenService::Observer, 40 public OAuth2TokenService::Observer,
39 public net::URLFetcherDelegate { 41 public net::URLFetcherDelegate {
40 public: 42 public:
41 // Callbacks for JSON parsing, needed because the parsing is platform- 43 // Callbacks for JSON parsing, needed because the parsing is platform-
42 // dependent. 44 // dependent.
43 using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>; 45 using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>;
44 using ErrorCallback = base::Callback<void(const std::string&)>; 46 using ErrorCallback = base::Callback<void(const std::string&)>;
45 using ParseJSONCallback = base::Callback< 47 using ParseJSONCallback = base::Callback<
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 }; 90 };
89 91
90 NTPSnippetsFetcher( 92 NTPSnippetsFetcher(
91 SigninManagerBase* signin_manager, 93 SigninManagerBase* signin_manager,
92 OAuth2TokenService* token_service, 94 OAuth2TokenService* token_service,
93 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, 95 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
94 PrefService* pref_service, 96 PrefService* pref_service,
95 CategoryFactory* category_factory, 97 CategoryFactory* category_factory,
96 translate::LanguageModel* language_model, 98 translate::LanguageModel* language_model,
97 const ParseJSONCallback& parse_json_callback, 99 const ParseJSONCallback& parse_json_callback,
98 const std::string& api_key); 100 const std::string& api_key,
101 const UserClassifier* user_classifier);
99 ~NTPSnippetsFetcher() override; 102 ~NTPSnippetsFetcher() override;
100 103
101 // Set a callback that is called when a new set of snippets are downloaded, 104 // Set a callback that is called when a new set of snippets are downloaded,
102 // overriding any previously set callback. 105 // overriding any previously set callback.
103 void SetCallback(const SnippetsAvailableCallback& callback); 106 void SetCallback(const SnippetsAvailableCallback& callback);
104 107
105 // Fetches snippets from the server. |hosts| restricts the results to a set of 108 // Fetches snippets from the server. |hosts| restricts the results to a set of
106 // hosts, e.g. "www.google.com". If |hosts| is empty, no host restrictions are 109 // hosts, e.g. "www.google.com". If |hosts| is empty, no host restrictions are
107 // applied. 110 // applied.
108 // 111 //
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 168
166 struct RequestParams { 169 struct RequestParams {
167 FetchAPI fetch_api; 170 FetchAPI fetch_api;
168 std::string obfuscated_gaia_id; 171 std::string obfuscated_gaia_id;
169 bool only_return_personalized_results; 172 bool only_return_personalized_results;
170 std::string user_locale; 173 std::string user_locale;
171 std::set<std::string> host_restricts; 174 std::set<std::string> host_restricts;
172 std::set<std::string> excluded_ids; 175 std::set<std::string> excluded_ids;
173 int count_to_fetch; 176 int count_to_fetch;
174 bool interactive_request; 177 bool interactive_request;
178 std::string user_class;
175 translate::LanguageModel::LanguageInfo ui_language; 179 translate::LanguageModel::LanguageInfo ui_language;
176 translate::LanguageModel::LanguageInfo other_top_language; 180 translate::LanguageModel::LanguageInfo other_top_language;
177 181
178 RequestParams(); 182 RequestParams();
179 ~RequestParams(); 183 ~RequestParams();
180 184
181 std::string BuildRequest(); 185 std::string BuildRequest();
182 }; 186 };
183 187
184 void FetchSnippetsImpl(const GURL& url, 188 void FetchSnippetsImpl(const GURL& url,
(...skipping 19 matching lines...) Expand all
204 void OnURLFetchComplete(const net::URLFetcher* source) override; 208 void OnURLFetchComplete(const net::URLFetcher* source) override;
205 209
206 bool JsonToSnippets(const base::Value& parsed, 210 bool JsonToSnippets(const base::Value& parsed,
207 FetchedCategoriesVector* categories); 211 FetchedCategoriesVector* categories);
208 void OnJsonParsed(std::unique_ptr<base::Value> parsed); 212 void OnJsonParsed(std::unique_ptr<base::Value> parsed);
209 void OnJsonError(const std::string& error); 213 void OnJsonError(const std::string& error);
210 void FetchFinished(OptionalFetchedCategories fetched_categories, 214 void FetchFinished(OptionalFetchedCategories fetched_categories,
211 FetchResult result, 215 FetchResult result,
212 const std::string& extra_message); 216 const std::string& extra_message);
213 217
218 bool DemandQuotaForRequest(bool interactive_request);
219
214 // Authorization for signed-in users. 220 // Authorization for signed-in users.
215 SigninManagerBase* signin_manager_; 221 SigninManagerBase* signin_manager_;
216 OAuth2TokenService* token_service_; 222 OAuth2TokenService* token_service_;
217 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; 223 std::unique_ptr<OAuth2TokenService::Request> oauth_request_;
218 bool waiting_for_refresh_token_; 224 bool waiting_for_refresh_token_;
219 225
220 // Holds the URL request context. 226 // Holds the URL request context.
221 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 227 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
222 228
223 // Weak references, not owned. 229 // Weak references, not owned.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 263
258 // The variant of the fetching to use, loaded from variation parameters. 264 // The variant of the fetching to use, loaded from variation parameters.
259 Personalization personalization_; 265 Personalization personalization_;
260 266
261 // Is the request user initiated? 267 // Is the request user initiated?
262 bool interactive_request_; 268 bool interactive_request_;
263 269
264 // Allow for an injectable tick clock for testing. 270 // Allow for an injectable tick clock for testing.
265 std::unique_ptr<base::TickClock> tick_clock_; 271 std::unique_ptr<base::TickClock> tick_clock_;
266 272
267 // Request throttler for limiting requests. 273 // Classifier that tells us how active the user is. Not owned.
268 RequestThrottler request_throttler_; 274 const UserClassifier* user_classifier_;
275
276 // Request throttlers for limiting requests for different classes of users.
277 RequestThrottler request_throttler_rare_ntp_user_;
278 RequestThrottler request_throttler_active_ntp_user_;
279 RequestThrottler request_throttler_active_suggestions_consumer_;
269 280
270 // When a token request gets canceled, we want to retry once. 281 // When a token request gets canceled, we want to retry once.
271 bool oauth_token_retried_; 282 bool oauth_token_retried_;
272 283
273 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; 284 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
274 285
275 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); 286 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);
276 }; 287 };
277 } // namespace ntp_snippets 288 } // namespace ntp_snippets
278 289
279 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ 290 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698