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

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 bd563a875684ff6ca79e2955d3e7f15d84c09a6c..922e985bf1290c8f5f8ff78f3b72c3ae635e5aca 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(
+ const std::vector<InstantMostVisitedItemIDPair>& old_item_id_pairs,
+ 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
@@ -506,6 +523,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(
« 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