Remove wpr.archive_info dependancy on page to avoid circular dependancies.
[chromium-blink-merge.git] / ui / app_list / search / mixer.h
blob7de0c1141a6926226a561c14d4487b74c7664005
1 // Copyright 2013 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.
5 #ifndef UI_APP_LIST_SEARCH_MIXER_H_
6 #define UI_APP_LIST_SEARCH_MIXER_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_vector.h"
13 #include "ui/app_list/app_list_export.h"
14 #include "ui/app_list/app_list_model.h"
15 #include "ui/app_list/search/history_types.h"
17 namespace app_list {
19 namespace test {
20 FORWARD_DECLARE_TEST(MixerTest, Publish);
23 class SearchProvider;
24 class SearchResult;
26 // Mixer collects results from providers, sorts them and publishes them to the
27 // SearchResults UI model. The targeted results have 6 slots to hold the
28 // result. The search controller can specify any number of groups, each with a
29 // different number of results and priority boost. The "omnibox" group is
30 // expected to contain omnibox results, and will be treated specially.
31 class APP_LIST_EXPORT Mixer {
32 public:
33 explicit Mixer(AppListModel::SearchResults* ui_results);
34 ~Mixer();
36 // Adds a new mixer group. A maximum of |max_results| results will be
37 // displayed from this group (if 0, will allow unlimited results from this
38 // group). Each result in the group will have its score boosted by |boost|.
39 // Returns the group's group_id.
40 size_t AddGroup(size_t max_results, double boost);
42 // Adds a new mixer group for the special "omnibox" group. This group will be
43 // treated specially by the Mixer (it will be truncated such that it fills the
44 // remaining slots without overflowing, but with at least one result). A
45 // maximum of one group should be added using this method.
46 size_t AddOmniboxGroup(size_t max_results, double boost);
48 // Associates a provider with a mixer group.
49 void AddProviderToGroup(size_t group_id, SearchProvider* provider);
51 // Collects the results, sorts and publishes them.
52 void MixAndPublish(bool is_voice_query, const KnownResults& known_results);
54 private:
55 FRIEND_TEST_ALL_PREFIXES(test::MixerTest, Publish);
57 // Used for sorting and mixing results.
58 struct APP_LIST_EXPORT SortData {
59 SortData();
60 SortData(SearchResult* result, double score);
62 bool operator<(const SortData& other) const;
64 SearchResult* result; // Not owned.
65 double score;
67 typedef std::vector<Mixer::SortData> SortedResults;
69 class Group;
70 typedef ScopedVector<Group> Groups;
72 // Publishes the given |new_results| to |ui_results|, deleting any existing
73 // results that are not in |new_results|. Results that already exist in
74 // |ui_results| are reused to avoid flickering caused by icon reload.
75 static void Publish(const SortedResults& results,
76 AppListModel::SearchResults* ui_results);
78 // Removes duplicates from |results|.
79 static void RemoveDuplicates(SortedResults* results);
81 void FetchResults(bool is_voice_query, const KnownResults& known_results);
83 AppListModel::SearchResults* ui_results_; // Not owned.
84 Groups groups_;
86 // The ID of the omnibox group. The group with this ID will be treated
87 // specially by the Mixer.
88 // TODO(mgiuca): Omnibox group should not be treated specially.
89 size_t omnibox_group_ = 0;
90 // Whether |omnibox_group_| has been set.
91 bool has_omnibox_group_ = false;
93 DISALLOW_COPY_AND_ASSIGN(Mixer);
96 } // namespace app_list
98 #endif // UI_APP_LIST_SEARCH_MIXER_H_