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