Chromium Code Reviews| 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/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 TemplateURLService* template_url_service, | 176 TemplateURLService* template_url_service, |
| 177 AutocompleteControllerDelegate* delegate, | 177 AutocompleteControllerDelegate* delegate, |
| 178 int provider_types) | 178 int provider_types) |
| 179 : delegate_(delegate), | 179 : delegate_(delegate), |
| 180 history_url_provider_(NULL), | 180 history_url_provider_(NULL), |
| 181 keyword_provider_(NULL), | 181 keyword_provider_(NULL), |
| 182 search_provider_(NULL), | 182 search_provider_(NULL), |
| 183 zero_suggest_provider_(NULL), | 183 zero_suggest_provider_(NULL), |
| 184 stop_timer_duration_(OmniboxFieldTrial::StopTimerFieldTrialDuration()), | 184 stop_timer_duration_(OmniboxFieldTrial::StopTimerFieldTrialDuration()), |
| 185 done_(true), | 185 done_(true), |
| 186 has_providers_for_omnibox_focus_(false), | |
| 186 in_start_(false), | 187 in_start_(false), |
| 187 template_url_service_(template_url_service) { | 188 template_url_service_(template_url_service) { |
| 188 provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); | 189 provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); |
| 189 if (provider_types & AutocompleteProvider::TYPE_BOOKMARK) | 190 if (provider_types & AutocompleteProvider::TYPE_BOOKMARK) |
| 190 providers_.push_back(new BookmarkProvider(profile)); | 191 providers_.push_back(new BookmarkProvider(profile)); |
| 191 if (provider_types & AutocompleteProvider::TYPE_BUILTIN) | 192 if (provider_types & AutocompleteProvider::TYPE_BUILTIN) |
| 192 providers_.push_back(new BuiltinProvider()); | 193 providers_.push_back(new BuiltinProvider()); |
| 193 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) | 194 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) |
| 194 providers_.push_back(new HistoryQuickProvider(profile)); | 195 providers_.push_back(new HistoryQuickProvider(profile)); |
| 195 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) { | 196 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 215 providers_.push_back(search_provider_); | 216 providers_.push_back(search_provider_); |
| 216 } | 217 } |
| 217 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) | 218 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) |
| 218 providers_.push_back(new ShortcutsProvider(profile)); | 219 providers_.push_back(new ShortcutsProvider(profile)); |
| 219 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { | 220 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { |
| 220 zero_suggest_provider_ = ZeroSuggestProvider::Create( | 221 zero_suggest_provider_ = ZeroSuggestProvider::Create( |
| 221 this, template_url_service, profile); | 222 this, template_url_service, profile); |
| 222 if (zero_suggest_provider_) | 223 if (zero_suggest_provider_) |
| 223 providers_.push_back(zero_suggest_provider_); | 224 providers_.push_back(zero_suggest_provider_); |
| 224 } | 225 } |
| 226 for (auto& provider : providers_) { | |
|
Peter Kasting
2014/12/30 21:18:23
Just eliminate this loop and the variable it sets
jif
2014/12/31 19:02:26
Done.
| |
| 227 if (provider.ActivatedOnOmniboxFocus()) { | |
| 228 has_providers_for_omnibox_focus_ = true; | |
| 229 break; | |
| 230 } | |
| 231 } | |
| 225 } | 232 } |
| 226 | 233 |
| 227 AutocompleteController::~AutocompleteController() { | 234 AutocompleteController::~AutocompleteController() { |
| 228 // The providers may have tasks outstanding that hold refs to them. We need | 235 // The providers may have tasks outstanding that hold refs to them. We need |
| 229 // to ensure they won't call us back if they outlive us. (Practically, | 236 // to ensure they won't call us back if they outlive us. (Practically, |
| 230 // calling Stop() should also cancel those tasks and make it so that we hold | 237 // calling Stop() should also cancel those tasks and make it so that we hold |
| 231 // the only refs.) We also don't want to bother notifying anyone of our | 238 // the only refs.) We also don't want to bother notifying anyone of our |
| 232 // result changes here, because the notification observer is in the midst of | 239 // result changes here, because the notification observer is in the midst of |
| 233 // shutdown too, so we don't ask Stop() to clear |result_| (and notify). | 240 // shutdown too, so we don't ask Stop() to clear |result_| (and notify). |
| 234 result_.Reset(); // Not really necessary. | 241 result_.Reset(); // Not really necessary. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 stop_timer_.Stop(); | 327 stop_timer_.Stop(); |
| 321 done_ = true; | 328 done_ = true; |
| 322 if (clear_result && !result_.empty()) { | 329 if (clear_result && !result_.empty()) { |
| 323 result_.Reset(); | 330 result_.Reset(); |
| 324 // NOTE: We pass in false since we're trying to only clear the popup, not | 331 // NOTE: We pass in false since we're trying to only clear the popup, not |
| 325 // touch the edit... this is all a mess and should be cleaned up :( | 332 // touch the edit... this is all a mess and should be cleaned up :( |
| 326 NotifyChanged(false); | 333 NotifyChanged(false); |
| 327 } | 334 } |
| 328 } | 335 } |
| 329 | 336 |
| 330 void AutocompleteController::StartZeroSuggest(const AutocompleteInput& input) { | 337 void AutocompleteController::StartOnOmniboxFocus( |
| 331 if (zero_suggest_provider_ == NULL) | 338 const AutocompleteInput& input) { |
| 339 if (!has_providers_for_omnibox_focus_) | |
| 332 return; | 340 return; |
| 333 | 341 |
| 334 DCHECK(!in_start_); // We should not be already running a query. | 342 DCHECK(!in_start_); // We should not be already running a query. |
| 335 | 343 |
| 336 // Call Start() on all prefix-based providers with an INVALID | 344 // Call Start() on all prefix-based providers with an INVALID |
| 337 // AutocompleteInput to clear out cached |matches_|, which ensures that | 345 // AutocompleteInput to clear out cached |matches_|, which ensures that |
| 338 // they aren't used with zero suggest. | 346 // they aren't used with zero suggest. |
| 347 bool non_empty_matches = false; | |
| 339 for (Providers::iterator i(providers_.begin()); i != providers_.end(); ++i) { | 348 for (Providers::iterator i(providers_.begin()); i != providers_.end(); ++i) { |
| 340 if (i->get() == zero_suggest_provider_) | 349 if (i->get().ActivatedOnOmniboxFocus()) { |
| 341 (*i)->Start(input, false); | 350 (*i)->Start(input, false); |
| 342 else | 351 if (!(*i)_->matches().empty()) |
| 352 non_empty_matches = true; | |
| 353 } else { | |
| 343 (*i)->Start(AutocompleteInput(), false); | 354 (*i)->Start(AutocompleteInput(), false); |
| 355 } | |
| 344 } | 356 } |
| 345 | 357 |
| 346 if (!zero_suggest_provider_->matches().empty()) | 358 if (non_empty_matches) |
|
Peter Kasting
2014/12/30 21:18:23
I think you can eliminate this conditional and jus
jif
2014/12/31 19:02:26
Done.
Looks good.
| |
| 347 UpdateResult(false, false); | 359 UpdateResult(false, false); |
| 348 } | 360 } |
| 349 | 361 |
| 350 void AutocompleteController::DeleteMatch(const AutocompleteMatch& match) { | 362 void AutocompleteController::DeleteMatch(const AutocompleteMatch& match) { |
| 351 DCHECK(match.SupportsDeletion()); | 363 DCHECK(match.SupportsDeletion()); |
| 352 | 364 |
| 353 // Delete duplicate matches attached to the main match first. | 365 // Delete duplicate matches attached to the main match first. |
| 354 for (ACMatches::const_iterator it(match.duplicate_matches.begin()); | 366 for (ACMatches::const_iterator it(match.duplicate_matches.begin()); |
| 355 it != match.duplicate_matches.end(); ++it) { | 367 it != match.duplicate_matches.end(); ++it) { |
| 356 if (it->deletable) | 368 if (it->deletable) |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 this, &AutocompleteController::ExpireCopiedEntries); | 691 this, &AutocompleteController::ExpireCopiedEntries); |
| 680 } | 692 } |
| 681 | 693 |
| 682 void AutocompleteController::StartStopTimer() { | 694 void AutocompleteController::StartStopTimer() { |
| 683 stop_timer_.Start(FROM_HERE, | 695 stop_timer_.Start(FROM_HERE, |
| 684 stop_timer_duration_, | 696 stop_timer_duration_, |
| 685 base::Bind(&AutocompleteController::Stop, | 697 base::Bind(&AutocompleteController::Stop, |
| 686 base::Unretained(this), | 698 base::Unretained(this), |
| 687 false)); | 699 false)); |
| 688 } | 700 } |
| OLD | NEW |