Chromium Code Reviews| 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_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 <queue> | 9 #include <queue> |
| 10 #include <set> | |
| 11 #include <string> | 10 #include <string> |
| 12 #include <utility> | 11 #include <utility> |
| 13 #include <vector> | |
| 14 | 12 |
| 15 #include "base/callback.h" | 13 #include "base/callback.h" |
| 16 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 17 #include "base/optional.h" | 15 #include "base/optional.h" |
| 18 #include "base/time/tick_clock.h" | 16 #include "base/time/tick_clock.h" |
| 19 #include "base/time/time.h" | |
| 20 #include "components/ntp_snippets/category.h" | 17 #include "components/ntp_snippets/category.h" |
| 21 #include "components/ntp_snippets/category_info.h" | 18 #include "components/ntp_snippets/category_info.h" |
| 22 #include "components/ntp_snippets/remote/ntp_snippet.h" | 19 #include "components/ntp_snippets/remote/ntp_snippet.h" |
| 20 #include "components/ntp_snippets/remote/ntp_snippets_json_request.h" | |
| 23 #include "components/ntp_snippets/remote/request_throttler.h" | 21 #include "components/ntp_snippets/remote/request_throttler.h" |
| 24 #include "components/ntp_snippets/status.h" | 22 #include "components/ntp_snippets/status.h" |
| 25 #include "components/translate/core/browser/language_model.h" | 23 #include "components/translate/core/browser/language_model.h" |
| 26 #include "google_apis/gaia/oauth2_token_service.h" | |
| 27 #include "net/http/http_request_headers.h" | |
| 28 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 29 | 25 |
| 30 class PrefService; | 26 class PrefService; |
| 31 class SigninManagerBase; | 27 class SigninManagerBase; |
| 32 | 28 |
| 33 namespace base { | 29 namespace base { |
| 34 class Value; | 30 class Value; |
| 35 } // namespace base | 31 } // namespace base |
| 36 | 32 |
| 37 namespace ntp_snippets { | 33 namespace ntp_snippets { |
| 38 | 34 |
| 35 namespace internal { | |
|
tschumann
2016/12/16 16:36:20
it's not in internal anymore ;-)
fhorschig
2016/12/20 10:07:38
Done.
| |
| 36 class NTPSnippetsRequestParams; | |
| 37 } | |
| 38 | |
| 39 class UserClassifier; | 39 class UserClassifier; |
| 40 | 40 |
| 41 // TODO(tschumann): BuildArticleCategoryInfo() and BuildRemoteCategoryInfo() | 41 // TODO(tschumann): BuildArticleCategoryInfo() and BuildRemoteCategoryInfo() |
| 42 // don't really belong into this library. However, as the snippets fetcher is | 42 // don't really belong into this library. However, as the snippets fetcher is |
| 43 // providing this data for server-defined remote sections it's a good starting | 43 // providing this data for server-defined remote sections it's a good starting |
| 44 // point. Candiates to add to such a library would be persisting categories | 44 // point. Candiates to add to such a library would be persisting categories |
| 45 // (have all category managment in one place) or turning parsed JSON into | 45 // (have all category managment in one place) or turning parsed JSON into |
| 46 // FetchedCategory objects (all domain-specific logic in one place). | 46 // FetchedCategory objects (all domain-specific logic in one place). |
| 47 | 47 |
| 48 // Provides the CategoryInfo data for article suggestions. If |title| is | 48 // Provides the CategoryInfo data for article suggestions. If |title| is |
| 49 // nullopt, then the default, hard-coded title will be used. | 49 // nullopt, then the default, hard-coded title will be used. |
| 50 CategoryInfo BuildArticleCategoryInfo( | 50 CategoryInfo BuildArticleCategoryInfo( |
| 51 const base::Optional<base::string16>& title); | 51 const base::Optional<base::string16>& title); |
| 52 | 52 |
| 53 // Provides the CategoryInfo data for other remote suggestions. | 53 // Provides the CategoryInfo data for other remote suggestions. |
| 54 CategoryInfo BuildRemoteCategoryInfo(const base::string16& title, | 54 CategoryInfo BuildRemoteCategoryInfo(const base::string16& title, |
| 55 bool allow_fetching_more_results); | 55 bool allow_fetching_more_results); |
| 56 | 56 |
| 57 // Fetches snippet data for the NTP from the server. | 57 // Fetches snippet data for the NTP from the server. |
| 58 class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, | 58 class NTPSnippetsFetcher : public OAuth2TokenService::Consumer, |
| 59 public OAuth2TokenService::Observer { | 59 public OAuth2TokenService::Observer { |
| 60 public: | 60 public: |
| 61 // Callbacks for JSON parsing, needed because the parsing is platform- | 61 // Exposing JSON parsing callback that needs to be injected on creation. |
| 62 // dependent. | 62 using ParseJSONCallback = internal::NTPSnippetsJsonRequest::ParseJSONCallback; |
|
tschumann
2016/12/16 16:36:20
for types which are exposed publicly, I'd try to a
fhorschig
2016/12/20 10:07:38
Added the TODO. The idea is great, but refactoring
| |
| 63 using SuccessCallback = | |
| 64 base::Callback<void(std::unique_ptr<base::Value> result)>; | |
| 65 using ErrorCallback = base::Callback<void(const std::string& error)>; | |
| 66 using ParseJSONCallback = | |
| 67 base::Callback<void(const std::string& raw_json_string, | |
| 68 const SuccessCallback& success_callback, | |
| 69 const ErrorCallback& error_callback)>; | |
| 70 | 63 |
| 71 struct FetchedCategory { | 64 struct FetchedCategory { |
| 72 Category category; | 65 Category category; |
| 73 CategoryInfo info; | 66 CategoryInfo info; |
| 74 NTPSnippet::PtrVector snippets; | 67 NTPSnippet::PtrVector snippets; |
| 75 | 68 |
| 76 FetchedCategory(Category c, CategoryInfo&& info); | 69 FetchedCategory(Category c, CategoryInfo&& info); |
| 77 FetchedCategory(FetchedCategory&&); // = default, in .cc | 70 FetchedCategory(FetchedCategory&&); // = default, in .cc |
| 78 ~FetchedCategory(); // = default, in .cc | 71 ~FetchedCategory(); // = default, in .cc |
| 79 FetchedCategory& operator=(FetchedCategory&&); // = default, in .cc | 72 FetchedCategory& operator=(FetchedCategory&&); // = default, in .cc |
| 80 }; | 73 }; |
| 81 using FetchedCategoriesVector = std::vector<FetchedCategory>; | 74 using FetchedCategoriesVector = std::vector<FetchedCategory>; |
| 82 using OptionalFetchedCategories = base::Optional<FetchedCategoriesVector>; | 75 using OptionalFetchedCategories = base::Optional<FetchedCategoriesVector>; |
| 83 | 76 |
| 84 // Enumeration listing all possible outcomes for fetch attempts. Used for UMA | |
| 85 // histograms, so do not change existing values. Insert new values at the end, | |
| 86 // and update the histogram definition. | |
| 87 enum class FetchResult { | |
| 88 SUCCESS, | |
| 89 DEPRECATED_EMPTY_HOSTS, | |
| 90 URL_REQUEST_STATUS_ERROR, | |
| 91 HTTP_ERROR, | |
| 92 JSON_PARSE_ERROR, | |
| 93 INVALID_SNIPPET_CONTENT_ERROR, | |
| 94 OAUTH_TOKEN_ERROR, | |
| 95 INTERACTIVE_QUOTA_ERROR, | |
| 96 NON_INTERACTIVE_QUOTA_ERROR, | |
| 97 RESULT_MAX | |
| 98 }; | |
| 99 | |
| 100 // |snippets| contains parsed snippets if a fetch succeeded. If problems | 77 // |snippets| contains parsed snippets if a fetch succeeded. If problems |
| 101 // occur, |snippets| contains no value (no actual vector in base::Optional). | 78 // occur, |snippets| contains no value (no actual vector in base::Optional). |
| 102 // Error details can be retrieved using last_status(). | 79 // Error details can be retrieved using last_status(). |
| 103 using SnippetsAvailableCallback = | 80 using SnippetsAvailableCallback = |
| 104 base::OnceCallback<void(Status status, | 81 base::OnceCallback<void(Status status, |
| 105 OptionalFetchedCategories fetched_categories)>; | 82 OptionalFetchedCategories fetched_categories)>; |
| 106 | 83 |
| 107 // Enumeration listing all possible variants of dealing with personalization. | |
| 108 enum class Personalization { kPersonal, kNonPersonal, kBoth }; | |
| 109 | |
| 110 // Contains all the parameters for one fetch. | |
| 111 struct Params { | |
| 112 Params(); | |
| 113 Params(const Params&); | |
| 114 ~Params(); | |
| 115 | |
| 116 // BCP 47 language code specifying the user's UI language. | |
| 117 std::string language_code; | |
| 118 | |
| 119 // A set of suggestion IDs that should not be returned again. | |
| 120 std::set<std::string> excluded_ids; | |
| 121 | |
| 122 // Maximum number of snippets to fetch. | |
| 123 int count_to_fetch = 0; | |
| 124 | |
| 125 // Whether this is an interactive request, i.e. triggered by an explicit | |
| 126 // user action. Typically, non-interactive requests are subject to a daily | |
| 127 // quota. | |
| 128 bool interactive_request = false; | |
| 129 | |
| 130 // If set, only return results for this category. | |
| 131 base::Optional<Category> exclusive_category; | |
| 132 }; | |
| 133 | |
| 134 NTPSnippetsFetcher( | 84 NTPSnippetsFetcher( |
| 135 SigninManagerBase* signin_manager, | 85 SigninManagerBase* signin_manager, |
| 136 OAuth2TokenService* token_service, | 86 OAuth2TokenService* token_service, |
| 137 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 87 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 138 PrefService* pref_service, | 88 PrefService* pref_service, |
| 139 CategoryFactory* category_factory, | 89 CategoryFactory* category_factory, |
| 140 translate::LanguageModel* language_model, | 90 translate::LanguageModel* language_model, |
| 141 const ParseJSONCallback& parse_json_callback, | 91 const ParseJSONCallback& parse_json_callback, |
| 142 const std::string& api_key, | 92 const std::string& api_key, |
| 143 const UserClassifier* user_classifier); | 93 const UserClassifier* user_classifier); |
| 144 ~NTPSnippetsFetcher() override; | 94 ~NTPSnippetsFetcher() override; |
| 145 | 95 |
| 146 // 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 |
| 147 // the subscriber of SetCallback(). | 97 // the callback. |
| 148 // | 98 // |
| 149 // If an ongoing fetch exists, it will be silently abandoned and a new one | 99 // If an ongoing fetch exists, both fetches won't influence each other (i.e. |
| 150 // started, without triggering an additional callback (i.e. the callback will | 100 // every callback will be called exactly once). |
| 151 // only be called once). | 101 void FetchSnippets(const NTPSnippetsRequestParams& params, |
| 152 void FetchSnippets(const Params& params, SnippetsAvailableCallback callback); | 102 SnippetsAvailableCallback callback); |
| 153 | 103 |
| 154 // Debug string representing the status/result of the last fetch attempt. | 104 // Debug string representing the status/result of the last fetch attempt. |
| 155 const std::string& last_status() const { return last_status_; } | 105 const std::string& last_status() const { return last_status_; } |
| 156 | 106 |
| 157 // Returns the last JSON fetched from the server. | 107 // Returns the last JSON fetched from the server. |
| 158 const std::string& last_json() const { | 108 const std::string& last_json() const { |
| 159 return last_fetch_json_; | 109 return last_fetch_json_; |
| 160 } | 110 } |
| 161 | 111 |
| 162 // Returns the personalization setting of the fetcher. | 112 // Returns the personalization setting of the fetcher. |
| 163 Personalization personalization() const { return personalization_; } | 113 internal::Personalization personalization() const { return personalization_; } |
| 164 | 114 |
| 165 // Returns the URL endpoint used by the fetcher. | 115 // Returns the URL endpoint used by the fetcher. |
| 166 const GURL& fetch_url() const { return fetch_url_; } | 116 const GURL& fetch_url() const { return fetch_url_; } |
| 167 | 117 |
| 168 // Overrides internal clock for testing purposes. | 118 // Overrides internal clock for testing purposes. |
| 169 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { | 119 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { |
| 170 tick_clock_ = std::move(tick_clock); | 120 tick_clock_ = std::move(tick_clock); |
| 171 } | 121 } |
| 172 | 122 |
| 173 private: | 123 private: |
| 174 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, | 124 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 175 BuildRequestAuthenticated); | 125 BuildRequestAuthenticated); |
| 176 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, | 126 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 177 BuildRequestUnauthenticated); | 127 BuildRequestUnauthenticated); |
| 178 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, | 128 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 179 BuildRequestExcludedIds); | 129 BuildRequestExcludedIds); |
| 180 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, | 130 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 181 BuildRequestNoUserClass); | 131 BuildRequestNoUserClass); |
| 182 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, | 132 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 183 BuildRequestWithTwoLanguages); | 133 BuildRequestWithTwoLanguages); |
| 184 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, | 134 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 185 BuildRequestWithUILanguageOnly); | 135 BuildRequestWithUILanguageOnly); |
| 186 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, | 136 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| 187 BuildRequestWithOtherLanguageOnly); | 137 BuildRequestWithOtherLanguageOnly); |
| 188 friend class ChromeReaderSnippetsFetcherTest; | 138 friend class ChromeReaderSnippetsFetcherTest; |
| 189 | 139 |
| 190 enum FetchAPI { | 140 void FetchSnippetsNonAuthenticated( |
| 191 CHROME_READER_API, | 141 internal::NTPSnippetsJsonRequest::Builder builder, |
| 192 CHROME_CONTENT_SUGGESTIONS_API, | 142 SnippetsAvailableCallback callback); |
| 193 }; | 143 void FetchSnippetsAuthenticated( |
| 194 | 144 internal::NTPSnippetsJsonRequest::Builder builder, |
| 195 class JsonRequest; | 145 SnippetsAvailableCallback callback, |
| 196 | 146 const std::string& account_id, |
| 197 // A class that builds authenticated and non-authenticated JsonRequests. | 147 const std::string& oauth_access_token); |
| 198 // This class is only in the header for testing. | 148 void StartRequest(internal::NTPSnippetsJsonRequest::Builder builder, |
| 199 // TODO(fhorschig): Move into separate file with snippets::internal namespace. | 149 SnippetsAvailableCallback callback); |
| 200 class RequestBuilder { | |
| 201 public: | |
| 202 RequestBuilder(); | |
| 203 RequestBuilder(RequestBuilder&&); | |
| 204 ~RequestBuilder(); | |
| 205 | |
| 206 // Builds a Request object that contains all data to fetch new snippets. | |
| 207 std::unique_ptr<JsonRequest> Build() const; | |
| 208 | |
| 209 RequestBuilder& SetAuthentication(const std::string& account_id, | |
| 210 const std::string& auth_header); | |
| 211 RequestBuilder& SetCreationTime(base::TimeTicks creation_time); | |
| 212 RequestBuilder& SetFetchAPI(FetchAPI fetch_api); | |
| 213 // The language_model borrowed from the fetcher needs to stay alive until | |
| 214 // the request body is built. | |
| 215 RequestBuilder& SetLanguageModel( | |
| 216 const translate::LanguageModel* language_model); | |
| 217 RequestBuilder& SetParams(const Params& params); | |
| 218 RequestBuilder& SetParseJsonCallback(ParseJSONCallback callback); | |
| 219 RequestBuilder& SetPersonalization(Personalization personalization); | |
| 220 // The tick_clock borrowed from the fetcher will be injected into the | |
| 221 // request. It will be used at build time and after the fetch returned. | |
| 222 // It has to be alive until the request is destroyed. | |
| 223 RequestBuilder& SetTickClock(base::TickClock* tick_clock); | |
| 224 RequestBuilder& SetUrl(const GURL& url); | |
| 225 RequestBuilder& SetUrlRequestContextGetter( | |
| 226 const scoped_refptr<net::URLRequestContextGetter>& context_getter); | |
| 227 RequestBuilder& SetUserClassifier(const UserClassifier& user_classifier); | |
| 228 | |
| 229 // These preview methods allow to inspect the Request without exposing it | |
| 230 // publicly. | |
| 231 // TODO(fhorschig): Remove these when moving the RequestBuilder to | |
| 232 // snippets::internal and trigger the request to intercept the request. | |
| 233 std::string PreviewRequestBodyForTesting() { return BuildBody(); } | |
| 234 std::string PreviewRequestHeadersForTesting() { return BuildHeaders(); } | |
| 235 RequestBuilder& SetUserClassForTesting(const std::string& user_class) { | |
| 236 user_class_ = user_class; | |
| 237 return *this; | |
| 238 } | |
| 239 | |
| 240 private: | |
| 241 std::string BuildHeaders() const; | |
| 242 std::string BuildBody() const; | |
| 243 std::unique_ptr<net::URLFetcher> BuildURLFetcher( | |
| 244 net::URLFetcherDelegate* request, | |
| 245 const std::string& headers, | |
| 246 const std::string& body) const; | |
| 247 | |
| 248 bool ReturnOnlyPersonalizedResults() const { | |
| 249 return !obfuscated_gaia_id_.empty() && | |
| 250 personalization_ == NTPSnippetsFetcher::Personalization::kPersonal; | |
| 251 } | |
| 252 | |
| 253 void PrepareLanguages( | |
| 254 translate::LanguageModel::LanguageInfo* ui_language, | |
| 255 translate::LanguageModel::LanguageInfo* other_top_language) const; | |
| 256 | |
| 257 // Only required, if the request needs to be sent. | |
| 258 std::string auth_header_; | |
| 259 base::TickClock* tick_clock_; | |
| 260 FetchAPI fetch_api_; | |
| 261 Params params_; | |
| 262 ParseJSONCallback parse_json_callback_; | |
| 263 Personalization personalization_; | |
| 264 GURL url_; | |
| 265 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
| 266 | |
| 267 // Optional properties. | |
| 268 std::string obfuscated_gaia_id_; | |
| 269 std::string user_class_; | |
| 270 const translate::LanguageModel* language_model_; | |
| 271 | |
| 272 DISALLOW_COPY_AND_ASSIGN(RequestBuilder); | |
| 273 }; | |
| 274 | |
| 275 void FetchSnippetsNonAuthenticated(RequestBuilder builder, | |
| 276 SnippetsAvailableCallback callback); | |
| 277 void FetchSnippetsAuthenticated(RequestBuilder builder, | |
| 278 SnippetsAvailableCallback callback, | |
| 279 const std::string& account_id, | |
| 280 const std::string& oauth_access_token); | |
| 281 void StartRequest(RequestBuilder builder, SnippetsAvailableCallback callback); | |
| 282 | 150 |
| 283 void StartTokenRequest(); | 151 void StartTokenRequest(); |
| 284 | 152 |
| 285 // OAuth2TokenService::Consumer overrides: | 153 // OAuth2TokenService::Consumer overrides: |
| 286 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 154 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 287 const std::string& access_token, | 155 const std::string& access_token, |
| 288 const base::Time& expiration_time) override; | 156 const base::Time& expiration_time) override; |
| 289 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 157 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 290 const GoogleServiceAuthError& error) override; | 158 const GoogleServiceAuthError& error) override; |
| 291 | 159 |
| 292 // OAuth2TokenService::Observer overrides: | 160 // OAuth2TokenService::Observer overrides: |
| 293 void OnRefreshTokenAvailable(const std::string& account_id) override; | 161 void OnRefreshTokenAvailable(const std::string& account_id) override; |
| 294 | 162 |
| 295 void JsonRequestDone(std::unique_ptr<JsonRequest> request, | 163 void JsonRequestDone( |
| 296 SnippetsAvailableCallback callback, | 164 std::unique_ptr<internal::NTPSnippetsJsonRequest> request, |
| 297 std::unique_ptr<base::Value> result, | 165 SnippetsAvailableCallback callback, |
| 298 FetchResult status_code, | 166 std::unique_ptr<base::Value> result, |
| 299 const std::string& error_details); | 167 internal::FetchResult status_code, |
| 168 const std::string& error_details); | |
| 300 void FetchFinished(OptionalFetchedCategories categories, | 169 void FetchFinished(OptionalFetchedCategories categories, |
| 301 SnippetsAvailableCallback callback, | 170 SnippetsAvailableCallback callback, |
| 302 FetchResult status_code, | 171 internal::FetchResult status_code, |
| 303 const std::string& error_details); | 172 const std::string& error_details); |
| 304 | 173 |
| 305 bool JsonToSnippets(const base::Value& parsed, | 174 bool JsonToSnippets(const base::Value& parsed, |
| 306 NTPSnippetsFetcher::FetchedCategoriesVector* categories); | 175 NTPSnippetsFetcher::FetchedCategoriesVector* categories); |
| 307 | 176 |
| 308 bool DemandQuotaForRequest(bool interactive_request); | 177 bool DemandQuotaForRequest(bool interactive_request); |
| 309 | 178 |
| 310 // Does the fetcher use authentication to get personalized results? | 179 // Does the fetcher use authentication to get personalized results? |
| 311 bool NeedsAuthentication() const; | 180 bool NeedsAuthentication() const; |
| 312 | 181 |
| 313 // Authentication for signed-in users. | 182 // Authentication for signed-in users. |
| 314 SigninManagerBase* signin_manager_; | 183 SigninManagerBase* signin_manager_; |
| 315 OAuth2TokenService* token_service_; | 184 OAuth2TokenService* token_service_; |
| 316 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; | 185 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; |
| 317 bool waiting_for_refresh_token_ = false; | 186 bool waiting_for_refresh_token_ = false; |
| 318 | 187 |
| 319 // When a token request gets canceled, we want to retry once. | 188 // When a token request gets canceled, we want to retry once. |
| 320 bool oauth_token_retried_ = false; | 189 bool oauth_token_retried_ = false; |
| 321 | 190 |
| 322 // Holds the URL request context. | 191 // Holds the URL request context. |
| 323 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 192 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 324 | 193 |
| 325 // Stores requests that wait for an access token. | 194 // Stores requests that wait for an access token. |
| 326 std::queue<std::pair<RequestBuilder, SnippetsAvailableCallback>> | 195 std::queue<std::pair<internal::NTPSnippetsJsonRequest::Builder, |
| 196 SnippetsAvailableCallback>> | |
| 327 pending_requests_; | 197 pending_requests_; |
| 328 | 198 |
| 329 // Weak references, not owned. | 199 // Weak references, not owned. |
| 330 CategoryFactory* const category_factory_; | 200 CategoryFactory* const category_factory_; |
| 331 translate::LanguageModel* const language_model_; | 201 translate::LanguageModel* const language_model_; |
| 332 | 202 |
| 333 const ParseJSONCallback parse_json_callback_; | 203 const ParseJSONCallback parse_json_callback_; |
| 334 | 204 |
| 335 // API endpoint for fetching snippets. | 205 // API endpoint for fetching snippets. |
| 336 const GURL fetch_url_; | 206 const GURL fetch_url_; |
| 337 // Which API to use | 207 // Which API to use |
| 338 const FetchAPI fetch_api_; | 208 const internal::FetchAPI fetch_api_; |
| 339 | 209 |
| 340 // API key to use for non-authenticated requests. | 210 // API key to use for non-authenticated requests. |
| 341 const std::string api_key_; | 211 const std::string api_key_; |
| 342 | 212 |
| 343 // The variant of the fetching to use, loaded from variation parameters. | 213 // The variant of the fetching to use, loaded from variation parameters. |
| 344 Personalization personalization_; | 214 internal::Personalization personalization_; |
| 345 | 215 |
| 346 // Allow for an injectable tick clock for testing. | 216 // Allow for an injectable tick clock for testing. |
| 347 std::unique_ptr<base::TickClock> tick_clock_; | 217 std::unique_ptr<base::TickClock> tick_clock_; |
| 348 | 218 |
| 349 // Classifier that tells us how active the user is. Not owned. | 219 // Classifier that tells us how active the user is. Not owned. |
| 350 const UserClassifier* user_classifier_; | 220 const UserClassifier* user_classifier_; |
| 351 | 221 |
| 352 // Request throttlers for limiting requests for different classes of users. | 222 // Request throttlers for limiting requests for different classes of users. |
| 353 RequestThrottler request_throttler_rare_ntp_user_; | 223 RequestThrottler request_throttler_rare_ntp_user_; |
| 354 RequestThrottler request_throttler_active_ntp_user_; | 224 RequestThrottler request_throttler_active_ntp_user_; |
| 355 RequestThrottler request_throttler_active_suggestions_consumer_; | 225 RequestThrottler request_throttler_active_suggestions_consumer_; |
| 356 | 226 |
| 357 // Info on the last finished fetch. | 227 // Info on the last finished fetch. |
| 358 std::string last_status_; | 228 std::string last_status_; |
| 359 std::string last_fetch_json_; | 229 std::string last_fetch_json_; |
| 360 | 230 |
| 361 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 231 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 362 | 232 |
| 363 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 233 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 364 }; | 234 }; |
| 365 } // namespace ntp_snippets | 235 } // namespace ntp_snippets |
| 366 | 236 |
| 367 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ | 237 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |