File: edit_search_engine_controller.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 (92 lines) | stat: -rw-r--r-- 3,747 bytes parent folder | download | duplicates (5)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_
#define CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_

#include <string>

#include "base/memory/raw_ptr.h"

class Profile;
class TemplateURL;

class EditSearchEngineControllerDelegate {
 public:
  // Invoked from the EditSearchEngineController when the user accepts the
  // edits. NOTE: |template_url| is the value supplied to
  // EditSearchEngineController's constructor, and may be nullptr. A nullptr
  // value indicates a new TemplateURL should be created rather than modifying
  // an existing TemplateURL.
  virtual void OnEditedKeyword(TemplateURL* template_url,
                               const std::u16string& title,
                               const std::u16string& keyword,
                               const std::string& url) = 0;

 protected:
  virtual ~EditSearchEngineControllerDelegate() = default;
};

// EditSearchEngineController provides the core platform independent logic
// for the Edit Search Engine dialog.
class EditSearchEngineController {
 public:
  // The |template_url| and/or |edit_keyword_delegate| may be nullptr.
  EditSearchEngineController(
      TemplateURL* template_url,
      EditSearchEngineControllerDelegate* edit_keyword_delegate,
      Profile* profile);

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

  ~EditSearchEngineController() = default;

  // Returns true if the value of |title_input| is a valid search engine name.
  bool IsTitleValid(const std::u16string& title_input) const;

  // Returns true if the value of |url_input| represents a valid search engine
  // URL. The URL is valid if it contains no search terms and is a valid
  // url, or if it contains a search term and replacing that search term with a
  // character results in a valid url.
  bool IsURLValid(const std::string& url_input) const;

  // Returns true if the value of |keyword_input| represents a valid keyword.
  // The keyword is valid if it is non-empty and does not conflict with an
  // existing entry. NOTE: this is just the keyword, not the title and url.
  bool IsKeywordValid(const std::u16string& keyword_input) const;

  // Completes the add or edit of a search engine.
  void AcceptAddOrEdit(const std::u16string& title_input,
                       const std::u16string& keyword_input,
                       const std::string& url_input);

  // Deletes an unused TemplateURL, if its add was cancelled and it's not
  // already owned by the TemplateURLService.
  void CleanUpCancelledAdd();

  // Accessors.
  const TemplateURL* template_url() const { return template_url_; }
  Profile* profile() const { return profile_; }

 private:
  // Fixes up and returns the URL the user has input. The returned URL is
  // suitable for use by TemplateURL.
  std::string GetFixedUpURL(const std::string& url_input) const;

  // The TemplateURL we're displaying information for. It may be nullptr. If we
  // have a keyword_editor_view, we assume that this TemplateURL is already in
  // the TemplateURLService; if not, we assume it isn't.
  raw_ptr<TemplateURL> template_url_;

  // We may have been created by this, in which case we will call back to it on
  // success to add/modify the entry.  May be nullptr.
  raw_ptr<EditSearchEngineControllerDelegate> edit_keyword_delegate_;

  // Profile whose TemplateURLService we're modifying.
  raw_ptr<Profile> profile_;
};

#endif  // CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_