Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 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 | |
Shakti Sahu | ce57c7d9 | 2020-04-29 01:47:17 | [diff] [blame^] | 5 | #ifndef COMPONENTS_QUERY_TILES_INTERNAL_TILE_MANAGER_H_ |
| 6 | #define COMPONENTS_QUERY_TILES_INTERNAL_TILE_MANAGER_H_ |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "base/callback.h" |
| 13 | #include "base/time/clock.h" |
Shakti Sahu | ce57c7d9 | 2020-04-29 01:47:17 | [diff] [blame^] | 14 | #include "components/query_tiles/internal/config.h" |
| 15 | #include "components/query_tiles/internal/store.h" |
| 16 | #include "components/query_tiles/internal/tile_group.h" |
| 17 | #include "components/query_tiles/internal/tile_types.h" |
| 18 | #include "components/query_tiles/tile.h" |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 19 | |
| 20 | namespace upboarding { |
| 21 | |
| 22 | // Manages the in-memory tile group and coordinates with storage layer. |
| 23 | class TileManager { |
| 24 | public: |
| 25 | using TileStore = Store<TileGroup>; |
| 26 | using TileGroupStatusCallback = base::OnceCallback<void(TileGroupStatus)>; |
Hesen Zhang | 4f42c28 | 2020-04-28 21:00:24 | [diff] [blame] | 27 | using GetTilesCallback = base::OnceCallback<void(std::vector<Tile>)>; |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 28 | |
| 29 | // Creates the instance. |
| 30 | static std::unique_ptr<TileManager> Create( |
| 31 | std::unique_ptr<TileStore> tile_store, |
| 32 | base::Clock* clock, |
Hesen Zhang | 70912aa | 2020-04-22 02:16:08 | [diff] [blame] | 33 | TileConfig* config); |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 34 | |
| 35 | // Initializes the query tile store, loading them into memory after |
| 36 | // validating. |
| 37 | virtual void Init(TileGroupStatusCallback callback) = 0; |
| 38 | |
| 39 | // Returns tiles to the caller. |
Hesen Zhang | 4f42c28 | 2020-04-28 21:00:24 | [diff] [blame] | 40 | virtual void GetTiles(GetTilesCallback callback) = 0; |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 41 | |
| 42 | // Save the query tiles into database. |
Hesen Zhang | 70912aa | 2020-04-22 02:16:08 | [diff] [blame] | 43 | virtual void SaveTiles(std::vector<std::unique_ptr<Tile>> top_level_tiles, |
| 44 | TileGroupStatusCallback callback) = 0; |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 45 | |
| 46 | TileManager(); |
| 47 | virtual ~TileManager() = default; |
| 48 | |
| 49 | TileManager(const TileManager& other) = delete; |
| 50 | TileManager& operator=(const TileManager& other) = delete; |
| 51 | }; |
| 52 | |
| 53 | } // namespace upboarding |
| 54 | |
Shakti Sahu | ce57c7d9 | 2020-04-29 01:47:17 | [diff] [blame^] | 55 | #endif // COMPONENTS_QUERY_TILES_INTERNAL_TILE_MANAGER_H_ |