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 EMPTY_HOSTS, | 70 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // OAuth2TokenService::Observer overrides: | 190 // OAuth2TokenService::Observer overrides: |
191 void OnRefreshTokenAvailable(const std::string& account_id) override; | 191 void OnRefreshTokenAvailable(const std::string& account_id) override; |
192 | 192 |
193 // URLFetcherDelegate implementation. | 193 // URLFetcherDelegate implementation. |
194 void OnURLFetchComplete(const net::URLFetcher* source) override; | 194 void OnURLFetchComplete(const net::URLFetcher* source) override; |
195 | 195 |
196 bool JsonToSnippets(const base::Value& parsed, | 196 bool JsonToSnippets(const base::Value& parsed, |
197 FetchedCategoriesVector* categories); | 197 FetchedCategoriesVector* categories); |
198 void OnJsonParsed(std::unique_ptr<base::Value> parsed); | 198 void OnJsonParsed(std::unique_ptr<base::Value> parsed); |
199 void OnJsonError(const std::string& error); | 199 void OnJsonError(const std::string& error); |
200 void FetchFinished(OptionalSnippets snippets, | 200 void FetchFinished(OptionalFetchedCategories fetched_categories, |
201 FetchResult result, | 201 FetchResult result, |
202 const std::string& extra_message); | 202 const std::string& extra_message); |
203 | 203 |
204 // Authorization for signed-in users. | 204 // Authorization for signed-in users. |
205 SigninManagerBase* signin_manager_; | 205 SigninManagerBase* signin_manager_; |
206 OAuth2TokenService* token_service_; | 206 OAuth2TokenService* token_service_; |
207 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; | 207 std::unique_ptr<OAuth2TokenService::Request> oauth_request_; |
208 bool waiting_for_refresh_token_; | 208 bool waiting_for_refresh_token_; |
209 | 209 |
210 // Holds the URL request context. | 210 // Holds the URL request context. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // When a token request gets canceled, we want to retry once. | 259 // When a token request gets canceled, we want to retry once. |
260 bool oauth_token_retried_; | 260 bool oauth_token_retried_; |
261 | 261 |
262 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 262 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
263 | 263 |
264 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 264 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
265 }; | 265 }; |
266 } // namespace ntp_snippets | 266 } // namespace ntp_snippets |
267 | 267 |
268 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ | 268 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ |
OLD | NEW |