blob: d13c0e6ffedd30e6c18ee86e596ab22c3e30b95c [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"
Shakti Sahufe5a7bca2020-04-30 00:00:1413#include "base/optional.h"
Hesen Zhang071689122020-04-21 22:02:2414#include "base/time/clock.h"
Shakti Sahuce57c7d92020-04-29 01:47:1715#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
Xing Liu6d873212020-05-13 22:33:4920namespace query_tiles {
Hesen Zhang071689122020-04-21 22:02:2421
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>)>;
Shakti Sahufe5a7bca2020-04-30 00:00:1428 using TileCallback = base::OnceCallback<void(base::Optional<Tile>)>;
Hesen Zhang071689122020-04-21 22:02:2429
30 // Creates the instance.
31 static std::unique_ptr<TileManager> Create(
32 std::unique_ptr<TileStore> tile_store,
Min Qin7e9bd172020-05-12 23:20:1333 base::Clock* clock,
Min Qin80dc12c2020-05-14 15:13:0634 const std::string& accept_languages);
Hesen Zhang071689122020-04-21 22:02:2435
36 // Initializes the query tile store, loading them into memory after
37 // validating.
38 virtual void Init(TileGroupStatusCallback callback) = 0;
39
Min Qin7e9bd172020-05-12 23:20:1340 // Returns tiles to the caller in the given |locale|.
Hesen Zhang4f42c282020-04-28 21:00:2441 virtual void GetTiles(GetTilesCallback callback) = 0;
Hesen Zhang071689122020-04-21 22:02:2442
Shakti Sahufe5a7bca2020-04-30 00:00:1443 // Returns the tile associated with |tile_id| to the caller.
44 virtual void GetTile(const std::string& tile_id, TileCallback callback) = 0;
45
Hesen Zhang071689122020-04-21 22:02:2446 // Save the query tiles into database.
Hesen Zhangc34f49b2020-05-08 05:21:2547 virtual void SaveTiles(std::unique_ptr<TileGroup> tile_group,
Hesen Zhang70912aa2020-04-22 02:16:0848 TileGroupStatusCallback callback) = 0;
Hesen Zhang071689122020-04-21 22:02:2449
Min Qin80dc12c2020-05-14 15:13:0650 virtual void SetAcceptLanguagesForTesting(
51 const std::string& accept_languages) = 0;
Min Qin7e9bd172020-05-12 23:20:1352
Hesen Zhang071689122020-04-21 22:02:2453 TileManager();
54 virtual ~TileManager() = default;
55
56 TileManager(const TileManager& other) = delete;
57 TileManager& operator=(const TileManager& other) = delete;
58};
59
Xing Liu6d873212020-05-13 22:33:4960} // namespace query_tiles
Hesen Zhang071689122020-04-21 22:02:2461
Shakti Sahuce57c7d92020-04-29 01:47:1762#endif // COMPONENTS_QUERY_TILES_INTERNAL_TILE_MANAGER_H_