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