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 "components/metrics/proto/omnibox_event.pb.h"
10 #include "components/omnibox/autocomplete_input.h"
11 #include "components/omnibox/autocomplete_match.h"
12 #include "components/omnibox/autocomplete_provider.h"
16 const int AutocompleteClassifier::kDefaultOmniboxProviders
=
17 AutocompleteProvider::TYPE_BOOKMARK
|
18 AutocompleteProvider::TYPE_BUILTIN
|
19 AutocompleteProvider::TYPE_HISTORY_QUICK
|
20 AutocompleteProvider::TYPE_HISTORY_URL
|
21 AutocompleteProvider::TYPE_KEYWORD
|
22 AutocompleteProvider::TYPE_SEARCH
|
23 AutocompleteProvider::TYPE_SHORTCUTS
|
24 AutocompleteProvider::TYPE_ZERO_SUGGEST
;
26 AutocompleteClassifier::AutocompleteClassifier(
27 scoped_ptr
<AutocompleteController
> controller
,
28 scoped_ptr
<AutocompleteSchemeClassifier
> scheme_classifier
)
29 : controller_(controller
.Pass()),
30 scheme_classifier_(scheme_classifier
.Pass()),
31 inside_classify_(false) {
34 AutocompleteClassifier::~AutocompleteClassifier() {
35 // We should only reach here after Shutdown() has been called.
36 DCHECK(!controller_
.get());
39 void AutocompleteClassifier::Classify(
40 const base::string16
& text
,
42 bool allow_exact_keyword_match
,
43 metrics::OmniboxEventProto::PageClassification page_classification
,
44 AutocompleteMatch
* match
,
45 GURL
* alternate_nav_url
) {
46 DCHECK(!inside_classify_
);
47 base::AutoReset
<bool> reset(&inside_classify_
, true);
48 controller_
->Start(AutocompleteInput(
49 text
, base::string16::npos
, std::string(), GURL(), page_classification
,
50 true, prefer_keyword
, allow_exact_keyword_match
, false,
51 *scheme_classifier_
));
52 DCHECK(controller_
->done());
53 const AutocompleteResult
& result
= controller_
->result();
55 if (alternate_nav_url
)
56 *alternate_nav_url
= GURL();
60 DCHECK(result
.default_match() != result
.end());
61 *match
= *result
.default_match();
62 if (alternate_nav_url
)
63 *alternate_nav_url
= result
.alternate_nav_url();
66 void AutocompleteClassifier::Shutdown() {