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