autocomplete_classifier.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/string16.h" 12#include "chrome/browser/profiles/profile_keyed_service.h" 13 14class AutocompleteController; 15struct AutocompleteMatch; 16class GURL; 17class Profile; 18 19class AutocompleteClassifier : public ProfileKeyedService { 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 // Bitmap of AutocompleteProvider::Type values describing the set of providers 27 // that have been whitelisted as working properly with the Instant Extended 28 // API. Intended to be passed to AutocompleteController(). 29 static const int kInstantExtendedOmniboxProviders; 30 31 explicit AutocompleteClassifier(Profile* profile); 32 virtual ~AutocompleteClassifier(); 33 34 // Given some string |text| that the user wants to use for navigation, 35 // determines how it should be interpreted. |desired_tld| is the user's 36 // desired TLD, if any; see AutocompleteInput::desired_tld(). 37 // |prefer_keyword| should be true the when keyword UI is onscreen; see 38 // comments on AutocompleteController::Start(). 39 // |allow_exact_keyword_match| should be true when treating the string as a 40 // potential keyword search is valid; see 41 // AutocompleteInput::allow_exact_keyword_match(). |match| should be a 42 // non-NULL outparam that will be set to the default match for this input, if 43 // any (for invalid input, there will be no default match, and |match| will be 44 // left unchanged). |alternate_nav_url| is a possibly-NULL outparam that, if 45 // non-NULL, will be set to the navigational URL (if any) in case of an 46 // accidental search; see comments on 47 // AutocompleteResult::alternate_nav_url_ in autocomplete.h. 48 void Classify(const string16& text, 49 const string16& desired_tld, 50 bool prefer_keyword, 51 bool allow_exact_keyword_match, 52 AutocompleteMatch* match, 53 GURL* alternate_nav_url); 54 55 private: 56 // ProfileKeyedService: 57 virtual void Shutdown() OVERRIDE; 58 59 scoped_ptr<AutocompleteController> controller_; 60 61 // Are we currently in Classify? Used to verify Classify isn't invoked 62 // recursively, since this can corrupt state and cause crashes. 63 bool inside_classify_; 64 65 DISALLOW_IMPLICIT_CONSTRUCTORS(AutocompleteClassifier); 66}; 67 68#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_ 69