Index: chrome/renderer/searchbox/searchbox.cc |
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc |
index 1d873975e601c4e1e8fe4a90e35ef3ee56358c63..eb17de17906ff6ef8027905e43ccbb5b4a39144d 100644 |
--- a/chrome/renderer/searchbox/searchbox.cc |
+++ b/chrome/renderer/searchbox/searchbox.cc |
@@ -28,6 +28,22 @@ namespace { |
// Size of the results cache. |
const size_t kMaxInstantAutocompleteResultItemCacheSize = 100; |
+// Returns true if |items_a| and |items_b| are equal. |
+bool AreMostVisitedItemsEqual( |
+ const std::vector<InstantMostVisitedItem>& items_a, |
+ const std::vector<InstantMostVisitedItem>& items_b) { |
+ if (items_a.size() != items_b.size()) |
+ return false; |
+ |
+ for (size_t i = 0; i < items_b.size(); ++i) { |
+ if (items_b[i].url != items_a[i].url || |
+ items_b[i].title != items_a[i].title) { |
+ return false; |
+ } |
+ } |
+ return true; |
+} |
+ |
} // namespace |
namespace internal { // for testing |
@@ -497,6 +513,19 @@ void SearchBox::SetQuery(const string16& query, bool verbatim) { |
void SearchBox::OnMostVisitedChanged( |
const std::vector<InstantMostVisitedItem>& items) { |
+ std::vector<InstantMostVisitedItemIDPair> item_id_pairs; |
+ GetMostVisitedItems(&item_id_pairs); |
+ |
+ std::vector<InstantMostVisitedItem> last_known_items; |
+ for (std::vector<InstantMostVisitedItemIDPair>::const_iterator it = |
samarth
2013/06/21 20:51:20
Why bother converting the list? Can't you change A
kmadhusu
2013/06/21 21:35:32
Done.
|
+ item_id_pairs.begin(); |
+ it != item_id_pairs.end(); ++it) { |
+ last_known_items.push_back(it->second); |
+ } |
+ |
+ 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( |