Home | History | Annotate | Download | only in omnibox
      1 // Copyright 2013 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_OMNIBOX_OMNIBOX_CONTROLLER_H_
      6 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/compiler_specific.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/strings/string16.h"
     12 #include "chrome/browser/autocomplete/autocomplete_controller.h"
     13 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
     14 #include "components/omnibox/autocomplete_match.h"
     15 
     16 class AUtocompleteInput;
     17 struct AutocompleteMatch;
     18 class AutocompleteResult;
     19 class InstantController;
     20 class OmniboxEditModel;
     21 class OmniboxPopupModel;
     22 class Profile;
     23 
     24 namespace gfx {
     25 class Rect;
     26 }
     27 
     28 // This class controls the various services that can modify the content
     29 // for the omnibox, including AutocompleteController and InstantController. It
     30 // is responsible of updating the omnibox content.
     31 // TODO(beaudoin): Keep on expanding this class so that OmniboxEditModel no
     32 //     longer needs to hold any reference to AutocompleteController. Also make
     33 //     this the point of contact between InstantController and OmniboxEditModel.
     34 //     As the refactor progresses, keep the class comment up-to-date to
     35 //     precisely explain what this class is doing.
     36 class OmniboxController : public AutocompleteControllerDelegate {
     37  public:
     38   OmniboxController(OmniboxEditModel* omnibox_edit_model,
     39                     Profile* profile);
     40   virtual ~OmniboxController();
     41 
     42   // The |current_url| field of input is only set for mobile ports.
     43   void StartAutocomplete(const AutocompleteInput& input) const;
     44 
     45   // AutocompleteControllerDelegate:
     46   virtual void OnResultChanged(bool default_match_changed) OVERRIDE;
     47 
     48   AutocompleteController* autocomplete_controller() {
     49     return autocomplete_controller_.get();
     50   }
     51 
     52   // Set |current_match_| to an invalid value, indicating that we do not yet
     53   // have a valid match for the current text in the omnibox.
     54   void InvalidateCurrentMatch();
     55 
     56   void set_popup_model(OmniboxPopupModel* popup_model) {
     57     popup_ = popup_model;
     58   }
     59 
     60   // TODO(beaudoin): The edit and popup model should be siblings owned by the
     61   // LocationBarView, making this accessor unnecessary.
     62   OmniboxPopupModel* popup_model() const { return popup_; }
     63 
     64   const AutocompleteMatch& current_match() const { return current_match_; }
     65 
     66   // Turns off keyword mode for the current match.
     67   void ClearPopupKeywordMode() const;
     68 
     69   const AutocompleteResult& result() const {
     70     return autocomplete_controller_->result();
     71   }
     72 
     73   // TODO(beaudoin): Make private once OmniboxEditModel no longer refers to it.
     74   void DoPreconnect(const AutocompleteMatch& match);
     75 
     76  private:
     77   // Weak, it owns us.
     78   // TODO(beaudoin): Consider defining a delegate to ease unit testing.
     79   OmniboxEditModel* omnibox_edit_model_;
     80 
     81   Profile* profile_;
     82 
     83   OmniboxPopupModel* popup_;
     84 
     85   scoped_ptr<AutocompleteController> autocomplete_controller_;
     86 
     87   // TODO(beaudoin): This AutocompleteMatch is used to let the OmniboxEditModel
     88   // know what it should display. Not every field is required for that purpose,
     89   // but the ones specifically needed are unclear. We should therefore spend
     90   // some time to extract these fields and use a tighter structure here.
     91   AutocompleteMatch current_match_;
     92 
     93   DISALLOW_COPY_AND_ASSIGN(OmniboxController);
     94 };
     95 
     96 #endif  // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_CONTROLLER_H_
     97