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_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/autocomplete_input.h"
     13 #include "chrome/browser/autocomplete/autocomplete_match.h"
     14 #include "chrome/browser/autocomplete/history_provider.h"
     15 #include "chrome/browser/history/history_types.h"
     16 #include "chrome/browser/history/in_memory_url_index.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   HistoryQuickProvider(AutocompleteProviderListener* listener,
     31                        Profile* profile);
     32 
     33   // AutocompleteProvider. |minimal_changes| is ignored since there is no asynch
     34   // completion performed.
     35   virtual void Start(const AutocompleteInput& input,
     36                      bool minimal_changes) OVERRIDE;
     37 
     38   // Disable this provider. For unit testing purposes only. This is required
     39   // because this provider is closely associated with the HistoryURLProvider
     40   // and in order to properly test the latter the HistoryQuickProvider must
     41   // be disabled.
     42   // TODO(mrossetti): Eliminate this once the HUP has been refactored.
     43   static void set_disabled(bool disabled) { disabled_ = disabled; }
     44 
     45  private:
     46   friend class HistoryQuickProviderTest;
     47   FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Spans);
     48   FRIEND_TEST_ALL_PREFIXES(HistoryQuickProviderTest, Relevance);
     49 
     50   virtual ~HistoryQuickProvider();
     51 
     52   // Performs the autocomplete matching and scoring.
     53   void DoAutocomplete();
     54 
     55   // Creates an AutocompleteMatch from |history_match|, assigning it
     56   // the score |score|.
     57   AutocompleteMatch QuickMatchToACMatch(
     58       const history::ScoredHistoryMatch& history_match,
     59       int score);
     60 
     61   // Returns the index that should be used for history lookups.
     62   history::InMemoryURLIndex* GetIndex();
     63 
     64   // Only for use in unittests.  Takes ownership of |index|.
     65   void set_index(history::InMemoryURLIndex* index) {
     66     index_for_testing_.reset(index);
     67   }
     68 
     69   AutocompleteInput autocomplete_input_;
     70   std::string languages_;
     71 
     72   // Only used for testing.
     73   scoped_ptr<history::InMemoryURLIndex> index_for_testing_;
     74 
     75   // This provider is disabled when true.
     76   static bool disabled_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(HistoryQuickProvider);
     79 };
     80 
     81 #endif  // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_QUICK_PROVIDER_H_
     82