| Index: chrome/renderer/searchbox/searchbox.cc
|
| diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
|
| index 3631412b48337beae307be724140cdaa2384a916..fdd7b83e7c91cb7d33b9d0f1a3eca72c9bd69fc8 100644
|
| --- a/chrome/renderer/searchbox/searchbox.cc
|
| +++ b/chrome/renderer/searchbox/searchbox.cc
|
| @@ -18,6 +18,8 @@ const char kThumbnailUrlPrefix[] = "chrome-search://thumb/";
|
| // Prefix for a thumbnail URL.
|
| const char kFaviconUrlPrefix[] = "chrome-search://favicon/";
|
|
|
| +// Size of the results cache.
|
| +const size_t kMaxResultsCacheSize = 1000;
|
| }
|
|
|
| SearchBox::SearchBox(content::RenderView* render_view)
|
| @@ -26,9 +28,8 @@ SearchBox::SearchBox(content::RenderView* render_view)
|
| verbatim_(false),
|
| selection_start_(0),
|
| selection_end_(0),
|
| - results_base_(0),
|
| start_margin_(0),
|
| - last_results_base_(0),
|
| + autocomplete_results_cache_(kMaxResultsCacheSize),
|
| is_key_capture_enabled_(false),
|
| display_instant_results_(false),
|
| omnibox_font_size_(0),
|
| @@ -106,22 +107,17 @@ 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<std::pair<size_t, InstantAutocompleteResult> >*
|
| + results) const {
|
| + autocomplete_results_cache_.GetCurrentItems(results);
|
| }
|
|
|
| -const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId(
|
| - size_t restricted_id) const {
|
| - if (restricted_id < last_results_base_ ||
|
| - restricted_id >= last_results_base_ + last_autocomplete_results_.size())
|
| - return NULL;
|
| - return &last_autocomplete_results_[restricted_id - last_results_base_];
|
| +bool SearchBox::GetAutocompleteResultWithId(
|
| + size_t restricted_id,
|
| + InstantAutocompleteResult* result) const {
|
| + return autocomplete_results_cache_.GetItemWithRestrictedId(restricted_id,
|
| + result);
|
| }
|
|
|
| const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
|
| @@ -235,8 +231,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(
|
| @@ -307,10 +302,9 @@ void SearchBox::Reset() {
|
| verbatim_ = false;
|
| selection_start_ = 0;
|
| selection_end_ = 0;
|
| - results_base_ = 0;
|
| popup_bounds_ = gfx::Rect();
|
| + autocomplete_results_cache_.Reset();
|
| 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
|
|
|