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 
5 #ifndef COMPONENTS_QUERY_TILES_TILE_H_
6 #define COMPONENTS_QUERY_TILES_TILE_H_
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "base/time/time.h"
13 #include "url/gurl.h"
14 
15 namespace query_tiles {
16 
17 // Metadata of a tile image.
18 struct ImageMetadata {
19   ImageMetadata();
20   explicit ImageMetadata(const GURL& url);
21   ~ImageMetadata();
22   ImageMetadata(const ImageMetadata& other);
23   bool operator==(const ImageMetadata& other) const;
24 
25   // URL of the image.
26   GURL url;
27 };
28 
29 // Stats of a tile, used for ranking.
30 struct TileStats {
31   TileStats();
32   TileStats(base::Time last_clicked_time, double score);
33   ~TileStats();
34   TileStats(const TileStats& other);
35   bool operator==(const TileStats& other) const;
36 
37   // Last clicked timestamp.
38   base::Time last_clicked_time;
39 
40   // Score of the tile, used for ranking.
41   double score;
42 };
43 
44 // Represents the in memory structure of Tile.
45 struct Tile {
46   Tile();
47   ~Tile();
48   bool operator==(const Tile& other) const;
49   bool operator!=(const Tile& other) const;
50 
51   Tile(const Tile& other);
52   Tile(Tile&& other) noexcept;
53 
54   Tile& operator=(const Tile& other);
55   Tile& operator=(Tile&& other) noexcept;
56 
57   // Unique Id for each entry.
58   std::string id;
59 
60   // String of query that send to the search engine.
61   std::string query_text;
62 
63   // String of the text that displays in UI.
64   std::string display_text;
65 
66   // Text for accessibility purposes, in pair with |display_text|.
67   std::string accessibility_text;
68 
69   // A list of images's matadatas.
70   std::vector<ImageMetadata> image_metadatas;
71 
72   // A list of children of this tile.
73   std::vector<std::unique_ptr<Tile>> sub_tiles;
74 
75   // Additional params for search query.
76   std::vector<std::string> search_params;
77 
78   // Print pretty formatted content in Tile struct.
79   std::string DebugString();
80 };
81 
82 }  // namespace query_tiles
83 
84 #endif  // COMPONENTS_QUERY_TILES_TILE_H_
85