blob: 15fbad023bb5c41e9a4ecb96720aba8468efce1a [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
16// The data for the TemplateURL. Separating this into its own class allows most
17// users to do SSA-style usage of TemplateURL: construct a TemplateURLData with
18// whatever fields are desired, then create an immutable TemplateURL from it.
19struct TemplateURLData {
20 TemplateURLData();
21 ~TemplateURLData();
22
23 // A short description of the template. This is the name we show to the user
24 // in various places that use TemplateURLs. For example, the location bar
25 // shows this when the user selects a substituting match.
mpearson3c6d7af2015-05-13 23:59:5326 void SetShortName(const base::string16& short_name);
27 const base::string16& short_name() const { return short_name_; }
[email protected]fa817b12014-06-11 06:25:2528
29 // The shortcut for this TemplateURL. |keyword| must be non-empty.
30 void SetKeyword(const base::string16& keyword);
31 const base::string16& keyword() const { return keyword_; }
32
33 // The raw URL for the TemplateURL, which may not be valid as-is (e.g. because
34 // it requires substitutions first). This must be non-empty.
35 void SetURL(const std::string& url);
36 const std::string& url() const { return url_; }
37
38 // Optional additional raw URLs.
39 std::string suggestions_url;
40 std::string instant_url;
41 std::string image_url;
42 std::string new_tab_url;
[email protected]448b17f52014-06-13 01:08:0343 std::string contextual_search_url;
[email protected]fa817b12014-06-11 06:25:2544
45 // The following post_params are comma-separated lists used to specify the
46 // post parameters for the corresponding URL.
47 std::string search_url_post_params;
48 std::string suggestions_url_post_params;
49 std::string instant_url_post_params;
50 std::string image_url_post_params;
51
52 // Optional favicon for the TemplateURL.
53 GURL favicon_url;
54
55 // URL to the OSD file this came from. May be empty.
56 GURL originating_url;
57
58 // Whether this TemplateURL is shown in the default list of search providers.
59 // This is just a property and does not indicate whether the TemplateURL has a
60 // TemplateURLRef that supports replacement. Use
61 // TemplateURL::ShowInDefaultList() to test both.
62 bool show_in_default_list;
63
64 // Whether it's safe for auto-modification code (the autogenerator and the
65 // code that imports data from other browsers) to replace the TemplateURL.
66 // This should be set to false for any TemplateURL the user edits, or any
67 // TemplateURL that the user clearly manually edited in the past, like a
68 // bookmark keyword from another browser.
69 bool safe_for_autoreplace;
70
71 // The list of supported encodings for the search terms. This may be empty,
72 // which indicates the terms should be encoded with UTF-8.
73 std::vector<std::string> input_encodings;
74
75 // Unique identifier of this TemplateURL. The unique ID is set by the
76 // TemplateURLService when the TemplateURL is added to it.
77 TemplateURLID id;
78
79 // Date this TemplateURL was created.
80 //
81 // NOTE: this may be 0, which indicates the TemplateURL was created before we
82 // started tracking creation time.
83 base::Time date_created;
84
85 // The last time this TemplateURL was modified by a user, since creation.
86 //
87 // NOTE: Like date_created above, this may be 0.
88 base::Time last_modified;
89
90 // True if this TemplateURL was automatically created by the administrator via
91 // group policy.
92 bool created_by_policy;
93
94 // Number of times this TemplateURL has been explicitly used to load a URL.
95 // We don't increment this for uses as the "default search engine" since
96 // that's not really "explicit" usage and incrementing would result in pinning
97 // the user's default search engine(s) to the top of the list of searches on
98 // the New Tab page, de-emphasizing the omnibox as "where you go to search".
99 int usage_count;
100
101 // If this TemplateURL comes from prepopulated data the prepopulate_id is > 0.
102 int prepopulate_id;
103
104 // The primary unique identifier for Sync. This set on all TemplateURLs
105 // regardless of whether they have been associated with Sync.
106 std::string sync_guid;
107
108 // A list of URL patterns that can be used, in addition to |url_|, to extract
109 // search terms from a URL.
110 std::vector<std::string> alternate_urls;
111
112 // A parameter that, if present in the query or ref parameters of a search_url
113 // or instant_url, causes Chrome to replace the URL with the search term.
114 std::string search_terms_replacement_key;
115
116 private:
117 // Private so we can enforce using the setters and thus enforce that these
118 // fields are never empty.
mpearson3c6d7af2015-05-13 23:59:53119 base::string16 short_name_;
[email protected]fa817b12014-06-11 06:25:25120 base::string16 keyword_;
121 std::string url_;
122};
123
124#endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_