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

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

Issue 12498002: InstantExtended: Adding InstantRestrictedIDCache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merging David's and Sreeram's changes. Created 7 years, 9 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
Index: chrome/renderer/searchbox/searchbox.cc
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index 83a9bd5fab10b1078c70adcdeb2d287329932411..79fda2adc70e8f9ed92784b5ae775e4dbc4ef98e 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -12,18 +12,23 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+namespace {
+// Size of the results cache.
+const size_t kMaxResultsCacheSize = 100;
palmer 2013/03/13 23:50:37 Don't the other instances of this have it at 1000?
dhollowa 2013/03/14 00:02:43 Move to common place.
Shishir 2013/03/14 19:53:03 Done.
Shishir 2013/03/14 19:53:03 Done for the most visited item. The Autocomplete c
+}
+
SearchBox::SearchBox(content::RenderView* render_view)
: content::RenderViewObserver(render_view),
content::RenderViewObserverTracker<SearchBox>(render_view),
verbatim_(false),
selection_start_(0),
selection_end_(0),
- results_base_(0),
start_margin_(0),
- last_results_base_(0),
is_key_capture_enabled_(false),
display_instant_results_(false),
- omnibox_font_size_(0) {
+ omnibox_font_size_(0),
+ autocomplete_results_cache_(kMaxResultsCacheSize),
+ most_visited_items_cache_(kMaxResultsCacheSize) {
}
SearchBox::~SearchBox() {
@@ -73,12 +78,14 @@ void SearchBox::NavigateToURL(const GURL& url,
url, transition, disposition));
}
-void SearchBox::DeleteMostVisitedItem(uint64 most_visited_item_id) {
+void SearchBox::DeleteMostVisitedItem(
+ InstantRestrictedID most_visited_item_id) {
render_view()->Send(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
render_view()->GetRoutingID(), most_visited_item_id));
}
-void SearchBox::UndoMostVisitedDeletion(uint64 most_visited_item_id) {
+void SearchBox::UndoMostVisitedDeletion(
+ InstantRestrictedID most_visited_item_id) {
render_view()->Send(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
render_view()->GetRoutingID(), most_visited_item_id));
}
@@ -101,24 +108,16 @@ gfx::Rect SearchBox::GetPopupBounds() const {
static_cast<int>(popup_bounds_.height() / zoom));
}
-const std::vector<InstantAutocompleteResult>&
- SearchBox::GetAutocompleteResults() {
- // Remember the last requested autocomplete_results to account for race
- // conditions between autocomplete providers returning new data and the user
- // clicking on a suggestion.
- last_autocomplete_results_ = autocomplete_results_;
- last_results_base_ = results_base_;
- return autocomplete_results_;
+void SearchBox::GetAutocompleteResults(
+ std::vector<InstantAutocompleteResultIDPair>* results) const {
+ autocomplete_results_cache_.GetCurrentItems(results);
}
-const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId(
- size_t autocomplete_result_id) const {
- if (autocomplete_result_id < last_results_base_ ||
- autocomplete_result_id >=
- last_results_base_ + last_autocomplete_results_.size())
- return NULL;
- return &last_autocomplete_results_[
- autocomplete_result_id - last_results_base_];
+bool SearchBox::GetAutocompleteResultWithId(
+ InstantRestrictedID restricted_id,
dhollowa 2013/03/14 00:02:43 s/restricted_id/autocomplete_item_id/ (Throughout
Shishir 2013/03/14 19:53:03 Done.
+ InstantAutocompleteResult* result) const {
+ return autocomplete_results_cache_.GetItemWithRestrictedID(restricted_id,
+ result);
}
const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
@@ -235,8 +234,7 @@ void SearchBox::OnDetermineIfPageSupportsInstant() {
void SearchBox::OnAutocompleteResults(
const std::vector<InstantAutocompleteResult>& results) {
- results_base_ += autocomplete_results_.size();
- autocomplete_results_ = results;
+ autocomplete_results_cache_.AddItems(results);
if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
DVLOG(1) << render_view() << " OnAutocompleteResults";
extensions_v8::SearchBoxExtension::DispatchAutocompleteResults(
@@ -326,10 +324,8 @@ void SearchBox::Reset() {
verbatim_ = false;
selection_start_ = 0;
selection_end_ = 0;
- results_base_ = 0;
popup_bounds_ = gfx::Rect();
start_margin_ = 0;
- autocomplete_results_.clear();
is_key_capture_enabled_ = false;
theme_info_ = ThemeBackgroundInfo();
// Don't reset display_instant_results_ to prevent clearing it on committed
@@ -340,8 +336,8 @@ void SearchBox::Reset() {
}
void SearchBox::OnMostVisitedChanged(
- const std::vector<InstantMostVisitedItem>& items) {
- most_visited_items_ = items;
+ const std::vector<InstantMostVisitedItemIDPair>& items) {
+ most_visited_items_cache_.AddItemsWithRestrictedID(items);
if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged(
@@ -349,7 +345,12 @@ void SearchBox::OnMostVisitedChanged(
}
}
-const std::vector<InstantMostVisitedItem>&
-SearchBox::GetMostVisitedItems() const {
- return most_visited_items_;
+void SearchBox::GetMostVisitedItems(
+ std::vector<InstantMostVisitedItemIDPair>* items) const {
+ return most_visited_items_cache_.GetCurrentItems(items);
+}
+
+bool SearchBox::GetMostVisitedItemWithID(InstantRestrictedID restricted_id,
+ InstantMostVisitedItem* item) const {
+ return most_visited_items_cache_.GetItemWithRestrictedID(restricted_id, item);
}

Powered by Google App Engine
This is Rietveld 408576698