OLD | NEW |
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_PARSER_H_ | 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_ |
6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_ | 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 | 14 |
14 class SearchTermsData; | 15 class SearchTermsData; |
15 class TemplateURL; | 16 class TemplateURL; |
16 | 17 |
17 // TemplateURLParser, as the name implies, handling reading of TemplateURLs | 18 // TemplateURLParser, as the name implies, handling reading of TemplateURLs |
18 // from OpenSearch description documents. | 19 // from OpenSearch description documents. |
19 class TemplateURLParser { | 20 class TemplateURLParser { |
20 public: | 21 public: |
21 class ParameterFilter { | 22 class ParameterFilter { |
22 public: | 23 public: |
23 // Invoked for each parameter of the template URL while parsing. If this | 24 // Invoked for each parameter of the template URL while parsing. If this |
24 // methods returns false, the parameter is not included. | 25 // methods returns false, the parameter is not included. |
25 virtual bool KeepParameter(const std::string& key, | 26 virtual bool KeepParameter(const std::string& key, |
26 const std::string& value) = 0; | 27 const std::string& value) = 0; |
27 | 28 |
28 protected: | 29 protected: |
29 virtual ~ParameterFilter() {} | 30 virtual ~ParameterFilter() {} |
30 }; | 31 }; |
31 | 32 |
32 // Decodes the chunk of data representing a TemplateURL, creates the | 33 // Decodes the chunk of data representing a TemplateURL, creates the |
33 // TemplateURL, and returns it. The caller owns the returned object. | 34 // TemplateURL, and returns it. Returns null if the data does not describe a |
34 // Returns NULL if data does not describe a valid TemplateURL, the | 35 // valid TemplateURL, the URLs referenced do not point to valid http/https |
35 // URLs referenced do not point to valid http/https resources, or for some | 36 // resources, or for some other reason we do not support the described |
36 // other reason we do not support the described TemplateURL. | 37 // TemplateURL. |parameter_filter| can be used if you want to filter some |
37 // |parameter_filter| can be used if you want to filter some parameters out of | 38 // parameters out of the URL. For example, when importing from another |
38 // the URL. For example, when importing from another browser, we remove any | 39 // browser, we remove any parameter identifying that browser. If set to null, |
39 // parameter identifying that browser. If set to NULL, the URL is not | 40 // the URL is not modified. |
40 // modified. | 41 static std::unique_ptr<TemplateURL> Parse( |
41 static TemplateURL* Parse(const SearchTermsData& search_terms_data, | 42 const SearchTermsData& search_terms_data, |
42 bool show_in_default_list, | 43 bool show_in_default_list, |
43 const char* data, | 44 const char* data, |
44 size_t length, | 45 size_t length, |
45 ParameterFilter* parameter_filter); | 46 ParameterFilter* parameter_filter); |
46 | 47 |
47 private: | 48 private: |
48 // No one should create one of these. | 49 // No one should create one of these. |
49 TemplateURLParser(); | 50 TemplateURLParser(); |
50 | 51 |
51 DISALLOW_COPY_AND_ASSIGN(TemplateURLParser); | 52 DISALLOW_COPY_AND_ASSIGN(TemplateURLParser); |
52 }; | 53 }; |
53 | 54 |
54 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_ | 55 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_ |
OLD | NEW |