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 #include "chrome/browser/ui/search/search_model.h" 6 7 #include "chrome/browser/search/search.h" 8 #include "chrome/browser/ui/search/search_model_observer.h" 9 10 SearchModel::State::State() 11 : instant_support(INSTANT_SUPPORT_UNKNOWN), 12 voice_search_supported(false) { 13 } 14 15 SearchModel::State::State(const SearchMode& mode, 16 InstantSupportState instant_support, 17 bool voice_search_supported) 18 : mode(mode), 19 instant_support(instant_support), 20 voice_search_supported(voice_search_supported) { 21 } 22 23 bool SearchModel::State::operator==(const State& rhs) const { 24 return mode == rhs.mode && instant_support == rhs.instant_support && 25 voice_search_supported == rhs.voice_search_supported; 26 } 27 28 SearchModel::SearchModel() { 29 } 30 31 SearchModel::~SearchModel() { 32 } 33 34 void SearchModel::SetState(const State& new_state) { 35 DCHECK(chrome::IsInstantExtendedAPIEnabled()) 36 << "Please do not try to set the SearchModel mode without first " 37 << "checking if Search is enabled."; 38 39 if (state_ == new_state) 40 return; 41 42 const State old_state = state_; 43 state_ = new_state; 44 45 FOR_EACH_OBSERVER(SearchModelObserver, observers_, 46 ModelChanged(old_state, state_)); 47 } 48 49 void SearchModel::SetMode(const SearchMode& new_mode) { 50 DCHECK(chrome::IsInstantExtendedAPIEnabled()) 51 << "Please do not try to set the SearchModel mode without first " 52 << "checking if Search is enabled."; 53 54 if (state_.mode == new_mode) 55 return; 56 57 const State old_state = state_; 58 state_.mode = new_mode; 59 60 FOR_EACH_OBSERVER(SearchModelObserver, observers_, 61 ModelChanged(old_state, state_)); 62 } 63 64 void SearchModel::SetInstantSupportState(InstantSupportState instant_support) { 65 DCHECK(chrome::IsInstantExtendedAPIEnabled()) 66 << "Please do not try to set the SearchModel state without first " 67 << "checking if Search is enabled."; 68 69 if (state_.instant_support == instant_support) 70 return; 71 72 const State old_state = state_; 73 state_.instant_support = instant_support; 74 FOR_EACH_OBSERVER(SearchModelObserver, observers_, 75 ModelChanged(old_state, state_)); 76 } 77 78 void SearchModel::SetVoiceSearchSupported(bool supported) { 79 DCHECK(chrome::IsInstantExtendedAPIEnabled()) 80 << "Please do not try to set the SearchModel state without first " 81 << "checking if Search is enabled."; 82 83 if (state_.voice_search_supported == supported) 84 return; 85 86 const State old_state = state_; 87 state_.voice_search_supported = supported; 88 89 FOR_EACH_OBSERVER(SearchModelObserver, observers_, 90 ModelChanged(old_state, state_)); 91 } 92 93 void SearchModel::AddObserver(SearchModelObserver* observer) { 94 observers_.AddObserver(observer); 95 } 96 97 void SearchModel::RemoveObserver(SearchModelObserver* observer) { 98 observers_.RemoveObserver(observer); 99 } 100