15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
12a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/core/keyed_service.h"
136d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/metrics/proto/omnibox_event.pb.h"
145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/omnibox/autocomplete_scheme_classifier.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutocompleteController;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct AutocompleteMatch;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class AutocompleteClassifier : public KeyedService {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Bitmap of AutocompleteProvider::Type values describing the default set of
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // providers queried for the omnibox.  Intended to be passed to
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // AutocompleteController().
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int kDefaultOmniboxProviders;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  AutocompleteClassifier(
28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      scoped_ptr<AutocompleteController> controller_,
29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      scoped_ptr<AutocompleteSchemeClassifier> scheme_classifier);
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~AutocompleteClassifier();
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Given some string |text| that the user wants to use for navigation,
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // determines how it should be interpreted.
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |prefer_keyword| should be true the when keyword UI is onscreen; see
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // comments on AutocompleteController::Start().
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |allow_exact_keyword_match| should be true when treating the string as a
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // potential keyword search is valid; see
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // AutocompleteInput::allow_exact_keyword_match().
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |page_classification| gives information about the context (e.g., is the
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // user on a search results page doing search term replacement); this may
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // be useful in deciding how the input should be interpreted.
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |match| should be a non-NULL outparam that will be set to the default
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // match for this input, if any (for invalid input, there will be no default
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // match, and |match| will be left unchanged).  |alternate_nav_url| is a
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // possibly-NULL outparam that, if non-NULL, will be set to the navigational
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // URL (if any) in case of an accidental search; see comments on
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // AutocompleteResult::alternate_nav_url_ in autocomplete.h.
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void Classify(const base::string16& text,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                bool prefer_keyword,
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                bool allow_exact_keyword_match,
516d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                metrics::OmniboxEventProto::PageClassification
526d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                    page_classification,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                AutocompleteMatch* match,
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                GURL* alternate_nav_url);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // KeyedService:
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Shutdown() OVERRIDE;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<AutocompleteController> controller_;
61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  scoped_ptr<AutocompleteSchemeClassifier> scheme_classifier_;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Are we currently in Classify? Used to verify Classify isn't invoked
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // recursively, since this can corrupt state and cause crashes.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool inside_classify_;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_IMPLICIT_CONSTRUCTORS(AutocompleteClassifier);
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_CLASSIFIER_H_
71