File: template_url_parser.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (66 lines) | stat: -rw-r--r-- 2,717 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_
#define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_

#include <stddef.h>

#include <memory>
#include <string>

#include "base/functional/callback.h"

class SearchTermsData;
class TemplateURL;

namespace data_decoder {
class DataDecoder;
}

// TemplateURLParser, as the name implies, handling reading of TemplateURLs
// from OpenSearch description documents.
class TemplateURLParser {
 public:
  // A ParameterFilter is called for every URL paramter encountered during
  // Parse(). It passes the parameter key as the first argument and the value
  // as the second. The callback should return true if the parameter should be
  // kept, and false if it should be discarded.
  using ParameterFilter =
      base::RepeatingCallback<bool(const std::string&, const std::string&)>;

  using ParseCallback = base::OnceCallback<void(std::unique_ptr<TemplateURL>)>;

  TemplateURLParser(const TemplateURLParser&) = delete;
  TemplateURLParser& operator=(const TemplateURLParser&) = delete;

  // Decodes the chunk of data representing a TemplateURL, creates the
  // TemplateURL, and calls the |completion_callback| with the result. A null
  // value is provided if the data does not describe a valid TemplateURL, the
  // URLs referenced do not point to valid http/https resources, or for some
  // other reason we do not support the described TemplateURL.
  // |parameter_filter| can be used if you want to filter some parameters out
  // of the URL. For example, when importing from another browser, we remove
  // any parameter identifying that browser. If set to null, the URL is not
  // modified.
  static void Parse(const SearchTermsData* search_terms_data,
                    const std::string& data,
                    const ParameterFilter& parameter_filter,
                    ParseCallback completion_callback);

  // The same as Parse(), but it allows the caller to manage the lifetime of
  // the DataDecoder service. The |data_decoder| must be kept alive until the
  // |completion_callback| is called.
  static void ParseWithDataDecoder(data_decoder::DataDecoder* data_decoder,
                                   const SearchTermsData* search_terms_data,
                                   const std::string& data,
                                   const ParameterFilter& parameter_filter,
                                   ParseCallback completion_callback);

 private:
  // No one should create one of these.
  TemplateURLParser();
};

#endif  // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_PARSER_H_