OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "ui/app_list/search/history_data.h" | 5 #include "ui/app_list/search/history_data.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 std::find(secondary.begin(), secondary.end(), result_id); | 90 std::find(secondary.begin(), secondary.end(), result_id); |
91 if (secondary_it != secondary.end()) | 91 if (secondary_it != secondary.end()) |
92 secondary.erase(secondary_it); | 92 secondary.erase(secondary_it); |
93 | 93 |
94 secondary.push_back(result_id); | 94 secondary.push_back(result_id); |
95 if (secondary.size() > max_secondary_) | 95 if (secondary.size() > max_secondary_) |
96 secondary.pop_front(); | 96 secondary.pop_front(); |
97 store_->SetSecondary(query, secondary); | 97 store_->SetSecondary(query, secondary); |
98 } | 98 } |
99 | 99 |
100 scoped_ptr<KnownResults> HistoryData::GetKnownResults( | 100 std::unique_ptr<KnownResults> HistoryData::GetKnownResults( |
101 const std::string& query) const { | 101 const std::string& query) const { |
102 scoped_ptr<KnownResults> results(new KnownResults); | 102 std::unique_ptr<KnownResults> results(new KnownResults); |
103 for (Associations::const_iterator assoc_it = associations_.lower_bound(query); | 103 for (Associations::const_iterator assoc_it = associations_.lower_bound(query); |
104 assoc_it != associations_.end(); | 104 assoc_it != associations_.end(); |
105 ++assoc_it) { | 105 ++assoc_it) { |
106 // Break out of the loop if |query| is no longer a prefix. | 106 // Break out of the loop if |query| is no longer a prefix. |
107 if (assoc_it->first.size() < query.size() || | 107 if (assoc_it->first.size() < query.size() || |
108 strncmp(assoc_it->first.c_str(), query.c_str(), query.length()) != 0) { | 108 strncmp(assoc_it->first.c_str(), query.c_str(), query.length()) != 0) { |
109 break; | 109 break; |
110 } | 110 } |
111 | 111 |
112 const bool perfect = assoc_it->first == query; | 112 const bool perfect = assoc_it->first == query; |
(...skipping 21 matching lines...) Expand all Loading... |
134 } | 134 } |
135 | 135 |
136 void HistoryData::AddObserver(HistoryDataObserver* observer) { | 136 void HistoryData::AddObserver(HistoryDataObserver* observer) { |
137 observers_.AddObserver(observer); | 137 observers_.AddObserver(observer); |
138 } | 138 } |
139 | 139 |
140 void HistoryData::RemoveObserver(HistoryDataObserver* observer) { | 140 void HistoryData::RemoveObserver(HistoryDataObserver* observer) { |
141 observers_.RemoveObserver(observer); | 141 observers_.RemoveObserver(observer); |
142 } | 142 } |
143 | 143 |
144 void HistoryData::OnStoreLoaded(scoped_ptr<Associations> loaded_data) { | 144 void HistoryData::OnStoreLoaded(std::unique_ptr<Associations> loaded_data) { |
145 if (loaded_data) | 145 if (loaded_data) |
146 loaded_data->swap(associations_); | 146 loaded_data->swap(associations_); |
147 | 147 |
148 FOR_EACH_OBSERVER( | 148 FOR_EACH_OBSERVER( |
149 HistoryDataObserver, observers_, OnHistoryDataLoadedFromStore()); | 149 HistoryDataObserver, observers_, OnHistoryDataLoadedFromStore()); |
150 } | 150 } |
151 | 151 |
152 void HistoryData::TrimEntries() { | 152 void HistoryData::TrimEntries() { |
153 if (associations_.size() <= max_primary_) | 153 if (associations_.size() <= max_primary_) |
154 return; | 154 return; |
(...skipping 12 matching lines...) Expand all Loading... |
167 &EntrySortByTimeAscending); | 167 &EntrySortByTimeAscending); |
168 | 168 |
169 for (size_t i = 0; i < entries_to_remove; ++i) { | 169 for (size_t i = 0; i < entries_to_remove; ++i) { |
170 const std::string& query = *entries[i].query; | 170 const std::string& query = *entries[i].query; |
171 store_->Delete(query); | 171 store_->Delete(query); |
172 associations_.erase(query); | 172 associations_.erase(query); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 } // namespace app_list | 176 } // namespace app_list |
OLD | NEW |