autocomplete_classifier.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
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.
4
5#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
6#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
7
8#include "base/basictypes.h"
9#include "base/compiler_specific.h"
10#include "base/memory/scoped_ptr.h"
11#include "base/strings/string16.h"
12#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
13
14class AutocompleteController;
15struct AutocompleteMatch;
16class GURL;
17class Profile;
18
19class AutocompleteClassifier : public BrowserContextKeyedService {
20 public:
21  // Bitmap of AutocompleteProvider::Type values describing the default set of
22  // providers queried for the omnibox.  Intended to be passed to
23  // AutocompleteController().
24  static const int kDefaultOmniboxProviders;
25
26  explicit AutocompleteClassifier(Profile* profile);
27  virtual ~AutocompleteClassifier();
28
29  // Given some string |text| that the user wants to use for navigation,
30  // determines how it should be interpreted.
31  // |prefer_keyword| should be true the when keyword UI is onscreen; see
32  // comments on AutocompleteController::Start().
33  // |allow_exact_keyword_match| should be true when treating the string as a
34  // potential keyword search is valid; see
35  // AutocompleteInput::allow_exact_keyword_match(). |match| should be a
36  // non-NULL outparam that will be set to the default match for this input, if
37  // any (for invalid input, there will be no default match, and |match| will be
38  // left unchanged).  |alternate_nav_url| is a possibly-NULL outparam that, if
39  // non-NULL, will be set to the navigational URL (if any) in case of an
40  // accidental search; see comments on
41  // AutocompleteResult::alternate_nav_url_ in autocomplete.h.
42  void Classify(const string16& text,
43                bool prefer_keyword,
44                bool allow_exact_keyword_match,
45                AutocompleteMatch* match,
46                GURL* alternate_nav_url);
47
48 private:
49  // BrowserContextKeyedService:
50  virtual void Shutdown() OVERRIDE;
51
52  scoped_ptr<AutocompleteController> controller_;
53
54  // Are we currently in Classify? Used to verify Classify isn't invoked
55  // recursively, since this can corrupt state and cause crashes.
56  bool inside_classify_;
57
58  DISALLOW_IMPLICIT_CONSTRUCTORS(AutocompleteClassifier);
59};
60
61#endif  // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
62