Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / search / search_model.cc
blobfac64e62037bdfe4f8f3001e9ce8f4d5189960e9
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.
5 #include "chrome/browser/ui/search/search_model.h"
7 #include "chrome/browser/search/search.h"
8 #include "chrome/browser/ui/search/search_model_observer.h"
10 SearchModel::State::State()
11 : instant_support(INSTANT_SUPPORT_UNKNOWN),
12 voice_search_supported(false) {
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) {
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;
28 SearchModel::SearchModel() {
31 SearchModel::~SearchModel() {
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.";
39 if (state_ == new_state)
40 return;
42 const State old_state = state_;
43 state_ = new_state;
45 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
46 ModelChanged(old_state, state_));
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.";
54 if (state_.mode == new_mode)
55 return;
57 const State old_state = state_;
58 state_.mode = new_mode;
60 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
61 ModelChanged(old_state, state_));
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.";
69 if (state_.instant_support == instant_support)
70 return;
72 const State old_state = state_;
73 state_.instant_support = instant_support;
74 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
75 ModelChanged(old_state, state_));
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.";
83 if (state_.voice_search_supported == supported)
84 return;
86 const State old_state = state_;
87 state_.voice_search_supported = supported;
89 FOR_EACH_OBSERVER(SearchModelObserver, observers_,
90 ModelChanged(old_state, state_));
93 void SearchModel::AddObserver(SearchModelObserver* observer) {
94 observers_.AddObserver(observer);
97 void SearchModel::RemoveObserver(SearchModelObserver* observer) {
98 observers_.RemoveObserver(observer);