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" |
Shakti Sahu | fe5a7bca | 2020-04-30 00:00:14 | [diff] [blame] | 13 | #include "base/optional.h" |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 14 | #include "base/time/clock.h" |
Shakti Sahu | ce57c7d9 | 2020-04-29 01:47:17 | [diff] [blame] | 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 | |
Xing Liu | 6d87321 | 2020-05-13 22:33:49 | [diff] [blame] | 20 | namespace query_tiles { |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 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>)>; |
Shakti Sahu | fe5a7bca | 2020-04-30 00:00:14 | [diff] [blame] | 28 | using TileCallback = base::OnceCallback<void(base::Optional<Tile>)>; |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 29 | |
| 30 | // Creates the instance. |
| 31 | static std::unique_ptr<TileManager> Create( |
| 32 | std::unique_ptr<TileStore> tile_store, |
Min Qin | 7e9bd17 | 2020-05-12 23:20:13 | [diff] [blame] | 33 | base::Clock* clock, |
Min Qin | 80dc12c | 2020-05-14 15:13:06 | [diff] [blame^] | 34 | const std::string& accept_languages); |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 35 | |
| 36 | // Initializes the query tile store, loading them into memory after |
| 37 | // validating. |
| 38 | virtual void Init(TileGroupStatusCallback callback) = 0; |
| 39 | |
Min Qin | 7e9bd17 | 2020-05-12 23:20:13 | [diff] [blame] | 40 | // Returns tiles to the caller in the given |locale|. |
Hesen Zhang | 4f42c28 | 2020-04-28 21:00:24 | [diff] [blame] | 41 | virtual void GetTiles(GetTilesCallback callback) = 0; |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 42 | |
Shakti Sahu | fe5a7bca | 2020-04-30 00:00:14 | [diff] [blame] | 43 | // Returns the tile associated with |tile_id| to the caller. |
| 44 | virtual void GetTile(const std::string& tile_id, TileCallback callback) = 0; |
| 45 | |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 46 | // Save the query tiles into database. |
Hesen Zhang | c34f49b | 2020-05-08 05:21:25 | [diff] [blame] | 47 | virtual void SaveTiles(std::unique_ptr<TileGroup> tile_group, |
Hesen Zhang | 70912aa | 2020-04-22 02:16:08 | [diff] [blame] | 48 | TileGroupStatusCallback callback) = 0; |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 49 | |
Min Qin | 80dc12c | 2020-05-14 15:13:06 | [diff] [blame^] | 50 | virtual void SetAcceptLanguagesForTesting( |
| 51 | const std::string& accept_languages) = 0; |
Min Qin | 7e9bd17 | 2020-05-12 23:20:13 | [diff] [blame] | 52 | |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 53 | TileManager(); |
| 54 | virtual ~TileManager() = default; |
| 55 | |
| 56 | TileManager(const TileManager& other) = delete; |
| 57 | TileManager& operator=(const TileManager& other) = delete; |
| 58 | }; |
| 59 | |
Xing Liu | 6d87321 | 2020-05-13 22:33:49 | [diff] [blame] | 60 | } // namespace query_tiles |
Hesen Zhang | 07168912 | 2020-04-21 22:02:24 | [diff] [blame] | 61 | |
Shakti Sahu | ce57c7d9 | 2020-04-29 01:47:17 | [diff] [blame] | 62 | #endif // COMPONENTS_QUERY_TILES_INTERNAL_TILE_MANAGER_H_ |