Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: chrome/browser/ui/search/search_model.cc

Issue 2885853002: Instant: remove InstantSupportState (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search/search_model.h" 5 #include "chrome/browser/ui/search/search_model.h"
6 6
7 #include "chrome/browser/ui/search/search_model_observer.h" 7 #include "chrome/browser/ui/search/search_model_observer.h"
8 #include "components/search/search.h" 8 #include "components/search/search.h"
9 9
10 SearchModel::State::State() : instant_support(INSTANT_SUPPORT_NO) {} 10 SearchModel::SearchModel() = default;
11 11
12 SearchModel::State::State(const SearchMode& mode, 12 SearchModel::~SearchModel() = default;
13 InstantSupportState instant_support)
14 : mode(mode), instant_support(instant_support) {}
15
16 bool SearchModel::State::operator==(const State& rhs) const {
17 return mode == rhs.mode && instant_support == rhs.instant_support;
18 }
19
20 SearchModel::SearchModel() {
21 }
22
23 SearchModel::~SearchModel() {
24 }
25
26 void SearchModel::SetState(const State& new_state) {
27 DCHECK(search::IsInstantExtendedAPIEnabled())
28 << "Please do not try to set the SearchModel mode without first "
29 << "checking if Search is enabled.";
30
31 if (state_ == new_state)
32 return;
33
34 const State old_state = state_;
35 state_ = new_state;
36
37 for (SearchModelObserver& observer : observers_)
38 observer.ModelChanged(old_state, state_);
39 }
40 13
41 void SearchModel::SetMode(const SearchMode& new_mode) { 14 void SearchModel::SetMode(const SearchMode& new_mode) {
42 DCHECK(search::IsInstantExtendedAPIEnabled()) 15 DCHECK(search::IsInstantExtendedAPIEnabled())
43 << "Please do not try to set the SearchModel mode without first " 16 << "Please do not try to set the SearchModel mode without first "
44 << "checking if Search is enabled."; 17 << "checking if Search is enabled.";
45 18
46 if (state_.mode == new_mode) 19 if (mode_ == new_mode)
47 return; 20 return;
48 21
49 const State old_state = state_; 22 const SearchMode old_mode = mode_;
50 state_.mode = new_mode; 23 mode_ = new_mode;
51 24
52 for (SearchModelObserver& observer : observers_) 25 for (SearchModelObserver& observer : observers_)
53 observer.ModelChanged(old_state, state_); 26 observer.ModelChanged(old_mode, mode_);
54 }
55
56 void SearchModel::SetInstantSupportState(InstantSupportState instant_support) {
57 DCHECK(search::IsInstantExtendedAPIEnabled())
58 << "Please do not try to set the SearchModel state without first "
59 << "checking if Search is enabled.";
60
61 if (state_.instant_support == instant_support)
62 return;
63
64 const State old_state = state_;
65 state_.instant_support = instant_support;
66 for (SearchModelObserver& observer : observers_)
67 observer.ModelChanged(old_state, state_);
68 } 27 }
69 28
70 void SearchModel::AddObserver(SearchModelObserver* observer) { 29 void SearchModel::AddObserver(SearchModelObserver* observer) {
71 observers_.AddObserver(observer); 30 observers_.AddObserver(observer);
72 } 31 }
73 32
74 void SearchModel::RemoveObserver(SearchModelObserver* observer) { 33 void SearchModel::RemoveObserver(SearchModelObserver* observer) {
75 observers_.RemoveObserver(observer); 34 observers_.RemoveObserver(observer);
76 } 35 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_model.h ('k') | chrome/browser/ui/search/search_model_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698