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

Unified Diff: chrome/renderer/searchbox/searchbox.cc

Issue 17521002: Added a check in Searchbox::OnMostVisitedChanged() to prevent duplicate notifications regarding mos… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698