Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / autocomplete / autocomplete_classifier.cc
blobb8169add958c971931076ee17c52b66e529e7293
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"
12 #include "url/gurl.h"
14 // static
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(const base::string16& text,
37 bool prefer_keyword,
38 bool allow_exact_keyword_match,
39 AutocompleteMatch* match,
40 GURL* alternate_nav_url) {
41 DCHECK(!inside_classify_);
42 base::AutoReset<bool> reset(&inside_classify_, true);
43 controller_->Start(AutocompleteInput(
44 text, base::string16::npos, base::string16(), GURL(),
45 AutocompleteInput::INVALID_SPEC, true, prefer_keyword,
46 allow_exact_keyword_match, AutocompleteInput::BEST_MATCH));
47 DCHECK(controller_->done());
48 const AutocompleteResult& result = controller_->result();
49 if (result.empty()) {
50 if (alternate_nav_url)
51 *alternate_nav_url = GURL();
52 return;
55 DCHECK(result.default_match() != result.end());
56 *match = *result.default_match();
57 if (alternate_nav_url)
58 *alternate_nav_url = result.alternate_nav_url();
61 void AutocompleteClassifier::Shutdown() {
62 controller_.reset();