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_KEYWORD_EDITOR_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
14 class PrefRegistrySimple
;
17 class TemplateURLService
;
18 class TemplateURLTableModel
;
20 class KeywordEditorController
{
22 explicit KeywordEditorController(Profile
* profile
);
23 ~KeywordEditorController();
25 static void RegisterPrefs(PrefRegistrySimple
* registry
);
27 // Invoked when the user succesfully fills out the add keyword dialog.
28 // Propagates the change to the TemplateURLService and updates the table
29 // model. Returns the index of the added URL.
30 int AddTemplateURL(const base::string16
& title
,
31 const base::string16
& keyword
,
32 const std::string
& url
);
34 // Invoked when the user modifies a TemplateURL. Updates the
35 // TemplateURLService and table model appropriately.
36 void ModifyTemplateURL(TemplateURL
* template_url
,
37 const base::string16
& title
,
38 const base::string16
& keyword
,
39 const std::string
& url
);
41 // Return true if the given |url| can be edited.
42 bool CanEdit(const TemplateURL
* url
) const;
44 // Return true if the given |url| can be made the default.
45 bool CanMakeDefault(const TemplateURL
* url
) const;
47 // Return true if the given |url| can be removed.
48 bool CanRemove(const TemplateURL
* url
) const;
50 // Remove the TemplateURL at the specified index in the TableModel.
51 void RemoveTemplateURL(int index
);
53 // Make the TemplateURL at the specified index (into the TableModel) the
54 // default search provider. Return the new index, or -1 if nothing was done.
55 int MakeDefaultTemplateURL(int index
);
57 // Return true if the |url_model_| data is loaded.
60 // Return the TemplateURL corresponding to the |index| in the model.
61 TemplateURL
* GetTemplateURL(int index
);
63 TemplateURLTableModel
* table_model() {
64 return table_model_
.get();
67 TemplateURLService
* url_model() const;
73 // Model for the TableView.
74 scoped_ptr
<TemplateURLTableModel
> table_model_
;
76 DISALLOW_COPY_AND_ASSIGN(KeywordEditorController
);
79 #endif // CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_