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
3 // found in the LICENSE file.
5 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
7 #include "base/auto_reset.h"
8 #include "chrome/browser/autocomplete/autocomplete_controller.h"
9 #include "chrome/browser/autocomplete/autocomplete_input.h"
10 #include "chrome/browser/autocomplete/autocomplete_match.h"
11 #include "chrome/browser/autocomplete/autocomplete_provider.h"
15 const int AutocompleteClassifier::kDefaultOmniboxProviders
=
16 AutocompleteProvider::TYPE_BOOKMARK
|
17 AutocompleteProvider::TYPE_BUILTIN
|
18 AutocompleteProvider::TYPE_HISTORY_QUICK
|
19 AutocompleteProvider::TYPE_HISTORY_URL
|
20 AutocompleteProvider::TYPE_KEYWORD
|
21 AutocompleteProvider::TYPE_SEARCH
|
22 AutocompleteProvider::TYPE_SHORTCUTS
|
23 AutocompleteProvider::TYPE_ZERO_SUGGEST
;
25 AutocompleteClassifier::AutocompleteClassifier(Profile
* profile
)
26 : controller_(new AutocompleteController(profile
, NULL
,
27 kDefaultOmniboxProviders
)),
28 inside_classify_(false) {
31 AutocompleteClassifier::~AutocompleteClassifier() {
32 // We should only reach here after Shutdown() has been called.
33 DCHECK(!controller_
.get());
36 void AutocompleteClassifier::Classify(
37 const base::string16
& text
,
39 bool allow_exact_keyword_match
,
40 AutocompleteInput::PageClassification page_classification
,
41 AutocompleteMatch
* match
,
42 GURL
* alternate_nav_url
) {
43 DCHECK(!inside_classify_
);
44 base::AutoReset
<bool> reset(&inside_classify_
, true);
45 controller_
->Start(AutocompleteInput(
46 text
, base::string16::npos
, base::string16(), GURL(),
47 page_classification
, true, prefer_keyword
,
48 allow_exact_keyword_match
, false));
49 DCHECK(controller_
->done());
50 const AutocompleteResult
& result
= controller_
->result();
52 if (alternate_nav_url
)
53 *alternate_nav_url
= GURL();
57 DCHECK(result
.default_match() != result
.end());
58 *match
= *result
.default_match();
59 if (alternate_nav_url
)
60 *alternate_nav_url
= result
.alternate_nav_url();
63 void AutocompleteClassifier::Shutdown() {