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

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

Issue 2395123002: Connecting UserClassifier to NtpSnippetsFetcher (Closed)
Patch Set: A minor fix 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 13 matching lines...) Expand all
24 24
25 class PrefService; 25 class PrefService;
26 class SigninManagerBase; 26 class SigninManagerBase;
27 27
28 namespace base { 28 namespace base {
29 class Value; 29 class Value;
30 } // namespace base 30 } // namespace base
31 31
32 namespace ntp_snippets { 32 namespace ntp_snippets {
33 33
34 class UserClassifier;
35
34 // Fetches snippet data for the NTP from the server. 36 // Fetches snippet data for the NTP from the server.
35 class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, 37 class NTPSnippetsFetcher : public OAuth2TokenService::Consumer,
36 public OAuth2TokenService::Observer, 38 public OAuth2TokenService::Observer,
37 public net::URLFetcherDelegate { 39 public net::URLFetcherDelegate {
38 public: 40 public:
39 // Callbacks for JSON parsing, needed because the parsing is platform- 41 // Callbacks for JSON parsing, needed because the parsing is platform-
40 // dependent. 42 // dependent.
41 using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>; 43 using SuccessCallback = base::Callback<void(std::unique_ptr<base::Value>)>;
42 using ErrorCallback = base::Callback<void(const std::string&)>; 44 using ErrorCallback = base::Callback<void(const std::string&)>;
43 using ParseJSONCallback = base::Callback< 45 using ParseJSONCallback = base::Callback<
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 kBoth 87 kBoth
86 }; 88 };
87 89
88 NTPSnippetsFetcher( 90 NTPSnippetsFetcher(
89 SigninManagerBase* signin_manager, 91 SigninManagerBase* signin_manager,
90 OAuth2TokenService* token_service, 92 OAuth2TokenService* token_service,
91 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, 93 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
92 PrefService* pref_service, 94 PrefService* pref_service,
93 CategoryFactory* category_factory, 95 CategoryFactory* category_factory,
94 const ParseJSONCallback& parse_json_callback, 96 const ParseJSONCallback& parse_json_callback,
95 const std::string& api_key); 97 const std::string& api_key,
98 const UserClassifier* user_classifier);
96 ~NTPSnippetsFetcher() override; 99 ~NTPSnippetsFetcher() override;
97 100
98 // Set a callback that is called when a new set of snippets are downloaded, 101 // Set a callback that is called when a new set of snippets are downloaded,
99 // overriding any previously set callback. 102 // overriding any previously set callback.
100 void SetCallback(const SnippetsAvailableCallback& callback); 103 void SetCallback(const SnippetsAvailableCallback& callback);
101 104
102 // Fetches snippets from the server. |hosts| restricts the results to a set of 105 // Fetches snippets from the server. |hosts| restricts the results to a set of
103 // hosts, e.g. "www.google.com". If host restrictions are enabled, an empty 106 // hosts, e.g. "www.google.com". If host restrictions are enabled, an empty
104 // host set produces an error without issuing a fetch. 107 // host set produces an error without issuing a fetch.
105 // 108 //
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 161
159 struct RequestParams { 162 struct RequestParams {
160 FetchAPI fetch_api; 163 FetchAPI fetch_api;
161 std::string obfuscated_gaia_id; 164 std::string obfuscated_gaia_id;
162 bool only_return_personalized_results; 165 bool only_return_personalized_results;
163 std::string user_locale; 166 std::string user_locale;
164 std::set<std::string> host_restricts; 167 std::set<std::string> host_restricts;
165 std::set<std::string> excluded_ids; 168 std::set<std::string> excluded_ids;
166 int count_to_fetch; 169 int count_to_fetch;
167 bool interactive_request; 170 bool interactive_request;
171 std::string user_class;
168 172
169 RequestParams(); 173 RequestParams();
170 ~RequestParams(); 174 ~RequestParams();
171 175
172 std::string BuildRequest(); 176 std::string BuildRequest();
173 }; 177 };
174 178
175 void FetchSnippetsImpl(const GURL& url, 179 void FetchSnippetsImpl(const GURL& url,
176 const std::string& auth_header, 180 const std::string& auth_header,
177 const std::string& request); 181 const std::string& request);
(...skipping 16 matching lines...) Expand all
194 void OnURLFetchComplete(const net::URLFetcher* source) override; 198 void OnURLFetchComplete(const net::URLFetcher* source) override;
195 199
196 bool JsonToSnippets(const base::Value& parsed, 200 bool JsonToSnippets(const base::Value& parsed,
197 FetchedCategoriesVector* categories); 201 FetchedCategoriesVector* categories);
198 void OnJsonParsed(std::unique_ptr<base::Value> parsed); 202 void OnJsonParsed(std::unique_ptr<base::Value> parsed);
199 void OnJsonError(const std::string& error); 203 void OnJsonError(const std::string& error);
200 void FetchFinished(OptionalSnippets snippets, 204 void FetchFinished(OptionalSnippets snippets,
201 FetchResult result, 205 FetchResult result,
202 const std::string& extra_message); 206 const std::string& extra_message);
203 207
208 bool DemandQuotaForRequest(bool interactive_request);
209
204 // Authorization for signed-in users. 210 // Authorization for signed-in users.
205 SigninManagerBase* signin_manager_; 211 SigninManagerBase* signin_manager_;
206 OAuth2TokenService* token_service_; 212 OAuth2TokenService* token_service_;
207 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; 213 std::unique_ptr<OAuth2TokenService::Request> oauth_request_;
208 bool waiting_for_refresh_token_; 214 bool waiting_for_refresh_token_;
209 215
210 // Holds the URL request context. 216 // Holds the URL request context.
211 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; 217 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
212 218
213 CategoryFactory* const category_factory_; 219 CategoryFactory* const category_factory_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 Personalization personalization_; 252 Personalization personalization_;
247 // Should we apply host restriction? It is loaded from variation parameters. 253 // Should we apply host restriction? It is loaded from variation parameters.
248 bool use_host_restriction_; 254 bool use_host_restriction_;
249 255
250 // Is the request user initiated? 256 // Is the request user initiated?
251 bool interactive_request_; 257 bool interactive_request_;
252 258
253 // Allow for an injectable tick clock for testing. 259 // Allow for an injectable tick clock for testing.
254 std::unique_ptr<base::TickClock> tick_clock_; 260 std::unique_ptr<base::TickClock> tick_clock_;
255 261
256 // Request throttler for limiting requests. 262 // Classifier that tells us how active the user is. Not owned.
257 RequestThrottler request_throttler_; 263 const UserClassifier* user_classifier_;
264
265 // Request throttlers for limiting requests for different classes of users.
266 RequestThrottler request_throttler_rare_ntp_user_;
267 RequestThrottler request_throttler_active_ntp_user_;
268 RequestThrottler request_throttler_active_suggestions_consumer_;
258 269
259 // When a token request gets canceled, we want to retry once. 270 // When a token request gets canceled, we want to retry once.
260 bool oauth_token_retried_; 271 bool oauth_token_retried_;
261 272
262 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; 273 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_;
263 274
264 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); 275 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher);
265 }; 276 };
266 } // namespace ntp_snippets 277 } // namespace ntp_snippets
267 278
268 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ 279 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698