Home | History | Annotate | Download | only in search_engines
      1 // Copyright (c) 2011 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 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/string16.h"
     14 
     15 class PrefService;
     16 class Profile;
     17 class TemplateURL;
     18 class TemplateURLModel;
     19 class TemplateURLTableModel;
     20 
     21 class KeywordEditorController {
     22  public:
     23   explicit KeywordEditorController(Profile* profile);
     24   ~KeywordEditorController();
     25 
     26   static void RegisterPrefs(PrefService* prefs);
     27 
     28   // Invoked when the user succesfully fills out the add keyword dialog.
     29   // Propagates the change to the TemplateURLModel and updates the table model.
     30   // Returns the index of the added URL.
     31   int AddTemplateURL(const string16& title,
     32                      const string16& keyword,
     33                      const std::string& url);
     34 
     35   // Invoked when the user modifies a TemplateURL. Updates the TemplateURLModel
     36   // and table model appropriately.
     37   void ModifyTemplateURL(const TemplateURL* template_url,
     38                          const string16& title,
     39                          const string16& keyword,
     40                          const std::string& url);
     41 
     42   // Return true if the given |url| can be edited.
     43   bool CanEdit(const TemplateURL* url) const;
     44 
     45   // Return true if the given |url| can be made the default.
     46   bool CanMakeDefault(const TemplateURL* url) const;
     47 
     48   // Return true if the given |url| can be removed.
     49   bool CanRemove(const TemplateURL* url) const;
     50 
     51   // Remove the TemplateURL at the specified index in the TableModel.
     52   void RemoveTemplateURL(int index);
     53 
     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);
     57 
     58   // Return true if the |url_model_| data is loaded.
     59   bool loaded() const;
     60 
     61   // Return the TemplateURL corresponding to the |index| in the model.
     62   const TemplateURL* GetTemplateURL(int index) const;
     63 
     64   TemplateURLTableModel* table_model() {
     65     return table_model_.get();
     66   }
     67 
     68   TemplateURLModel* url_model() const;
     69 
     70  private:
     71   // The profile.
     72   Profile* profile_;
     73 
     74   // Model for the TableView.
     75   scoped_ptr<TemplateURLTableModel> table_model_;
     76 
     77   DISALLOW_COPY_AND_ASSIGN(KeywordEditorController);
     78 };
     79 
     80 #endif  // CHROME_BROWSER_UI_SEARCH_ENGINES_KEYWORD_EDITOR_CONTROLLER_H_
     81