| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(std::unique_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 (auto& observer : observers_) |
| 149 HistoryDataObserver, observers_, OnHistoryDataLoadedFromStore()); | 149 observer.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; |
| 155 | 155 |
| 156 std::vector<EntrySortData> entries; | 156 std::vector<EntrySortData> entries; |
| 157 for (Associations::const_iterator it = associations_.begin(); | 157 for (Associations::const_iterator it = associations_.begin(); |
| 158 it != associations_.end(); | 158 it != associations_.end(); |
| 159 ++it) { | 159 ++it) { |
| 160 entries.push_back(EntrySortData(&it->first, &it->second.update_time)); | 160 entries.push_back(EntrySortData(&it->first, &it->second.update_time)); |
| 161 } | 161 } |
| 162 | 162 |
| 163 const size_t entries_to_remove = associations_.size() - max_primary_; | 163 const size_t entries_to_remove = associations_.size() - max_primary_; |
| 164 std::partial_sort(entries.begin(), | 164 std::partial_sort(entries.begin(), |
| 165 entries.begin() + entries_to_remove, | 165 entries.begin() + entries_to_remove, |
| 166 entries.end(), | 166 entries.end(), |
| 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 |