Home | History | Annotate | Download | only in autocomplete
      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 
     14 class AutocompleteController;
     15 struct AutocompleteMatch;
     16 class GURL;
     17 class Profile;
     18 
     19 class 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   // 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.
     36   // |prefer_keyword| should be true the when keyword UI is onscreen; see
     37   // comments on AutocompleteController::Start().
     38   // |allow_exact_keyword_match| should be true when treating the string as a
     39   // potential keyword search is valid; see
     40   // AutocompleteInput::allow_exact_keyword_match(). |match| should be a
     41   // non-NULL outparam that will be set to the default match for this input, if
     42   // any (for invalid input, there will be no default match, and |match| will be
     43   // left unchanged).  |alternate_nav_url| is a possibly-NULL outparam that, if
     44   // non-NULL, will be set to the navigational URL (if any) in case of an
     45   // accidental search; see comments on
     46   // AutocompleteResult::alternate_nav_url_ in autocomplete.h.
     47   void Classify(const string16& text,
     48                 bool prefer_keyword,
     49                 bool allow_exact_keyword_match,
     50                 AutocompleteMatch* match,
     51                 GURL* alternate_nav_url);
     52 
     53  private:
     54   // BrowserContextKeyedService:
     55   virtual void Shutdown() OVERRIDE;
     56 
     57   scoped_ptr<AutocompleteController> controller_;
     58 
     59   // Are we currently in Classify? Used to verify Classify isn't invoked
     60   // recursively, since this can corrupt state and cause crashes.
     61   bool inside_classify_;
     62 
     63   DISALLOW_IMPLICIT_CONSTRUCTORS(AutocompleteClassifier);
     64 };
     65 
     66 #endif  // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
     67