Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / search_engines / edit_search_engine_controller.h
blobb1d988d74a41a0f057c5a31c44544db67a1fabb7
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_
8 #include <string>
10 #include "base/strings/string16.h"
11 #include "ui/gfx/native_widget_types.h"
13 class Profile;
14 class TemplateURL;
16 class EditSearchEngineControllerDelegate {
17 public:
18 // Invoked from the EditSearchEngineController when the user accepts the
19 // edits. NOTE: |template_url| is the value supplied to
20 // EditSearchEngineController's constructor, and may be NULL. A NULL value
21 // indicates a new TemplateURL should be created rather than modifying an
22 // existing TemplateURL.
23 virtual void OnEditedKeyword(TemplateURL* template_url,
24 const base::string16& title,
25 const base::string16& keyword,
26 const std::string& url) = 0;
28 protected:
29 virtual ~EditSearchEngineControllerDelegate() {}
32 // EditSearchEngineController provides the core platform independent logic
33 // for the Edit Search Engine dialog.
34 class EditSearchEngineController {
35 public:
36 // The |template_url| and/or |edit_keyword_delegate| may be NULL.
37 EditSearchEngineController(
38 TemplateURL* template_url,
39 EditSearchEngineControllerDelegate* edit_keyword_delegate,
40 Profile* profile);
41 ~EditSearchEngineController() {}
43 // Returns true if the value of |title_input| is a valid search engine name.
44 bool IsTitleValid(const base::string16& title_input) const;
46 // Returns true if the value of |url_input| represents a valid search engine
47 // URL. The URL is valid if it contains no search terms and is a valid
48 // url, or if it contains a search term and replacing that search term with a
49 // character results in a valid url.
50 bool IsURLValid(const std::string& url_input) const;
52 // Returns true if the value of |keyword_input| represents a valid keyword.
53 // The keyword is valid if it is non-empty and does not conflict with an
54 // existing entry. NOTE: this is just the keyword, not the title and url.
55 bool IsKeywordValid(const base::string16& keyword_input) const;
57 // Completes the add or edit of a search engine.
58 void AcceptAddOrEdit(const base::string16& title_input,
59 const base::string16& keyword_input,
60 const std::string& url_input);
62 // Deletes an unused TemplateURL, if its add was cancelled and it's not
63 // already owned by the TemplateURLService.
64 void CleanUpCancelledAdd();
66 // Accessors.
67 const TemplateURL* template_url() const { return template_url_; }
68 Profile* profile() const { return profile_; }
70 private:
71 // Fixes up and returns the URL the user has input. The returned URL is
72 // suitable for use by TemplateURL.
73 std::string GetFixedUpURL(const std::string& url_input) const;
75 // The TemplateURL we're displaying information for. It may be NULL. If we
76 // have a keyword_editor_view, we assume that this TemplateURL is already in
77 // the TemplateURLService; if not, we assume it isn't.
78 TemplateURL* template_url_;
80 // We may have been created by this, in which case we will call back to it on
81 // success to add/modify the entry. May be NULL.
82 EditSearchEngineControllerDelegate* edit_keyword_delegate_;
84 // Profile whose TemplateURLService we're modifying.
85 Profile* profile_;
87 DISALLOW_COPY_AND_ASSIGN(EditSearchEngineController);
90 #endif // CHROME_BROWSER_UI_SEARCH_ENGINES_EDIT_SEARCH_ENGINE_CONTROLLER_H_