[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 1 | // 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-y | 6028ec2 | 2016-11-22 20:09:36 | [diff] [blame] | 16 | namespace base { |
| 17 | class ListValue; |
| 18 | } |
| 19 | |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 20 | // 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. |
| 23 | struct TemplateURLData { |
| 24 | TemplateURLData(); |
vmpstr | b6449d51 | 2016-02-25 23:55:40 | [diff] [blame] | 25 | TemplateURLData(const TemplateURLData& other); |
Denis Yaroshevskiy | 361a5932 | 2018-02-12 20:16:12 | [diff] [blame] | 26 | |
a-v-y | 6028ec2 | 2016-11-22 20:09:36 | [diff] [blame] | 27 | // 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-y | 6028ec2 | 2016-11-22 20:09:36 | [diff] [blame] | 37 | base::StringPiece image_url, |
| 38 | base::StringPiece new_tab_url, |
| 39 | base::StringPiece contextual_search_url, |
Bernhard Bauer | 41c477c1 | 2017-06-22 09:24:48 | [diff] [blame] | 40 | base::StringPiece logo_url, |
Marc Treib | 41ed19d | 2017-08-22 09:17:13 | [diff] [blame] | 41 | base::StringPiece doodle_url, |
a-v-y | 6028ec2 | 2016-11-22 20:09:36 | [diff] [blame] | 42 | base::StringPiece search_url_post_params, |
| 43 | base::StringPiece suggest_url_post_params, |
a-v-y | 6028ec2 | 2016-11-22 20:09:36 | [diff] [blame] | 44 | base::StringPiece image_url_post_params, |
| 45 | base::StringPiece favicon_url, |
| 46 | base::StringPiece encoding, |
| 47 | const base::ListValue& alternate_urls_list, |
a-v-y | 6028ec2 | 2016-11-22 20:09:36 | [diff] [blame] | 48 | int prepopulate_id); |
| 49 | |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 50 | ~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. |
mpearson | 3c6d7af | 2015-05-13 23:59:53 | [diff] [blame] | 55 | void SetShortName(const base::string16& short_name); |
| 56 | const base::string16& short_name() const { return short_name_; } |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 57 | |
| 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 Yaroshevskiy | 361a5932 | 2018-02-12 20:16:12 | [diff] [blame] | 67 | // Estimates dynamic memory usage. |
| 68 | // See base/trace_event/memory_usage_estimator.h for more info. |
| 69 | size_t EstimateMemoryUsage() const; |
| 70 | |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 71 | // Optional additional raw URLs. |
| 72 | std::string suggestions_url; |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 73 | std::string image_url; |
| 74 | std::string new_tab_url; |
[email protected] | 448b17f5 | 2014-06-13 01:08:03 | [diff] [blame] | 75 | std::string contextual_search_url; |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 76 | |
Bernhard Bauer | 41c477c1 | 2017-06-22 09:24:48 | [diff] [blame] | 77 | // Optional URL for the logo. |
| 78 | GURL logo_url; |
| 79 | |
Marc Treib | 41ed19d | 2017-08-22 09:17:13 | [diff] [blame] | 80 | // Optional URL for the Doodle. |
| 81 | GURL doodle_url; |
| 82 | |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 83 | // 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] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 87 | std::string image_url_post_params; |
| 88 | |
Bernhard Bauer | 41c477c1 | 2017-06-22 09:24:48 | [diff] [blame] | 89 | // Favicon for the TemplateURL. |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 90 | GURL favicon_url; |
| 91 | |
| 92 | // URL to the OSD file this came from. May be empty. |
| 93 | GURL originating_url; |
| 94 | |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 95 | // 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 | |
ltian | 8b5fc83 | 2016-12-02 23:43:35 | [diff] [blame] | 121 | // 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] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 126 | // 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] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 148 | private: |
| 149 | // Private so we can enforce using the setters and thus enforce that these |
| 150 | // fields are never empty. |
mpearson | 3c6d7af | 2015-05-13 23:59:53 | [diff] [blame] | 151 | base::string16 short_name_; |
[email protected] | fa817b1 | 2014-06-11 06:25:25 | [diff] [blame] | 152 | base::string16 keyword_; |
| 153 | std::string url_; |
| 154 | }; |
| 155 | |
| 156 | #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_ |