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

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

Issue 14805004: InstantExtended: Prevent spurious themechanged/mostvisitedchanged events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use Equal check, not changed Created 7 years, 8 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/common/instant_types.h ('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 287fad330eab28167e5ae9c318ab51eb2bf513d9..3522baf3015cb2abb453f2001d8e978712210e45 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -24,6 +24,37 @@ namespace {
// Size of the results cache.
const size_t kMaxInstantAutocompleteResultItemCacheSize = 100;
+bool IsThemeInfoEqual(const ThemeBackgroundInfo& theme_info,
+ const ThemeBackgroundInfo& old_theme_info) {
+ return old_theme_info.color_r == theme_info.color_r &&
+ old_theme_info.color_g == theme_info.color_g &&
+ old_theme_info.color_b == theme_info.color_b &&
+ old_theme_info.color_a == theme_info.color_a &&
+ old_theme_info.theme_id == theme_info.theme_id &&
+ old_theme_info.image_horizontal_alignment ==
+ theme_info.image_horizontal_alignment &&
+ old_theme_info.image_vertical_alignment ==
+ theme_info.image_vertical_alignment &&
+ old_theme_info.image_tiling == theme_info.image_tiling &&
+ old_theme_info.image_height == theme_info.image_height &&
+ old_theme_info.has_attribution == theme_info.has_attribution;
+}
+
+bool AreMostVisitedItemsEqual(
+ const std::vector<InstantMostVisitedItemIDPair>& items,
+ const std::vector<InstantMostVisitedItemIDPair>& old_items) {
+ if (old_items.size() != items.size())
+ return false;
+ for (size_t i = 0; i < items.size(); i++) {
+ InstantMostVisitedItem old_item = old_items[i].second;
+ InstantMostVisitedItem new_item = items[i].second;
sreeram 2013/05/05 02:19:12 "const InstantMostVisitedItem&" in both lines abov
sreeram 2013/05/05 02:19:12 It's mildly inconsistent to have "items" and "old_
Anuj 2013/05/06 17:44:44 Done.
Anuj 2013/05/06 17:44:44 Done.
+ if (new_item.url != old_item.url || new_item.title != old_item.title) {
+ return false;
sreeram 2013/05/05 02:19:12 Nit: No braces.
Anuj 2013/05/06 17:44:44 Done.
+ }
+ }
+ return true;
+}
+
} // namespace
SearchBox::SearchBox(content::RenderView* render_view)
@@ -329,6 +360,8 @@ void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) {
}
void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) {
+ if (IsThemeInfoEqual(theme_info, theme_info_))
+ return;
theme_info_ = theme_info;
if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
extensions_v8::SearchBoxExtension::DispatchThemeChange(
@@ -377,6 +410,11 @@ void SearchBox::SetQuery(const string16& query, bool verbatim) {
void SearchBox::OnMostVisitedChanged(
const std::vector<InstantMostVisitedItemIDPair>& items) {
+ std::vector<InstantMostVisitedItemIDPair> old_items;
+ most_visited_items_cache_.GetCurrentItems(&old_items);
+ if (AreMostVisitedItemsEqual(items, old_items))
+ return;
+
most_visited_items_cache_.AddItemsWithRestrictedID(items);
if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
« no previous file with comments | « chrome/common/instant_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698