json_to_categories.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_JSON_TO_CATEGORIES_H_
  5. #define COMPONENTS_NTP_SNIPPETS_REMOTE_JSON_TO_CATEGORIES_H_
  6. #include <vector>
  7. #include "base/time/time.h"
  8. #include "base/values.h"
  9. #include "components/ntp_snippets/category.h"
  10. #include "components/ntp_snippets/category_info.h"
  11. #include "components/ntp_snippets/remote/remote_suggestion.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. namespace ntp_snippets {
  14. struct FetchedCategory {
  15. Category category;
  16. CategoryInfo info;
  17. RemoteSuggestion::PtrVector suggestions;
  18. FetchedCategory(Category c, CategoryInfo&& info);
  19. FetchedCategory(FetchedCategory&&);
  20. ~FetchedCategory();
  21. FetchedCategory& operator=(FetchedCategory&&);
  22. };
  23. using FetchedCategoriesVector = std::vector<FetchedCategory>;
  24. // Provides the CategoryInfo data for article suggestions. If |title| is
  25. // nullopt, then the default, hard-coded title will be used.
  26. CategoryInfo BuildArticleCategoryInfo(
  27. const absl::optional<std::u16string>& title);
  28. // Provides the CategoryInfo data for other remote suggestions.
  29. CategoryInfo BuildRemoteCategoryInfo(const std::u16string& title,
  30. bool allow_fetching_more_results);
  31. bool JsonToCategories(const base::Value& parsed,
  32. FetchedCategoriesVector* categories,
  33. const base::Time& fetch_time);
  34. } // namespace ntp_snippets
  35. #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_JSON_TO_CATEGORIES_H_