1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
6
7 #include "base/auto_reset.h"
8 #include "chrome/browser/autocomplete/autocomplete.h"
9 #include "chrome/browser/autocomplete/autocomplete_match.h"
10 #include "googleurl/src/gurl.h"
11
AutocompleteClassifier(Profile * profile)12 AutocompleteClassifier::AutocompleteClassifier(Profile* profile)
13 : controller_(new AutocompleteController(profile, NULL)),
14 inside_classify_(false) {
15 }
16
~AutocompleteClassifier()17 AutocompleteClassifier::~AutocompleteClassifier() {
18 }
19
Classify(const string16 & text,const string16 & desired_tld,bool allow_exact_keyword_match,AutocompleteMatch * match,GURL * alternate_nav_url)20 void AutocompleteClassifier::Classify(const string16& text,
21 const string16& desired_tld,
22 bool allow_exact_keyword_match,
23 AutocompleteMatch* match,
24 GURL* alternate_nav_url) {
25 DCHECK(!inside_classify_);
26 AutoReset<bool> reset(&inside_classify_, true);
27 controller_->Start(text, desired_tld, true, false, allow_exact_keyword_match,
28 AutocompleteInput::BEST_MATCH);
29 DCHECK(controller_->done());
30 const AutocompleteResult& result = controller_->result();
31 if (result.empty()) {
32 if (alternate_nav_url)
33 *alternate_nav_url = GURL();
34 return;
35 }
36
37 DCHECK(result.default_match() != result.end());
38 *match = *result.default_match();
39 if (alternate_nav_url)
40 *alternate_nav_url = result.alternate_nav_url();
41 }
42