This source file includes following definitions.
- inside_classify_
- Classify
- Shutdown
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "base/auto_reset.h"
#include "chrome/browser/autocomplete/autocomplete_controller.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_provider.h"
#include "url/gurl.h"
const int AutocompleteClassifier::kDefaultOmniboxProviders =
AutocompleteProvider::TYPE_BOOKMARK |
AutocompleteProvider::TYPE_BUILTIN |
AutocompleteProvider::TYPE_HISTORY_QUICK |
AutocompleteProvider::TYPE_HISTORY_URL |
AutocompleteProvider::TYPE_KEYWORD |
AutocompleteProvider::TYPE_SEARCH |
AutocompleteProvider::TYPE_SHORTCUTS |
AutocompleteProvider::TYPE_ZERO_SUGGEST;
AutocompleteClassifier::AutocompleteClassifier(Profile* profile)
: controller_(new AutocompleteController(profile, NULL,
kDefaultOmniboxProviders)),
inside_classify_(false) {
}
AutocompleteClassifier::~AutocompleteClassifier() {
DCHECK(!controller_.get());
}
void AutocompleteClassifier::Classify(
const base::string16& text,
bool prefer_keyword,
bool allow_exact_keyword_match,
AutocompleteInput::PageClassification page_classification,
AutocompleteMatch* match,
GURL* alternate_nav_url) {
DCHECK(!inside_classify_);
base::AutoReset<bool> reset(&inside_classify_, true);
controller_->Start(AutocompleteInput(
text, base::string16::npos, base::string16(), GURL(),
page_classification, true, prefer_keyword,
allow_exact_keyword_match, AutocompleteInput::BEST_MATCH));
DCHECK(controller_->done());
const AutocompleteResult& result = controller_->result();
if (result.empty()) {
if (alternate_nav_url)
*alternate_nav_url = GURL();
return;
}
DCHECK(result.default_match() != result.end());
*match = *result.default_match();
if (alternate_nav_url)
*alternate_nav_url = result.alternate_nav_url();
}
void AutocompleteClassifier::Shutdown() {
controller_.reset();
}