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

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: Addressed comments 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 std::vector<InstantMostVisitedItemIDPair> old_item_id_pairs,
samarth 2013/06/21 22:03:43 const reference, please
kmadhusu 2013/06/21 22:07:09 Done.
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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } 512 }
496 513
497 void SearchBox::SetQuery(const string16& query, bool verbatim) { 514 void SearchBox::SetQuery(const string16& query, bool verbatim) {
498 query_ = query; 515 query_ = query;
499 verbatim_ = verbatim; 516 verbatim_ = verbatim;
500 query_is_restricted_ = false; 517 query_is_restricted_ = false;
501 } 518 }
502 519
503 void SearchBox::OnMostVisitedChanged( 520 void SearchBox::OnMostVisitedChanged(
504 const std::vector<InstantMostVisitedItem>& items) { 521 const std::vector<InstantMostVisitedItem>& items) {
522 std::vector<InstantMostVisitedItemIDPair> last_known_items;
523 GetMostVisitedItems(&last_known_items);
524
525 if (AreMostVisitedItemsEqual(last_known_items, items))
526 return; // Do not send duplicate onmostvisitedchange events.
527
505 most_visited_items_cache_.AddItems(items); 528 most_visited_items_cache_.AddItems(items);
506 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 529 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
507 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( 530 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged(
508 render_view()->GetWebView()->mainFrame()); 531 render_view()->GetWebView()->mainFrame());
509 } 532 }
510 } 533 }
511 534
512 void SearchBox::GetMostVisitedItems( 535 void SearchBox::GetMostVisitedItems(
513 std::vector<InstantMostVisitedItemIDPair>* items) const { 536 std::vector<InstantMostVisitedItemIDPair>* items) const {
514 return most_visited_items_cache_.GetCurrentItems(items); 537 return most_visited_items_cache_.GetCurrentItems(items);
(...skipping 10 matching lines...) Expand all
525 InstantMostVisitedItem item; 548 InstantMostVisitedItem item;
526 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); 549 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL();
527 } 550 }
528 551
529 void SearchBox::OnToggleVoiceSearch() { 552 void SearchBox::OnToggleVoiceSearch() {
530 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 553 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
531 extensions_v8::SearchBoxExtension::DispatchToggleVoiceSearch( 554 extensions_v8::SearchBoxExtension::DispatchToggleVoiceSearch(
532 render_view()->GetWebView()->mainFrame()); 555 render_view()->GetWebView()->mainFrame());
533 } 556 }
534 } 557 }
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