| 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_REMOTE_SUGGESTIONS_FETCHER_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 ~RemoteSuggestionsFetcher() override; | 88 ~RemoteSuggestionsFetcher() override; |
| 89 | 89 |
| 90 // Initiates a fetch from the server. When done (successfully or not), calls | 90 // Initiates a fetch from the server. When done (successfully or not), calls |
| 91 // the callback. | 91 // the callback. |
| 92 // | 92 // |
| 93 // If an ongoing fetch exists, both fetches won't influence each other (i.e. | 93 // If an ongoing fetch exists, both fetches won't influence each other (i.e. |
| 94 // every callback will be called exactly once). | 94 // every callback will be called exactly once). |
| 95 void FetchSnippets(const RequestParams& params, | 95 void FetchSnippets(const RequestParams& params, |
| 96 SnippetsAvailableCallback callback); | 96 SnippetsAvailableCallback callback); |
| 97 | 97 |
| 98 std::string PersonalizationModeString() const; | |
| 99 | |
| 100 // Debug string representing the status/result of the last fetch attempt. | 98 // Debug string representing the status/result of the last fetch attempt. |
| 101 const std::string& last_status() const { return last_status_; } | 99 const std::string& last_status() const { return last_status_; } |
| 102 | 100 |
| 103 // Returns the last JSON fetched from the server. | 101 // Returns the last JSON fetched from the server. |
| 104 const std::string& last_json() const { return last_fetch_json_; } | 102 const std::string& last_json() const { return last_fetch_json_; } |
| 105 | 103 |
| 106 // Returns the personalization setting of the fetcher as used in tests. | |
| 107 // TODO(fhorschig): Reconsider these tests and remove this getter. | |
| 108 Personalization personalization() const { return personalization_; } | |
| 109 | |
| 110 // Returns the URL endpoint used by the fetcher. | 104 // Returns the URL endpoint used by the fetcher. |
| 111 const GURL& fetch_url() const { return fetch_url_; } | 105 const GURL& fetch_url() const { return fetch_url_; } |
| 112 | 106 |
| 113 // Overrides internal clock for testing purposes. | 107 // Overrides internal clock for testing purposes. |
| 114 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { | 108 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) { |
| 115 tick_clock_ = std::move(tick_clock); | 109 tick_clock_ = std::move(tick_clock); |
| 116 } | 110 } |
| 117 | 111 |
| 118 private: | 112 private: |
| 119 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, | 113 FRIEND_TEST_ALL_PREFIXES(ChromeReaderSnippetsFetcherTest, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 void FetchFinished(OptionalFetchedCategories categories, | 155 void FetchFinished(OptionalFetchedCategories categories, |
| 162 SnippetsAvailableCallback callback, | 156 SnippetsAvailableCallback callback, |
| 163 internal::FetchResult status_code, | 157 internal::FetchResult status_code, |
| 164 const std::string& error_details); | 158 const std::string& error_details); |
| 165 | 159 |
| 166 bool JsonToSnippets(const base::Value& parsed, | 160 bool JsonToSnippets(const base::Value& parsed, |
| 167 FetchedCategoriesVector* categories); | 161 FetchedCategoriesVector* categories); |
| 168 | 162 |
| 169 bool DemandQuotaForRequest(bool interactive_request); | 163 bool DemandQuotaForRequest(bool interactive_request); |
| 170 | 164 |
| 171 // Does the fetcher use authentication to get personalized results? | |
| 172 bool NeedsAuthentication() const; | |
| 173 | |
| 174 // Authentication for signed-in users. | 165 // Authentication for signed-in users. |
| 175 SigninManagerBase* signin_manager_; | 166 SigninManagerBase* signin_manager_; |
| 176 OAuth2TokenService* token_service_; | 167 OAuth2TokenService* token_service_; |
| 177 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; | 168 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; |
| 178 bool waiting_for_refresh_token_ = false; | 169 bool waiting_for_refresh_token_ = false; |
| 179 | 170 |
| 180 // When a token request gets canceled, we want to retry once. | 171 // When a token request gets canceled, we want to retry once. |
| 181 bool oauth_token_retried_ = false; | 172 bool oauth_token_retried_ = false; |
| 182 | 173 |
| 183 // Holds the URL request context. | 174 // Holds the URL request context. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 194 const ParseJSONCallback parse_json_callback_; | 185 const ParseJSONCallback parse_json_callback_; |
| 195 | 186 |
| 196 // API endpoint for fetching suggestions. | 187 // API endpoint for fetching suggestions. |
| 197 const GURL fetch_url_; | 188 const GURL fetch_url_; |
| 198 // Which API to use | 189 // Which API to use |
| 199 const internal::FetchAPI fetch_api_; | 190 const internal::FetchAPI fetch_api_; |
| 200 | 191 |
| 201 // API key to use for non-authenticated requests. | 192 // API key to use for non-authenticated requests. |
| 202 const std::string api_key_; | 193 const std::string api_key_; |
| 203 | 194 |
| 204 // The variant of the fetching to use, loaded from variation parameters. | |
| 205 Personalization personalization_; | |
| 206 | |
| 207 // Allow for an injectable tick clock for testing. | 195 // Allow for an injectable tick clock for testing. |
| 208 std::unique_ptr<base::TickClock> tick_clock_; | 196 std::unique_ptr<base::TickClock> tick_clock_; |
| 209 | 197 |
| 210 // Classifier that tells us how active the user is. Not owned. | 198 // Classifier that tells us how active the user is. Not owned. |
| 211 const UserClassifier* user_classifier_; | 199 const UserClassifier* user_classifier_; |
| 212 | 200 |
| 213 // Request throttlers for limiting requests for different classes of users. | 201 // Request throttlers for limiting requests for different classes of users. |
| 214 RequestThrottler request_throttler_rare_ntp_user_; | 202 RequestThrottler request_throttler_rare_ntp_user_; |
| 215 RequestThrottler request_throttler_active_ntp_user_; | 203 RequestThrottler request_throttler_active_ntp_user_; |
| 216 RequestThrottler request_throttler_active_suggestions_consumer_; | 204 RequestThrottler request_throttler_active_suggestions_consumer_; |
| 217 | 205 |
| 218 // Info on the last finished fetch. | 206 // Info on the last finished fetch. |
| 219 std::string last_status_; | 207 std::string last_status_; |
| 220 std::string last_fetch_json_; | 208 std::string last_fetch_json_; |
| 221 | 209 |
| 222 base::WeakPtrFactory<RemoteSuggestionsFetcher> weak_ptr_factory_; | 210 base::WeakPtrFactory<RemoteSuggestionsFetcher> weak_ptr_factory_; |
| 223 | 211 |
| 224 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcher); | 212 DISALLOW_COPY_AND_ASSIGN(RemoteSuggestionsFetcher); |
| 225 }; | 213 }; |
| 226 | 214 |
| 227 } // namespace ntp_snippets | 215 } // namespace ntp_snippets |
| 228 | 216 |
| 229 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ | 217 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REMOTE_SUGGESTIONS_FETCHER_H_ |
| OLD | NEW |