request_params.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_PARAMS_H_
  5. #define COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_PARAMS_H_
  6. #include <memory>
  7. #include <set>
  8. #include <string>
  9. #include "base/callback.h"
  10. #include "base/values.h"
  11. #include "components/ntp_snippets/category.h"
  12. #include "third_party/abseil-cpp/absl/types/optional.h"
  13. namespace ntp_snippets {
  14. // Contains all parameters for fetching remote suggestions.
  15. struct RequestParams {
  16. RequestParams();
  17. RequestParams(const RequestParams&);
  18. ~RequestParams();
  19. // BCP 47 language code specifying the user's UI language.
  20. std::string language_code;
  21. // A set of suggestion IDs that should not be returned again.
  22. std::set<std::string> excluded_ids;
  23. // Maximum number of snippets to fetch.
  24. int count_to_fetch = 0;
  25. // Whether this is an interactive request, i.e. triggered by an explicit
  26. // user action. Typically, non-interactive requests are subject to a daily
  27. // quota.
  28. bool interactive_request = false;
  29. // If set, only return results for this category.
  30. absl::optional<Category> exclusive_category;
  31. };
  32. // Callbacks for JSON parsing to allow injecting platform-dependent code.
  33. using SuccessCallback = base::OnceCallback<void(base::Value result)>;
  34. using ErrorCallback = base::OnceCallback<void(const std::string& error)>;
  35. using ParseJSONCallback =
  36. base::RepeatingCallback<void(const std::string& raw_json_string,
  37. SuccessCallback success_callback,
  38. ErrorCallback error_callback)>;
  39. } // namespace ntp_snippets
  40. #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_REQUEST_PARAMS_H_