Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / autocomplete / history_quick_provider.h
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_HISTORY_QUICK_PROVIDER_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/autocomplete/history_provider.h"
13 #include "chrome/browser/history/in_memory_url_index.h"
14 #include "components/history/core/browser/history_types.h"
15 #include "components/omnibox/autocomplete_input.h"
16 #include "components/omnibox/autocomplete_match.h"
17
18 class Profile;
19
20 namespace history {
21 class ScoredHistoryMatch;
22 }  // namespace history
23
24 // This class is an autocomplete provider (a pseudo-internal component of
25 // the history system) which quickly (and synchronously) provides matching
26 // results from recently or frequently visited sites in the profile's
27 // history.
28 class HistoryQuickProvider : public HistoryProvider {
29  public:
30   explicit HistoryQuickProvider(Profile* profile);
31
32   // AutocompleteProvider. |minimal_changes| is ignored since there is no asynch
33   // completion performed.
34   void Start(const AutocompleteInput& input, bool minimal_changes) override;
35
36   // Disable this provider. For unit testing purposes only. This is required
37   // because this provider is closely associated with the HistoryURLProvider
38   // and in order to properly test the latter the HistoryQuickProvider must
39   // be disabled.
40   // TODO(mrossetti): Eliminate this once the HUP has been refactored.
41   static void set_disabled(bool disabled) { disabled_ = disabled; }
42
43  private:
44   friend class HistoryQuickProviderTest;
45   FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans);
46   FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Relevance);
47
48   ~HistoryQuickProvider() override;
49
50   // Performs the autocomplete matching and scoring.
51   void DoAutocomplete();
52
53   // Creates an AutocompleteMatch from |history_match|, assigning it
54   // the score |score|.
55   AutocompleteMatch QuickMatchToACMatch(
56       const history::ScoredHistoryMatch& history_match,
57       int score);
58
59   // Returns the index that should be used for history lookups.
60   history::InMemoryURLIndex* GetIndex();
61
62   // Only for use in unittests.  Takes ownership of |index|.
63   void set_index(history::InMemoryURLIndex* index) {
64     index_for_testing_.reset(index);
65   }
66
67   AutocompleteInput autocomplete_input_;
68   std::string languages_;
69
70   // Only used for testing.
71   scoped_ptr<history::InMemoryURLIndex> index_for_testing_;
72
73   // This provider is disabled when true.
74   static bool disabled_;
75
76   DISALLOW_COPY_AND_ASSIGN(HistoryQuickProvider);
77 };
78
79 #endif  // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_