| 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 <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 Category category; | 47 Category category; |
| 48 base::string16 localized_title; // Ignored for non-server categories. | 48 base::string16 localized_title; // Ignored for non-server categories. |
| 49 NTPSnippet::PtrVector snippets; | 49 NTPSnippet::PtrVector snippets; |
| 50 | 50 |
| 51 explicit FetchedCategory(Category c); | 51 explicit FetchedCategory(Category c); |
| 52 FetchedCategory(FetchedCategory&&); // = default, in .cc | 52 FetchedCategory(FetchedCategory&&); // = default, in .cc |
| 53 ~FetchedCategory(); // = default, in .cc | 53 ~FetchedCategory(); // = default, in .cc |
| 54 FetchedCategory& operator=(FetchedCategory&&); // = default, in .cc | 54 FetchedCategory& operator=(FetchedCategory&&); // = default, in .cc |
| 55 }; | 55 }; |
| 56 using FetchedCategoriesVector = std::vector<FetchedCategory>; | 56 using FetchedCategoriesVector = std::vector<FetchedCategory>; |
| 57 using OptionalSnippets = base::Optional<FetchedCategoriesVector>; | 57 using OptionalFetchedCategories = base::Optional<FetchedCategoriesVector>; |
| 58 | 58 |
| 59 // |snippets| contains parsed snippets if a fetch succeeded. If problems | 59 // |snippets| contains parsed snippets if a fetch succeeded. If problems |
| 60 // occur, |snippets| contains no value (no actual vector in base::Optional). | 60 // occur, |snippets| contains no value (no actual vector in base::Optional). |
| 61 // Error details can be retrieved using last_status(). | 61 // Error details can be retrieved using last_status(). |
| 62 using SnippetsAvailableCallback = | 62 using SnippetsAvailableCallback = |
| 63 base::Callback<void(OptionalSnippets snippets)>; | 63 base::Callback<void(OptionalFetchedCategories fetched_categories)>; |
| 64 | 64 |
| 65 // Enumeration listing all possible outcomes for fetch attempts. Used for UMA | 65 // Enumeration listing all possible outcomes for fetch attempts. Used for UMA |
| 66 // histograms, so do not change existing values. Insert new values at the end, | 66 // histograms, so do not change existing values. Insert new values at the end, |
| 67 // and update the histogram definition. | 67 // and update the histogram definition. |
| 68 enum class FetchResult { | 68 enum class FetchResult { |
| 69 SUCCESS, | 69 SUCCESS, |
| 70 DEPRECATED_EMPTY_HOSTS, | 70 DEPRECATED_EMPTY_HOSTS, |
| 71 URL_REQUEST_STATUS_ERROR, | 71 URL_REQUEST_STATUS_ERROR, |
| 72 HTTP_ERROR, | 72 HTTP_ERROR, |
| 73 JSON_PARSE_ERROR, | 73 JSON_PARSE_ERROR, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // OAuth2TokenService::Observer overrides: | 188 // OAuth2TokenService::Observer overrides: |
| 189 void OnRefreshTokenAvailable(const std::string& account_id) override; | 189 void OnRefreshTokenAvailable(const std::string& account_id) override; |
| 190 | 190 |
| 191 // URLFetcherDelegate implementation. | 191 // URLFetcherDelegate implementation. |
| 192 void OnURLFetchComplete(const net::URLFetcher* source) override; | 192 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 193 | 193 |
| 194 bool JsonToSnippets(const base::Value& parsed, | 194 bool JsonToSnippets(const base::Value& parsed, |
| 195 FetchedCategoriesVector* categories); | 195 FetchedCategoriesVector* categories); |
| 196 void OnJsonParsed(std::unique_ptr<base::Value> parsed); | 196 void OnJsonParsed(std::unique_ptr<base::Value> parsed); |
| 197 void OnJsonError(const std::string& error); | 197 void OnJsonError(const std::string& error); |
| 198 void FetchFinished(OptionalSnippets snippets, | 198 void FetchFinished(OptionalFetchedCategories fetched_categories, |
| 199 FetchResult result, | 199 FetchResult result, |
| 200 const std::string& extra_message); | 200 const std::string& extra_message); |
| 201 | 201 |
| 202 // Authorization for signed-in users. | 202 // Authorization for signed-in users. |
| 203 SigninManagerBase* signin_manager_; | 203 SigninManagerBase* signin_manager_; |
| 204 OAuth2TokenService* token_service_; | 204 OAuth2TokenService* token_service_; |
| 205 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; | 205 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; |
| 206 bool waiting_for_refresh_token_; | 206 bool waiting_for_refresh_token_; |
| 207 | 207 |
| 208 // Holds the URL request context. | 208 // Holds the URL request context. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // When a token request gets canceled, we want to retry once. | 255 // When a token request gets canceled, we want to retry once. |
| 256 bool oauth_token_retried_; | 256 bool oauth_token_retried_; |
| 257 | 257 |
| 258 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 258 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 259 | 259 |
| 260 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 260 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 261 }; | 261 }; |
| 262 } // namespace ntp_snippets | 262 } // namespace ntp_snippets |
| 263 | 263 |
| 264 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ | 264 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |