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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 10392184: Fix possible crash in FinalizeInstantQuery() if AddMatchToMap() fails. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 | « no previous file | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 return; 129 return;
130 } 130 }
131 131
132 default_provider_suggest_text_ = suggest_text; 132 default_provider_suggest_text_ = suggest_text;
133 133
134 string16 adjusted_input_text(input_text); 134 string16 adjusted_input_text(input_text);
135 AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(), 135 AutocompleteInput::RemoveForcedQueryStringIfNecessary(input_.type(),
136 &adjusted_input_text); 136 &adjusted_input_text);
137 137
138 const string16 text = adjusted_input_text + suggest_text; 138 const string16 text = adjusted_input_text + suggest_text;
139 bool results_updated = false;
139 // Remove any matches that are identical to |text|. We don't use the 140 // Remove any matches that are identical to |text|. We don't use the
140 // destination_url for comparison as it varies depending upon the index passed 141 // destination_url for comparison as it varies depending upon the index passed
141 // to TemplateURL::ReplaceSearchTerms. 142 // to TemplateURL::ReplaceSearchTerms.
142 for (ACMatches::iterator i = matches_.begin(); i != matches_.end();) { 143 for (ACMatches::iterator i = matches_.begin(); i != matches_.end();) {
143 if (((i->type == AutocompleteMatch::SEARCH_HISTORY) || 144 if (((i->type == AutocompleteMatch::SEARCH_HISTORY) ||
144 (i->type == AutocompleteMatch::SEARCH_SUGGEST)) && 145 (i->type == AutocompleteMatch::SEARCH_SUGGEST)) &&
145 (i->fill_into_edit == text)) { 146 (i->fill_into_edit == text)) {
146 i = matches_.erase(i); 147 i = matches_.erase(i);
148 results_updated = true;
147 } else { 149 } else {
148 ++i; 150 ++i;
149 } 151 }
150 } 152 }
151 153
152 // Add the new instant suggest result. We give it a rank higher than 154 // Add the new instant suggest result. We give it a rank higher than
153 // SEARCH_WHAT_YOU_TYPED so that it gets autocompleted. 155 // SEARCH_WHAT_YOU_TYPED so that it gets autocompleted.
154 int did_not_accept_default_suggestion = default_suggest_results_.empty() ? 156 int did_not_accept_default_suggestion = default_suggest_results_.empty() ?
155 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE : 157 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE :
156 TemplateURLRef::NO_SUGGESTION_CHOSEN; 158 TemplateURLRef::NO_SUGGESTION_CHOSEN;
157 MatchMap match_map; 159 MatchMap match_map;
158 AddMatchToMap(text, adjusted_input_text, 160 AddMatchToMap(text, adjusted_input_text,
159 CalculateRelevanceForWhatYouTyped() + 1, 161 CalculateRelevanceForWhatYouTyped() + 1,
160 AutocompleteMatch::SEARCH_SUGGEST, 162 AutocompleteMatch::SEARCH_SUGGEST,
161 did_not_accept_default_suggestion, false, &match_map); 163 did_not_accept_default_suggestion, false, &match_map);
162 DCHECK_EQ(1u, match_map.size()); 164 if (!match_map.empty()) {
163 matches_.push_back(match_map.begin()->second); 165 matches_.push_back(match_map.begin()->second);
166 results_updated = true;
167 }
164 168
165 listener_->OnProviderUpdate(true); 169 if (results_updated || done_)
170 listener_->OnProviderUpdate(results_updated);
166 } 171 }
167 172
168 void SearchProvider::Start(const AutocompleteInput& input, 173 void SearchProvider::Start(const AutocompleteInput& input,
169 bool minimal_changes) { 174 bool minimal_changes) {
170 matches_.clear(); 175 matches_.clear();
171 176
172 instant_finalized_ = 177 instant_finalized_ =
173 (input.matches_requested() != AutocompleteInput::ALL_MATCHES); 178 (input.matches_requested() != AutocompleteInput::ALL_MATCHES);
174 179
175 // Can't return search/suggest results for bogus input or without a profile. 180 // Can't return search/suggest results for bogus input or without a profile.
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 995
991 return match; 996 return match;
992 } 997 }
993 998
994 void SearchProvider::UpdateDone() { 999 void SearchProvider::UpdateDone() {
995 // We're done when there are no more suggest queries pending (this is set to 1 1000 // We're done when there are no more suggest queries pending (this is set to 1
996 // when the timer is started) and we're not waiting on instant. 1001 // when the timer is started) and we're not waiting on instant.
997 done_ = ((suggest_results_pending_ == 0) && 1002 done_ = ((suggest_results_pending_ == 0) &&
998 (instant_finalized_ || !InstantController::IsEnabled(profile_))); 1003 (instant_finalized_ || !InstantController::IsEnabled(profile_)));
999 } 1004 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698