Chromium Code Reviews| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 ~FetchedCategory(); // = default, in .cc | 58 ~FetchedCategory(); // = default, in .cc |
| 59 FetchedCategory& operator=(FetchedCategory&&); // = default, in .cc | 59 FetchedCategory& operator=(FetchedCategory&&); // = default, in .cc |
| 60 }; | 60 }; |
| 61 using FetchedCategoriesVector = std::vector<FetchedCategory>; | 61 using FetchedCategoriesVector = std::vector<FetchedCategory>; |
| 62 using OptionalFetchedCategories = base::Optional<FetchedCategoriesVector>; | 62 using OptionalFetchedCategories = base::Optional<FetchedCategoriesVector>; |
| 63 | 63 |
| 64 // |snippets| contains parsed snippets if a fetch succeeded. If problems | 64 // |snippets| contains parsed snippets if a fetch succeeded. If problems |
| 65 // occur, |snippets| contains no value (no actual vector in base::Optional). | 65 // occur, |snippets| contains no value (no actual vector in base::Optional). |
| 66 // Error details can be retrieved using last_status(). | 66 // Error details can be retrieved using last_status(). |
| 67 using SnippetsAvailableCallback = | 67 using SnippetsAvailableCallback = |
| 68 base::Callback<void(OptionalFetchedCategories fetched_categories)>; | 68 base::OnceCallback<void(OptionalFetchedCategories fetched_categories)>; |
|
Marc Treib
2016/10/18 08:17:45
If the callback is now for one fetch only, it shou
fhorschig
2016/10/20 13:10:38
The callback is passed into FetchSnippets.
The de
Marc Treib
2016/10/20 16:51:39
Well, that's what the previous behavior amounted t
tschumann
2016/10/24 06:38:25
never trust untested code ;-) A test would be real
Marc Treib
2016/10/28 14:49:48
We decided to fix this after this CL (crbug.com/65
| |
| 69 | 69 |
| 70 // Enumeration listing all possible outcomes for fetch attempts. Used for UMA | 70 // Enumeration listing all possible outcomes for fetch attempts. Used for UMA |
| 71 // histograms, so do not change existing values. Insert new values at the end, | 71 // histograms, so do not change existing values. Insert new values at the end, |
| 72 // and update the histogram definition. | 72 // and update the histogram definition. |
| 73 enum class FetchResult { | 73 enum class FetchResult { |
| 74 SUCCESS, | 74 SUCCESS, |
| 75 DEPRECATED_EMPTY_HOSTS, | 75 DEPRECATED_EMPTY_HOSTS, |
| 76 URL_REQUEST_STATUS_ERROR, | 76 URL_REQUEST_STATUS_ERROR, |
| 77 HTTP_ERROR, | 77 HTTP_ERROR, |
| 78 JSON_PARSE_ERROR, | 78 JSON_PARSE_ERROR, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 97 PrefService* pref_service, | 97 PrefService* pref_service, |
| 98 CategoryFactory* category_factory, | 98 CategoryFactory* category_factory, |
| 99 translate::LanguageModel* language_model, | 99 translate::LanguageModel* language_model, |
| 100 const ParseJSONCallback& parse_json_callback, | 100 const ParseJSONCallback& parse_json_callback, |
| 101 const std::string& api_key, | 101 const std::string& api_key, |
| 102 const UserClassifier* user_classifier); | 102 const UserClassifier* user_classifier); |
| 103 ~NTPSnippetsFetcher() override; | 103 ~NTPSnippetsFetcher() override; |
| 104 | 104 |
| 105 // Set a callback that is called when a new set of snippets are downloaded, | 105 // Set a callback that is called when a new set of snippets are downloaded, |
| 106 // overriding any previously set callback. | 106 // overriding any previously set callback. |
| 107 void SetCallback(const SnippetsAvailableCallback& callback); | 107 void SetCallback(SnippetsAvailableCallback callback); |
| 108 | 108 |
| 109 // Fetches snippets from the server. |hosts| restricts the results to a set of | 109 // Fetches snippets from the server. |hosts| restricts the results to a set of |
| 110 // hosts, e.g. "www.google.com". If |hosts| is empty, no host restrictions are | 110 // hosts, e.g. "www.google.com". If |hosts| is empty, no host restrictions are |
| 111 // applied. | 111 // applied. |
| 112 // | 112 // |
| 113 // |excluded_ids| will be reported to the server; the server should not return | 113 // |excluded_ids| will be reported to the server; the server should not return |
| 114 // suggestions with those IDs. | 114 // suggestions with those IDs. |
| 115 // | 115 // |
| 116 // If an ongoing fetch exists, it will be cancelled and a new one started, | 116 // If an ongoing fetch exists, it will be cancelled and a new one started, |
| 117 // without triggering an additional callback (i.e. not noticeable by | 117 // without triggering an additional callback (i.e. not noticeable by |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 // When a token request gets canceled, we want to retry once. | 283 // When a token request gets canceled, we want to retry once. |
| 284 bool oauth_token_retried_; | 284 bool oauth_token_retried_; |
| 285 | 285 |
| 286 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; | 286 base::WeakPtrFactory<NTPSnippetsFetcher> weak_ptr_factory_; |
| 287 | 287 |
| 288 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); | 288 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcher); |
| 289 }; | 289 }; |
| 290 } // namespace ntp_snippets | 290 } // namespace ntp_snippets |
| 291 | 291 |
| 292 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ | 292 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_FETCHER_H_ |
| OLD | NEW |