| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // providers (such as SearchProvider) wait for the user to stop typing before | 69 // providers (such as SearchProvider) wait for the user to stop typing before |
| 70 // they initiate a query. | 70 // they initiate a query. |
| 71 const int kExpireTimeMS = 500; | 71 const int kExpireTimeMS = 500; |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 const int AutocompleteController::kNoItemSelected = -1; | 75 const int AutocompleteController::kNoItemSelected = -1; |
| 76 | 76 |
| 77 AutocompleteController::AutocompleteController( | 77 AutocompleteController::AutocompleteController( |
| 78 Profile* profile, | 78 Profile* profile, |
| 79 AutocompleteControllerDelegate* delegate) | 79 AutocompleteControllerDelegate* delegate, |
| 80 int provider_types) |
| 80 : delegate_(delegate), | 81 : delegate_(delegate), |
| 81 keyword_provider_(NULL), | 82 keyword_provider_(NULL), |
| 83 search_provider_(NULL), |
| 82 zero_suggest_provider_(NULL), | 84 zero_suggest_provider_(NULL), |
| 83 done_(true), | 85 done_(true), |
| 84 in_start_(false), | 86 in_start_(false), |
| 85 in_zero_suggest_(false), | 87 in_zero_suggest_(false), |
| 86 profile_(profile) { | 88 profile_(profile) { |
| 87 search_provider_ = new SearchProvider(this, profile); | 89 bool use_hqp = !!(provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK); |
| 88 providers_.push_back(search_provider_); | 90 // TODO(mrossetti): Permanently modify the HistoryURLProvider to not search |
| 89 #if !defined(OS_ANDROID) | 91 // titles once HQP is turned on permanently. |
| 90 // History quick provider is enabled on all platforms other than Android. | 92 // History quick provider can be used on all platforms other than Android. |
| 91 bool hqp_enabled = true; | |
| 92 providers_.push_back(new HistoryQuickProvider(this, profile)); | |
| 93 // Search provider/"tab to search" is enabled on all platforms other than | |
| 94 // Android. | |
| 95 keyword_provider_ = new KeywordProvider(this, profile); | |
| 96 providers_.push_back(keyword_provider_); | |
| 97 #else | |
| 98 // TODO(mrossetti): Remove the following and permanently modify the | |
| 99 // HistoryURLProvider to not search titles once HQP is turned on permanently. | |
| 100 // TODO(jcivelli): Enable the History Quick Provider and figure out why it | 93 // TODO(jcivelli): Enable the History Quick Provider and figure out why it |
| 101 // reports the wrong results for some pages. | 94 // reports the wrong results for some pages. |
| 102 bool hqp_enabled = false; | 95 #if defined(OS_ANDROID) |
| 103 #endif // !OS_ANDROID | 96 use_hqp = false; |
| 104 providers_.push_back(new HistoryURLProvider(this, profile)); | 97 #endif |
| 105 providers_.push_back(new ShortcutsProvider(this, profile)); | 98 |
| 106 providers_.push_back(new HistoryContentsProvider(this, profile, hqp_enabled)); | 99 if (provider_types & AutocompleteProvider::TYPE_BUILTIN) |
| 107 providers_.push_back(new BuiltinProvider(this, profile)); | 100 providers_.push_back(new BuiltinProvider(this, profile)); |
| 108 providers_.push_back(new ExtensionAppProvider(this, profile)); | 101 if (provider_types & AutocompleteProvider::TYPE_EXTENSION_APP) |
| 109 // Create ZeroSuggest if its switch is present. | 102 providers_.push_back(new ExtensionAppProvider(this, profile)); |
| 103 if (provider_types & AutocompleteProvider::TYPE_HISTORY_CONTENTS) |
| 104 providers_.push_back(new HistoryContentsProvider(this, profile, use_hqp)); |
| 105 if (use_hqp) |
| 106 providers_.push_back(new HistoryQuickProvider(this, profile)); |
| 107 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) |
| 108 providers_.push_back(new HistoryURLProvider(this, profile)); |
| 109 // Search provider/"tab to search" can be used on all platforms other than |
| 110 // Android. |
| 111 #if !defined(OS_ANDROID) |
| 112 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) { |
| 113 keyword_provider_ = new KeywordProvider(this, profile); |
| 114 providers_.push_back(keyword_provider_); |
| 115 } |
| 116 #endif |
| 117 if (provider_types & AutocompleteProvider::TYPE_SEARCH) { |
| 118 search_provider_ = new SearchProvider(this, profile); |
| 119 providers_.push_back(search_provider_); |
| 120 } |
| 121 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) |
| 122 providers_.push_back(new ShortcutsProvider(this, profile)); |
| 123 |
| 110 CommandLine* cl = CommandLine::ForCurrentProcess(); | 124 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 111 if (cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) { | 125 if ((provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) && |
| 126 cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) { |
| 112 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile, | 127 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile, |
| 113 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix)); | 128 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix)); |
| 114 providers_.push_back(zero_suggest_provider_); | 129 providers_.push_back(zero_suggest_provider_); |
| 115 } | 130 } |
| 131 |
| 116 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) | 132 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) |
| 117 (*i)->AddRef(); | 133 (*i)->AddRef(); |
| 118 } | 134 } |
| 119 | 135 |
| 120 AutocompleteController::~AutocompleteController() { | 136 AutocompleteController::~AutocompleteController() { |
| 121 // The providers may have tasks outstanding that hold refs to them. We need | 137 // The providers may have tasks outstanding that hold refs to them. We need |
| 122 // to ensure they won't call us back if they outlive us. (Practically, | 138 // to ensure they won't call us back if they outlive us. (Practically, |
| 123 // calling Stop() should also cancel those tasks and make it so that we hold | 139 // calling Stop() should also cancel those tasks and make it so that we hold |
| 124 // the only refs.) We also don't want to bother notifying anyone of our | 140 // the only refs.) We also don't want to bother notifying anyone of our |
| 125 // result changes here, because the notification observer is in the midst of | 141 // result changes here, because the notification observer is in the midst of |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms( | 402 match->destination_url = GURL(template_url->url_ref().ReplaceSearchTerms( |
| 387 *match->search_terms_args)); | 403 *match->search_terms_args)); |
| 388 } | 404 } |
| 389 } | 405 } |
| 390 | 406 |
| 391 void AutocompleteController::UpdateKeywordDescriptions( | 407 void AutocompleteController::UpdateKeywordDescriptions( |
| 392 AutocompleteResult* result) { | 408 AutocompleteResult* result) { |
| 393 string16 last_keyword; | 409 string16 last_keyword; |
| 394 for (AutocompleteResult::iterator i(result->begin()); i != result->end(); | 410 for (AutocompleteResult::iterator i(result->begin()); i != result->end(); |
| 395 ++i) { | 411 ++i) { |
| 396 if ((i->provider == keyword_provider_ && !i->keyword.empty()) || | 412 if ((i->provider->type() == AutocompleteProvider::TYPE_KEYWORD && |
| 397 (i->provider == search_provider_ && | 413 !i->keyword.empty()) || |
| 414 (i->provider->type() == AutocompleteProvider::TYPE_SEARCH && |
| 398 AutocompleteMatch::IsSearchType(i->type))) { | 415 AutocompleteMatch::IsSearchType(i->type))) { |
| 399 i->description.clear(); | 416 i->description.clear(); |
| 400 i->description_class.clear(); | 417 i->description_class.clear(); |
| 401 DCHECK(!i->keyword.empty()); | 418 DCHECK(!i->keyword.empty()); |
| 402 if (i->keyword != last_keyword) { | 419 if (i->keyword != last_keyword) { |
| 403 const TemplateURL* template_url = i->GetTemplateURL(profile_); | 420 const TemplateURL* template_url = i->GetTemplateURL(profile_); |
| 404 if (template_url) { | 421 if (template_url) { |
| 405 i->description = l10n_util::GetStringFUTF16( | 422 i->description = l10n_util::GetStringFUTF16( |
| 406 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, | 423 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, |
| 407 template_url->AdjustedShortNameForLocaleDirection()); | 424 template_url->AdjustedShortNameForLocaleDirection()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 437 } | 454 } |
| 438 done_ = true; | 455 done_ = true; |
| 439 } | 456 } |
| 440 | 457 |
| 441 void AutocompleteController::StartExpireTimer() { | 458 void AutocompleteController::StartExpireTimer() { |
| 442 if (result_.HasCopiedMatches()) | 459 if (result_.HasCopiedMatches()) |
| 443 expire_timer_.Start(FROM_HERE, | 460 expire_timer_.Start(FROM_HERE, |
| 444 base::TimeDelta::FromMilliseconds(kExpireTimeMS), | 461 base::TimeDelta::FromMilliseconds(kExpireTimeMS), |
| 445 this, &AutocompleteController::ExpireCopiedEntries); | 462 this, &AutocompleteController::ExpireCopiedEntries); |
| 446 } | 463 } |
| OLD | NEW |