tile_service.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2020 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_QUERY_TILES_TILE_SERVICE_H_
  5. #define COMPONENTS_QUERY_TILES_TILE_SERVICE_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/callback.h"
  9. #include "base/supports_user_data.h"
  10. #include "components/keyed_service/core/keyed_service.h"
  11. #include "components/query_tiles/logger.h"
  12. #include "components/query_tiles/tile.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. namespace gfx {
  15. class Image;
  16. } // namespace gfx
  17. namespace query_tiles {
  18. using TileList = std::vector<Tile>;
  19. using GetTilesCallback = base::OnceCallback<void(TileList)>;
  20. using TileCallback = base::OnceCallback<void(absl::optional<Tile>)>;
  21. using VisualsCallback = base::OnceCallback<void(const gfx::Image&)>;
  22. using BackgroundTaskFinishedCallback = base::OnceCallback<void(bool)>;
  23. // The central class on chrome client responsible for fetching, storing,
  24. // managing, and displaying query tiles in chrome.
  25. class TileService : public KeyedService, public base::SupportsUserData {
  26. public:
  27. // Called to retrieve all the tiles.
  28. virtual void GetQueryTiles(GetTilesCallback callback) = 0;
  29. // Called to retrieve the tile associated with |tile_id|.
  30. virtual void GetTile(const std::string& tile_id, TileCallback callback) = 0;
  31. // Start fetch query tiles from server.
  32. virtual void StartFetchForTiles(bool is_from_reduced_mode,
  33. BackgroundTaskFinishedCallback callback) = 0;
  34. // Cancel any existing scheduled task, and reset backoff.
  35. virtual void CancelTask() = 0;
  36. // Used for debugging and testing only. Clear everything in db.
  37. virtual void PurgeDb() = 0;
  38. // Used for setting the server url for test.
  39. virtual void SetServerUrl(const std::string& base_url) = 0;
  40. // Called when a tile was clicked.
  41. virtual void OnTileClicked(const std::string& tile_id) = 0;
  42. // Called when the final level of tile is selected. |parent_tile_id| is
  43. // the Id of the parent tile, if it exists.
  44. virtual void OnQuerySelected(
  45. const absl::optional<std::string>& parent_tile_id,
  46. const std::u16string& query_text) = 0;
  47. // Returns a Logger instance that is meant to be used by logging and debug UI
  48. // components in the larger system.
  49. virtual Logger* GetLogger() = 0;
  50. TileService() = default;
  51. ~TileService() override = default;
  52. TileService(const TileService&) = delete;
  53. TileService& operator=(const TileService&) = delete;
  54. };
  55. } // namespace query_tiles
  56. #endif // COMPONENTS_QUERY_TILES_TILE_SERVICE_H_