Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: components/search_engines/template_url_data.h

Issue 1983773002: Cache SearchEngineType of TemplateURL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-extracting-terms-from-template-url
Patch Set: Move calculation to TemplateURLData Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_ 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_
6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_ 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "components/search_engines/search_engine_type.h"
13 #include "components/search_engines/template_url_id.h" 14 #include "components/search_engines/template_url_id.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
17 class SearchTermsData;
18 class TemplateURL;
19
16 // The data for the TemplateURL. Separating this into its own class allows most 20 // 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 21 // users to do SSA-style usage of TemplateURL: construct a TemplateURLData with
18 // whatever fields are desired, then create an immutable TemplateURL from it. 22 // whatever fields are desired, then create an immutable TemplateURL from it.
19 struct TemplateURLData { 23 struct TemplateURLData {
20 TemplateURLData(); 24 TemplateURLData();
21 TemplateURLData(const TemplateURLData& other); 25 TemplateURLData(const TemplateURLData& other);
22 ~TemplateURLData(); 26 ~TemplateURLData();
23 27
24 // A short description of the template. This is the name we show to the user 28 // A short description of the template. This is the name we show to the user
25 // in various places that use TemplateURLs. For example, the location bar 29 // in various places that use TemplateURLs. For example, the location bar
26 // shows this when the user selects a substituting match. 30 // shows this when the user selects a substituting match.
27 void SetShortName(const base::string16& short_name); 31 void SetShortName(const base::string16& short_name);
28 const base::string16& short_name() const { return short_name_; } 32 const base::string16& short_name() const { return short_name_; }
29 33
30 // The shortcut for this TemplateURL. |keyword| must be non-empty. 34 // The shortcut for this TemplateURL. |keyword| must be non-empty.
31 void SetKeyword(const base::string16& keyword); 35 void SetKeyword(const base::string16& keyword);
32 const base::string16& keyword() const { return keyword_; } 36 const base::string16& keyword() const { return keyword_; }
33 37
34 // The raw URL for the TemplateURL, which may not be valid as-is (e.g. because 38 // The raw URL for the TemplateURL, which may not be valid as-is (e.g. because
35 // it requires substitutions first). This must be non-empty. 39 // it requires substitutions first). This must be non-empty.
36 void SetURL(const std::string& url); 40 void SetURL(const std::string& url);
37 const std::string& url() const { return url_; } 41 const std::string& url() const { return url_; }
38 42
43 // Returns the type of this search engine, or SEARCH_ENGINE_OTHER if no
44 // engines match. |template_url_hint| is a TemplateURL which owns this
45 // TemplateURLData. If |template_url_hint| is nullptr it's ignored.
46 SearchEngineType GetEngineType(
47 const SearchTermsData& search_terms_data,
48 const TemplateURL* template_url_hint = nullptr) const;
Peter Kasting 2016/06/09 23:00:56 Supplying a null second arg is only used by one te
Vitaly Baranov 2016/06/12 07:29:15 Done.
49
39 // Optional additional raw URLs. 50 // Optional additional raw URLs.
40 std::string suggestions_url; 51 std::string suggestions_url;
41 std::string instant_url; 52 std::string instant_url;
42 std::string image_url; 53 std::string image_url;
43 std::string new_tab_url; 54 std::string new_tab_url;
44 std::string contextual_search_url; 55 std::string contextual_search_url;
45 56
46 // The following post_params are comma-separated lists used to specify the 57 // The following post_params are comma-separated lists used to specify the
47 // post parameters for the corresponding URL. 58 // post parameters for the corresponding URL.
48 std::string search_url_post_params; 59 std::string search_url_post_params;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // A parameter that, if present in the query or ref parameters of a search_url 124 // A parameter that, if present in the query or ref parameters of a search_url
114 // or instant_url, causes Chrome to replace the URL with the search term. 125 // or instant_url, causes Chrome to replace the URL with the search term.
115 std::string search_terms_replacement_key; 126 std::string search_terms_replacement_key;
116 127
117 private: 128 private:
118 // Private so we can enforce using the setters and thus enforce that these 129 // Private so we can enforce using the setters and thus enforce that these
119 // fields are never empty. 130 // fields are never empty.
120 base::string16 short_name_; 131 base::string16 short_name_;
121 base::string16 keyword_; 132 base::string16 keyword_;
122 std::string url_; 133 std::string url_;
134
135 // Mutable to allow GetEngineType() to assign it implicitly.
Peter Kasting 2016/06/09 23:00:56 Nit: This is sort of implied by the mutable keywor
Vitaly Baranov 2016/06/12 07:29:15 Done.
136 mutable SearchEngineType engine_type_;
123 }; 137 };
Peter Kasting 2016/06/09 23:00:56 NIt: While here: DISALLOW_COPY_AND_ASSIGN
Vitaly Baranov 2016/06/12 07:29:15 TemplateURLData has a copy constructor.
124 138
125 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_ 139 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698