Chromium Code Reviews| Index: chrome/renderer/searchbox/searchbox.cc |
| diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc |
| index 9450a1e89f3f2e562a6144bf0f71ec74ae3159fd..e62f845ba2dc47dab6e412b8cf95785dcb4dafcd 100644 |
| --- a/chrome/renderer/searchbox/searchbox.cc |
| +++ b/chrome/renderer/searchbox/searchbox.cc |
| @@ -28,6 +28,23 @@ namespace { |
| // Size of the results cache. |
| const size_t kMaxInstantAutocompleteResultItemCacheSize = 100; |
| +// Returns true if items stored in |old_item_id_pairs| and |new_items| are |
| +// equal. |
| +bool AreMostVisitedItemsEqual( |
| + std::vector<InstantMostVisitedItemIDPair> old_item_id_pairs, |
|
samarth
2013/06/21 22:03:43
const reference, please
kmadhusu
2013/06/21 22:07:09
Done.
|
| + const std::vector<InstantMostVisitedItem>& new_items) { |
| + if (old_item_id_pairs.size() != new_items.size()) |
| + return false; |
| + |
| + for (size_t i = 0; i < new_items.size(); ++i) { |
| + if (new_items[i].url != old_item_id_pairs[i].second.url || |
| + new_items[i].title != old_item_id_pairs[i].second.title) { |
| + return false; |
| + } |
| + } |
| + return true; |
| +} |
| + |
| } // namespace |
| namespace internal { // for testing |
| @@ -502,6 +519,12 @@ void SearchBox::SetQuery(const string16& query, bool verbatim) { |
| void SearchBox::OnMostVisitedChanged( |
| const std::vector<InstantMostVisitedItem>& items) { |
| + std::vector<InstantMostVisitedItemIDPair> last_known_items; |
| + GetMostVisitedItems(&last_known_items); |
| + |
| + if (AreMostVisitedItemsEqual(last_known_items, items)) |
| + return; // Do not send duplicate onmostvisitedchange events. |
| + |
| most_visited_items_cache_.AddItems(items); |
| if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( |