| OLD | NEW |
| 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/autocomplete_controller.h" | 5 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // shutdown too, so we don't ask Stop() to clear |result_| (and notify). | 159 // shutdown too, so we don't ask Stop() to clear |result_| (and notify). |
| 160 result_.Reset(); // Not really necessary. | 160 result_.Reset(); // Not really necessary. |
| 161 Stop(false); | 161 Stop(false); |
| 162 | 162 |
| 163 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 163 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
| 164 (*i)->Release(); | 164 (*i)->Release(); |
| 165 | 165 |
| 166 providers_.clear(); // Not really necessary. | 166 providers_.clear(); // Not really necessary. |
| 167 } | 167 } |
| 168 | 168 |
| 169 void AutocompleteController::Start( | 169 void AutocompleteController::Start(const AutocompleteInput& input) { |
| 170 const string16& text, | |
| 171 const string16& desired_tld, | |
| 172 bool prevent_inline_autocomplete, | |
| 173 bool prefer_keyword, | |
| 174 bool allow_exact_keyword_match, | |
| 175 AutocompleteInput::MatchesRequested matches_requested) { | |
| 176 const string16 old_input_text(input_.text()); | 170 const string16 old_input_text(input_.text()); |
| 177 const AutocompleteInput::MatchesRequested old_matches_requested = | 171 const AutocompleteInput::MatchesRequested old_matches_requested = |
| 178 input_.matches_requested(); | 172 input_.matches_requested(); |
| 179 input_ = AutocompleteInput(text, desired_tld, prevent_inline_autocomplete, | 173 input_ = input; |
| 180 prefer_keyword, allow_exact_keyword_match, matches_requested); | |
| 181 | 174 |
| 182 // See if we can avoid rerunning autocomplete when the query hasn't changed | 175 // See if we can avoid rerunning autocomplete when the query hasn't changed |
| 183 // much. When the user presses or releases the ctrl key, the desired_tld | 176 // much. When the user presses or releases the ctrl key, the desired_tld |
| 184 // changes, and when the user finishes an IME composition, inline autocomplete | 177 // changes, and when the user finishes an IME composition, inline autocomplete |
| 185 // may no longer be prevented. In both these cases the text itself hasn't | 178 // may no longer be prevented. In both these cases the text itself hasn't |
| 186 // changed since the last query, and some providers can do much less work (and | 179 // changed since the last query, and some providers can do much less work (and |
| 187 // get matches back more quickly). Taking advantage of this reduces flicker. | 180 // get matches back more quickly). Taking advantage of this reduces flicker. |
| 188 // | 181 // |
| 189 // NOTE: This comes after constructing |input_| above since that construction | 182 // NOTE: This comes after constructing |input_| above since that construction |
| 190 // can change the text string (e.g. by stripping off a leading '?'). | 183 // can change the text string (e.g. by stripping off a leading '?'). |
| 191 const bool minimal_changes = (input_.text() == old_input_text) && | 184 const bool minimal_changes = (input_.text() == old_input_text) && |
| 192 (input_.matches_requested() == old_matches_requested); | 185 (input_.matches_requested() == old_matches_requested); |
| 193 | 186 |
| 194 expire_timer_.Stop(); | 187 expire_timer_.Stop(); |
| 195 | 188 |
| 196 // Start the new query. | 189 // Start the new query. |
| 197 in_zero_suggest_ = false; | 190 in_zero_suggest_ = false; |
| 198 in_start_ = true; | 191 in_start_ = true; |
| 199 base::TimeTicks start_time = base::TimeTicks::Now(); | 192 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 200 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); | 193 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); |
| 201 ++i) { | 194 ++i) { |
| 202 (*i)->Start(input_, minimal_changes); | 195 (*i)->Start(input_, minimal_changes); |
| 203 if (matches_requested != AutocompleteInput::ALL_MATCHES) | 196 if (input.matches_requested() != AutocompleteInput::ALL_MATCHES) |
| 204 DCHECK((*i)->done()); | 197 DCHECK((*i)->done()); |
| 205 } | 198 } |
| 206 if (matches_requested == AutocompleteInput::ALL_MATCHES && | 199 if (input.matches_requested() == AutocompleteInput::ALL_MATCHES && |
| 207 (text.length() < 6)) { | 200 (input.text().length() < 6)) { |
| 208 base::TimeTicks end_time = base::TimeTicks::Now(); | 201 base::TimeTicks end_time = base::TimeTicks::Now(); |
| 209 std::string name = "Omnibox.QueryTime." + base::IntToString(text.length()); | 202 std::string name = "Omnibox.QueryTime." + base::IntToString( |
| 203 input.text().length()); |
| 210 base::Histogram* counter = base::Histogram::FactoryGet( | 204 base::Histogram* counter = base::Histogram::FactoryGet( |
| 211 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); | 205 name, 1, 1000, 50, base::Histogram::kUmaTargetedHistogramFlag); |
| 212 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); | 206 counter->Add(static_cast<int>((end_time - start_time).InMilliseconds())); |
| 213 } | 207 } |
| 214 in_start_ = false; | 208 in_start_ = false; |
| 215 CheckIfDone(); | 209 CheckIfDone(); |
| 216 // The second true forces saying the default match has changed. | 210 // The second true forces saying the default match has changed. |
| 217 // This triggers the edit model to update things such as the inline | 211 // This triggers the edit model to update things such as the inline |
| 218 // autocomplete state. In particular, if the user has typed a key | 212 // autocomplete state. In particular, if the user has typed a key |
| 219 // since the last notification, and we're now re-running | 213 // since the last notification, and we're now re-running |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 } | 493 } |
| 500 done_ = true; | 494 done_ = true; |
| 501 } | 495 } |
| 502 | 496 |
| 503 void AutocompleteController::StartExpireTimer() { | 497 void AutocompleteController::StartExpireTimer() { |
| 504 if (result_.HasCopiedMatches()) | 498 if (result_.HasCopiedMatches()) |
| 505 expire_timer_.Start(FROM_HERE, | 499 expire_timer_.Start(FROM_HERE, |
| 506 base::TimeDelta::FromMilliseconds(kExpireTimeMS), | 500 base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
| 507 this, &AutocompleteController::ExpireCopiedEntries); | 501 this, &AutocompleteController::ExpireCopiedEntries); |
| 508 } | 502 } |
| OLD | NEW |