blob: 3d8c8a3efed796b04ae6f08b782179157ce5365e [file] [log] [blame]
[email protected]fa817b12014-06-11 06:25:251// Copyright 2014 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_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_
6#define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_
7
8#include <string>
9#include <vector>
10
11#include "base/strings/string16.h"
12#include "base/time/time.h"
13#include "components/search_engines/template_url_id.h"
14#include "url/gurl.h"
15
a-v-y6028ec22016-11-22 20:09:3616namespace base {
17class ListValue;
18}
19
[email protected]fa817b12014-06-11 06:25:2520// The data for the TemplateURL. Separating this into its own class allows most
21// users to do SSA-style usage of TemplateURL: construct a TemplateURLData with
22// whatever fields are desired, then create an immutable TemplateURL from it.
23struct TemplateURLData {
24 TemplateURLData();
vmpstrb6449d512016-02-25 23:55:4025 TemplateURLData(const TemplateURLData& other);
Denis Yaroshevskiy361a59322018-02-12 20:16:1226
a-v-y6028ec22016-11-22 20:09:3627 // Creates a TemplateURLData suitable for prepopulated engines.
28 // Note that unlike in the default constructor, |safe_for_autoreplace| will
29 // be set to true. date_created and last_modified will be set to null time
30 // value, instead of current time.
31 // StringPiece in arguments is used to pass const char* pointer members
32 // of PrepopulatedEngine structure which can be nullptr.
33 TemplateURLData(const base::string16& name,
34 const base::string16& keyword,
35 base::StringPiece search_url,
36 base::StringPiece suggest_url,
a-v-y6028ec22016-11-22 20:09:3637 base::StringPiece image_url,
38 base::StringPiece new_tab_url,
39 base::StringPiece contextual_search_url,
Bernhard Bauer41c477c12017-06-22 09:24:4840 base::StringPiece logo_url,
Marc Treib41ed19d2017-08-22 09:17:1341 base::StringPiece doodle_url,
a-v-y6028ec22016-11-22 20:09:3642 base::StringPiece search_url_post_params,
43 base::StringPiece suggest_url_post_params,
a-v-y6028ec22016-11-22 20:09:3644 base::StringPiece image_url_post_params,
45 base::StringPiece favicon_url,
46 base::StringPiece encoding,
47 const base::ListValue& alternate_urls_list,
a-v-y6028ec22016-11-22 20:09:3648 int prepopulate_id);
49
[email protected]fa817b12014-06-11 06:25:2550 ~TemplateURLData();
51
52 // A short description of the template. This is the name we show to the user
53 // in various places that use TemplateURLs. For example, the location bar
54 // shows this when the user selects a substituting match.
mpearson3c6d7af2015-05-13 23:59:5355 void SetShortName(const base::string16& short_name);
56 const base::string16& short_name() const { return short_name_; }
[email protected]fa817b12014-06-11 06:25:2557
58 // The shortcut for this TemplateURL. |keyword| must be non-empty.
59 void SetKeyword(const base::string16& keyword);
60 const base::string16& keyword() const { return keyword_; }
61
62 // The raw URL for the TemplateURL, which may not be valid as-is (e.g. because
63 // it requires substitutions first). This must be non-empty.
64 void SetURL(const std::string& url);
65 const std::string& url() const { return url_; }
66
Denis Yaroshevskiy361a59322018-02-12 20:16:1267 // Estimates dynamic memory usage.
68 // See base/trace_event/memory_usage_estimator.h for more info.
69 size_t EstimateMemoryUsage() const;
70
[email protected]fa817b12014-06-11 06:25:2571 // Optional additional raw URLs.
72 std::string suggestions_url;
[email protected]fa817b12014-06-11 06:25:2573 std::string image_url;
74 std::string new_tab_url;
[email protected]448b17f52014-06-13 01:08:0375 std::string contextual_search_url;
[email protected]fa817b12014-06-11 06:25:2576
Bernhard Bauer41c477c12017-06-22 09:24:4877 // Optional URL for the logo.
78 GURL logo_url;
79
Marc Treib41ed19d2017-08-22 09:17:1380 // Optional URL for the Doodle.
81 GURL doodle_url;
82
[email protected]fa817b12014-06-11 06:25:2583 // The following post_params are comma-separated lists used to specify the
84 // post parameters for the corresponding URL.
85 std::string search_url_post_params;
86 std::string suggestions_url_post_params;
[email protected]fa817b12014-06-11 06:25:2587 std::string image_url_post_params;
88
Bernhard Bauer41c477c12017-06-22 09:24:4889 // Favicon for the TemplateURL.
[email protected]fa817b12014-06-11 06:25:2590 GURL favicon_url;
91
92 // URL to the OSD file this came from. May be empty.
93 GURL originating_url;
94
[email protected]fa817b12014-06-11 06:25:2595 // Whether it's safe for auto-modification code (the autogenerator and the
96 // code that imports data from other browsers) to replace the TemplateURL.
97 // This should be set to false for any TemplateURL the user edits, or any
98 // TemplateURL that the user clearly manually edited in the past, like a
99 // bookmark keyword from another browser.
100 bool safe_for_autoreplace;
101
102 // The list of supported encodings for the search terms. This may be empty,
103 // which indicates the terms should be encoded with UTF-8.
104 std::vector<std::string> input_encodings;
105
106 // Unique identifier of this TemplateURL. The unique ID is set by the
107 // TemplateURLService when the TemplateURL is added to it.
108 TemplateURLID id;
109
110 // Date this TemplateURL was created.
111 //
112 // NOTE: this may be 0, which indicates the TemplateURL was created before we
113 // started tracking creation time.
114 base::Time date_created;
115
116 // The last time this TemplateURL was modified by a user, since creation.
117 //
118 // NOTE: Like date_created above, this may be 0.
119 base::Time last_modified;
120
ltian8b5fc832016-12-02 23:43:35121 // Date when this TemplateURL was last visited.
122 //
123 // NOTE: This might be 0 if the TemplateURL has never been visited.
124 base::Time last_visited;
125
[email protected]fa817b12014-06-11 06:25:25126 // True if this TemplateURL was automatically created by the administrator via
127 // group policy.
128 bool created_by_policy;
129
130 // Number of times this TemplateURL has been explicitly used to load a URL.
131 // We don't increment this for uses as the "default search engine" since
132 // that's not really "explicit" usage and incrementing would result in pinning
133 // the user's default search engine(s) to the top of the list of searches on
134 // the New Tab page, de-emphasizing the omnibox as "where you go to search".
135 int usage_count;
136
137 // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0.
138 int prepopulate_id;
139
140 // The primary unique identifier for Sync. This set on all TemplateURLs
141 // regardless of whether they have been associated with Sync.
142 std::string sync_guid;
143
144 // A list of URL patterns that can be used, in addition to |url_|, to extract
145 // search terms from a URL.
146 std::vector<std::string> alternate_urls;
147
[email protected]fa817b12014-06-11 06:25:25148 private:
149 // Private so we can enforce using the setters and thus enforce that these
150 // fields are never empty.
mpearson3c6d7af2015-05-13 23:59:53151 base::string16 short_name_;
[email protected]fa817b12014-06-11 06:25:25152 base::string16 keyword_;
153 std::string url_;
154};
155
156#endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_