blob: e3b8886db8eef4f7e4acdb89466a58a0ce7183d5 [file] [log] [blame]
Hesen Zhang071689122020-04-21 22:02:241// 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 Sahuce57c7d92020-04-29 01:47:175#ifndef COMPONENTS_QUERY_TILES_INTERNAL_TILE_MANAGER_H_
6#define COMPONENTS_QUERY_TILES_INTERNAL_TILE_MANAGER_H_
Hesen Zhang071689122020-04-21 22:02:247
8#include <memory>
9#include <string>
10#include <vector>
11
12#include "base/callback.h"
13#include "base/time/clock.h"
Shakti Sahuce57c7d92020-04-29 01:47:1714#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 Zhang071689122020-04-21 22:02:2419
20namespace upboarding {
21
22// Manages the in-memory tile group and coordinates with storage layer.
23class TileManager {
24 public:
25 using TileStore = Store<TileGroup>;
26 using TileGroupStatusCallback = base::OnceCallback<void(TileGroupStatus)>;
Hesen Zhang4f42c282020-04-28 21:00:2427 using GetTilesCallback = base::OnceCallback<void(std::vector<Tile>)>;
Hesen Zhang071689122020-04-21 22:02:2428
29 // Creates the instance.
30 static std::unique_ptr<TileManager> Create(
31 std::unique_ptr<TileStore> tile_store,
32 base::Clock* clock,
Hesen Zhang70912aa2020-04-22 02:16:0833 TileConfig* config);
Hesen Zhang071689122020-04-21 22:02:2434
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 Zhang4f42c282020-04-28 21:00:2440 virtual void GetTiles(GetTilesCallback callback) = 0;
Hesen Zhang071689122020-04-21 22:02:2441
42 // Save the query tiles into database.
Hesen Zhang70912aa2020-04-22 02:16:0843 virtual void SaveTiles(std::vector<std::unique_ptr<Tile>> top_level_tiles,
44 TileGroupStatusCallback callback) = 0;
Hesen Zhang071689122020-04-21 22:02:2445
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 Sahuce57c7d92020-04-29 01:47:1755#endif // COMPONENTS_QUERY_TILES_INTERNAL_TILE_MANAGER_H_