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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/search/search_tab_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/searchbox/searchbox.h" 5 #include "chrome/renderer/searchbox/searchbox.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "third_party/WebKit/public/web/WebDocument.h" 21 #include "third_party/WebKit/public/web/WebDocument.h"
22 #include "third_party/WebKit/public/web/WebFrame.h" 22 #include "third_party/WebKit/public/web/WebFrame.h"
23 #include "third_party/WebKit/public/web/WebView.h" 23 #include "third_party/WebKit/public/web/WebView.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 25
26 namespace { 26 namespace {
27 27
28 // Size of the results cache. 28 // Size of the results cache.
29 const size_t kMaxInstantAutocompleteResultItemCacheSize = 100; 29 const size_t kMaxInstantAutocompleteResultItemCacheSize = 100;
30 30
31 // Returns true if items stored in |old_item_id_pairs| and |new_items| are
32 // equal.
33 bool AreMostVisitedItemsEqual(
34 const std::vector<InstantMostVisitedItemIDPair>& old_item_id_pairs,
35 const std::vector<InstantMostVisitedItem>& new_items) {
36 if (old_item_id_pairs.size() != new_items.size())
37 return false;
38
39 for (size_t i = 0; i < new_items.size(); ++i) {
40 if (new_items[i].url != old_item_id_pairs[i].second.url ||
41 new_items[i].title != old_item_id_pairs[i].second.title) {
42 return false;
43 }
44 }
45 return true;
46 }
47
31 } // namespace 48 } // namespace
32 49
33 namespace internal { // for testing 50 namespace internal { // for testing
34 51
35 // Parses |url| and fills in |id| with the InstantRestrictedID obtained from the 52 // Parses |url| and fills in |id| with the InstantRestrictedID obtained from the
36 // |url|. |render_view_id| is the ID of the associated RenderView. 53 // |url|. |render_view_id| is the ID of the associated RenderView.
37 // 54 //
38 // Valid |url| forms: 55 // Valid |url| forms:
39 // chrome-search://favicon/<view_id>/<restricted_id> 56 // chrome-search://favicon/<view_id>/<restricted_id>
40 // chrome-search://thumb/<view_id>/<restricted_id> 57 // chrome-search://thumb/<view_id>/<restricted_id>
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 516 }
500 517
501 void SearchBox::SetQuery(const string16& query, bool verbatim) { 518 void SearchBox::SetQuery(const string16& query, bool verbatim) {
502 query_ = query; 519 query_ = query;
503 verbatim_ = verbatim; 520 verbatim_ = verbatim;
504 query_is_restricted_ = false; 521 query_is_restricted_ = false;
505 } 522 }
506 523
507 void SearchBox::OnMostVisitedChanged( 524 void SearchBox::OnMostVisitedChanged(
508 const std::vector<InstantMostVisitedItem>& items) { 525 const std::vector<InstantMostVisitedItem>& items) {
526 std::vector<InstantMostVisitedItemIDPair> last_known_items;
527 GetMostVisitedItems(&last_known_items);
528
529 if (AreMostVisitedItemsEqual(last_known_items, items))
530 return; // Do not send duplicate onmostvisitedchange events.
531
509 most_visited_items_cache_.AddItems(items); 532 most_visited_items_cache_.AddItems(items);
510 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 533 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
511 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( 534 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged(
512 render_view()->GetWebView()->mainFrame()); 535 render_view()->GetWebView()->mainFrame());
513 } 536 }
514 } 537 }
515 538
516 void SearchBox::GetMostVisitedItems( 539 void SearchBox::GetMostVisitedItems(
517 std::vector<InstantMostVisitedItemIDPair>* items) const { 540 std::vector<InstantMostVisitedItemIDPair>* items) const {
518 return most_visited_items_cache_.GetCurrentItems(items); 541 return most_visited_items_cache_.GetCurrentItems(items);
(...skipping 10 matching lines...) Expand all
529 InstantMostVisitedItem item; 552 InstantMostVisitedItem item;
530 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); 553 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL();
531 } 554 }
532 555
533 void SearchBox::OnToggleVoiceSearch() { 556 void SearchBox::OnToggleVoiceSearch() {
534 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 557 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
535 extensions_v8::SearchBoxExtension::DispatchToggleVoiceSearch( 558 extensions_v8::SearchBoxExtension::DispatchToggleVoiceSearch(
536 render_view()->GetWebView()->mainFrame()); 559 render_view()->GetWebView()->mainFrame());
537 } 560 }
538 } 561 }
OLDNEW
« 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