| 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> | 10 #include <set> |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 // If set, only return results for this category. | 129 // If set, only return results for this category. |
| 130 base::Optional<Category> exclusive_category; | 130 base::Optional<Category> exclusive_category; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 NTPSnippetsFetcher( | 133 NTPSnippetsFetcher( |
| 134 SigninManagerBase* signin_manager, | 134 SigninManagerBase* signin_manager, |
| 135 OAuth2TokenService* token_service, | 135 OAuth2TokenService* token_service, |
| 136 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, | 136 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, |
| 137 PrefService* pref_service, | 137 PrefService* pref_service, |
| 138 CategoryFactory* category_factory, | |
| 139 translate::LanguageModel* language_model, | 138 translate::LanguageModel* language_model, |
| 140 const ParseJSONCallback& parse_json_callback, | 139 const ParseJSONCallback& parse_json_callback, |
| 141 const std::string& api_key, | 140 const std::string& api_key, |
| 142 const UserClassifier* user_classifier); | 141 const UserClassifier* user_classifier); |
| 143 ~NTPSnippetsFetcher() override; | 142 ~NTPSnippetsFetcher() override; |
| 144 | 143 |
| 145 // Initiates a fetch from the server. When done (successfully or not), calls | 144 // Initiates a fetch from the server. When done (successfully or not), calls |
| 146 // the subscriber of SetCallback(). | 145 // the subscriber of SetCallback(). |
| 147 // | 146 // |
| 148 // If an ongoing fetch exists, it will be silently abandoned and a new one | 147 // If an ongoing fetch exists, it will be silently abandoned and a new one |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // When a token request gets canceled, we want to retry once. | 317 // When a token request gets canceled, we want to retry once. |
| 319 bool oauth_token_retried_ = false; | 318 bool oauth_token_retried_ = false; |
| 320 | 319 |
| 321 // Holds the URL request context. | 320 // Holds the URL request context. |
| 322 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 321 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 323 | 322 |
| 324 // Stores requests that wait for an access token. | 323 // Stores requests that wait for an access token. |
| 325 std::queue<std::pair<RequestBuilder, SnippetsAvailableCallback>> | 324 std::queue<std::pair<RequestBuilder, SnippetsAvailableCallback>> |
| 326 pending_requests_; | 325 pending_requests_; |
| 327 | 326 |
| 328 // Weak references, not owned. | 327 // Weak reference, not owned. |
| 329 CategoryFactory* const category_factory_; | |
| 330 translate::LanguageModel* const language_model_; | 328 translate::LanguageModel* const language_model_; |
| 331 | 329 |
| 332 const ParseJSONCallback parse_json_callback_; | 330 const ParseJSONCallback parse_json_callback_; |
| 333 | 331 |
| 334 // API endpoint for fetching snippets. | 332 // API endpoint for fetching snippets. |
| 335 const GURL fetch_url_; | 333 const GURL fetch_url_; |
| 336 // Which API to use | 334 // Which API to use |
| 337 const FetchAPI fetch_api_; | 335 const FetchAPI fetch_api_; |
| 338 | 336 |
| 339 // API key to use for non-authenticated requests. | 337 // API key to use for non-authenticated requests. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 357 std::string last_status_; | 355 std::string last_status_; |
| 358 std::string last_fetch_json_; | 356 std::string last_fetch_json_; |
| 359 | 357 |
| 360 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 358 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 361 | 359 |
| 362 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 360 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 363 }; | 361 }; |
| 364 } // namespace ntp_snippets | 362 } // namespace ntp_snippets |
| 365 | 363 |
| 366 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ | 364 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |