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 // Invoked when the user succesfully fills out the add keyword dialog.
26 // Propagates the change to the TemplateURLService and updates the table
27 // model. Returns the index of the added URL.
28 int AddTemplateURL(const base::string16
& title
,
29 const base::string16
& keyword
,
30 const std::string
& url
);
32 // Invoked when the user modifies a TemplateURL. Updates the
33 // TemplateURLService and table model appropriately.
34 void ModifyTemplateURL(TemplateURL
* template_url
,
35 const base::string16
& title
,
36 const base::string16
& keyword
,
37 const std::string
& url
);
39 // Return true if the given |url| can be edited.
40 bool CanEdit(const TemplateURL
* url
) const;
42 // Return true if the given |url| can be made the default.
43 bool CanMakeDefault(const TemplateURL
* url
) const;
45 // Return true if the given |url| can be removed.
46 bool CanRemove(const TemplateURL
* url
) const;
48 // Remove the TemplateURL at the specified index in the TableModel.
49 void RemoveTemplateURL(int index
);
51 // Returns the default search provider.
52 TemplateURL
* GetDefaultSearchProvider();
54 // Make the TemplateURL at the specified index (into the TableModel) the
55 // default search provider. Return the new index, or -1 if nothing was done.
56 int MakeDefaultTemplateURL(int index
);
58 // Return true if the |url_model_| data is loaded.
61 // Return the TemplateURL corresponding to the |index| in the model.
62 TemplateURL
* GetTemplateURL(int index
);
64 TemplateURLTableModel
* table_model() {
65 return table_model_
.get();
69 TemplateURLService
* url_model_
;
71 // Model for the TableView.
72 scoped_ptr
<TemplateURLTableModel
> table_model_
;
74 DISALLOW_COPY_AND_ASSIGN(KeywordEditorController
);
77 #endif // CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_