template_url_parser.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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 CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_
6#define CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11
12class TemplateURL;
13
14// TemplateURLParser, as the name implies, handling reading of TemplateURLs
15// from OpenSearch description documents.
16class TemplateURLParser {
17 public:
18  class ParameterFilter {
19   public:
20    // Invoked for each parameter of the template URL while parsing.  If this
21    // methods returns false, the parameter is not included.
22    virtual bool KeepParameter(const std::string& key,
23                               const std::string& value) = 0;
24  };
25  // Decodes the chunk of data representing a TemplateURL. If data does
26  // not describe a valid TemplateURL false is returned. Additionally, if the
27  // URLs referenced do not point to valid http/https resources, false is
28  // returned. |parameter_filter| can be used if you want to filter out some
29  // parameters out of the URL. For example when importing from another browser
30  // we remove any parameter identifying that browser.  If set to NULL, the URL
31  // is not modified.
32  //
33  // NOTE: This does not clear all values of the supplied TemplateURL; it's
34  // expected callers will supply a new TemplateURL to this method.
35  static bool Parse(const unsigned char* data,
36                    size_t length,
37                    ParameterFilter* parameter_filter,
38                    TemplateURL* url);
39
40 private:
41  // No one should create one of these.
42  TemplateURLParser();
43
44  DISALLOW_COPY_AND_ASSIGN(TemplateURLParser);
45};
46
47#endif  // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_
48