Home | History | Annotate | Download | only in search_engines
      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.
      4 
      5 #ifndef CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_
      6 #define CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "base/strings/string16.h"
     13 
     14 class PrefRegistrySimple;
     15 class Profile;
     16 class TemplateURL;
     17 class TemplateURLService;
     18 class TemplateURLTableModel;
     19 
     20 class KeywordEditorController {
     21  public:
     22   explicit KeywordEditorController(Profile* profile);
     23   ~KeywordEditorController();
     24 
     25   static void RegisterPrefs(PrefRegistrySimple* registry);
     26 
     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);
     33 
     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);
     40 
     41   // Return true if the given |url| can be edited.
     42   bool CanEdit(const TemplateURL* url) const;
     43 
     44   // Return true if the given |url| can be made the default.
     45   bool CanMakeDefault(const TemplateURL* url) const;
     46 
     47   // Return true if the given |url| can be removed.
     48   bool CanRemove(const TemplateURL* url) const;
     49 
     50   // Remove the TemplateURL at the specified index in the TableModel.
     51   void RemoveTemplateURL(int index);
     52 
     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);
     56 
     57   // Return true if the |url_model_| data is loaded.
     58   bool loaded() const;
     59 
     60   // Return the TemplateURL corresponding to the |index| in the model.
     61   TemplateURL* GetTemplateURL(int index);
     62 
     63   TemplateURLTableModel* table_model() {
     64     return table_model_.get();
     65   }
     66 
     67   TemplateURLService* url_model() const;
     68 
     69  private:
     70   // The profile.
     71   Profile* profile_;
     72 
     73   // Model for the TableView.
     74   scoped_ptr<TemplateURLTableModel> table_model_;
     75 
     76   DISALLOW_COPY_AND_ASSIGN(KeywordEditorController);
     77 };
     78 
     79 #endif  // CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_
     80