Home | History | Annotate | Download | only in search
      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_SEARCH_MODEL_H_
      6 #define CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/observer_list.h"
     10 #include "chrome/common/search_types.h"
     11 
     12 class SearchModelObserver;
     13 
     14 // Represents whether a page supports Instant.
     15 enum InstantSupportState {
     16   INSTANT_SUPPORT_NO,
     17   INSTANT_SUPPORT_YES,
     18   INSTANT_SUPPORT_UNKNOWN,
     19 };
     20 
     21 // An observable model for UI components that care about search model state
     22 // changes.
     23 class SearchModel {
     24  public:
     25   struct State {
     26     State();
     27     State(const SearchMode& mode,
     28           InstantSupportState instant_support,
     29           bool voice_search_supported);
     30 
     31     bool operator==(const State& rhs) const;
     32 
     33     // The display mode of UI elements such as the toolbar, the tab strip, etc.
     34     SearchMode mode;
     35 
     36     // Does the current page support Instant?
     37     InstantSupportState instant_support;
     38 
     39     // Does the current page support voice search?
     40     bool voice_search_supported;
     41   };
     42 
     43   SearchModel();
     44   ~SearchModel();
     45 
     46   // Change the state.  Change notifications are sent to observers.
     47   void SetState(const State& state);
     48 
     49   // Get the current state.
     50   const State& state() const { return state_; }
     51 
     52   // Change the mode.  Change notifications are sent to observers.
     53   void SetMode(const SearchMode& mode);
     54 
     55   // Get the active mode.
     56   const SearchMode& mode() const { return state_.mode; }
     57 
     58   // Sets the page instant support state. Change notifications are sent to
     59   // observers.
     60   void SetInstantSupportState(InstantSupportState instant_support);
     61 
     62   // Gets the instant support state of the page.
     63   InstantSupportState instant_support() const {
     64     return state_.instant_support;
     65   }
     66 
     67   // Sets the page voice search support state.  Change notifications are sent to
     68   // observers.
     69   void SetVoiceSearchSupported(bool supported);
     70 
     71   // Gets the voice search support state of the page.
     72   bool voice_search_supported() const { return state_.voice_search_supported; }
     73 
     74   // Add and remove observers.
     75   void AddObserver(SearchModelObserver* observer);
     76   void RemoveObserver(SearchModelObserver* observer);
     77 
     78  private:
     79   // Current state of model.
     80   State state_;
     81 
     82   // Observers.
     83   ObserverList<SearchModelObserver> observers_;
     84 
     85   DISALLOW_COPY_AND_ASSIGN(SearchModel);
     86 };
     87 
     88 #endif  // CHROME_BROWSER_UI_SEARCH_SEARCH_MODEL_H_
     89