Workaround for xkbcommon dead keys.
[chromium-blink-merge.git] / ui / app_list / search / mixer.h
blob611db2be66be7c250d7093ee54276627707bf580
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 <map>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/linked_ptr.h"
14 #include "ui/app_list/app_list_export.h"
15 #include "ui/app_list/app_list_model.h"
16 #include "ui/app_list/search/history_types.h"
18 namespace app_list {
20 namespace test {
21 FORWARD_DECLARE_TEST(MixerTest, Publish);
24 class SearchProvider;
25 class SearchResult;
27 // Mixer collects results from providers, sorts them and publishes them to the
28 // SearchResults UI model. The targeted results have 6 slots to hold the
29 // result. These slots could be viewed as having three groups: main group
30 // (local apps and contacts), omnibox group and web store group. The
31 // main group takes no more than 4 slots. The web store takes no more than 2
32 // slots. The omnibox group takes all the remaining slots.
33 class APP_LIST_EXPORT Mixer {
34 public:
35 // The enum represents mixer groups. Each must have a Group added in Init().
36 enum GroupId {
37 MAIN_GROUP = 0,
38 OMNIBOX_GROUP = 1,
39 WEBSTORE_GROUP = 2,
40 PEOPLE_GROUP = 3,
41 SUGGESTIONS_GROUP = 4,
44 explicit Mixer(AppListModel::SearchResults* ui_results);
45 ~Mixer();
47 // Creates mixer groups.
48 void Init();
50 // Associates a provider with a mixer group.
51 void AddProviderToGroup(GroupId group, SearchProvider* provider);
53 // Collects the results, sorts and publishes them.
54 void MixAndPublish(bool is_voice_query, const KnownResults& known_results);
56 private:
57 FRIEND_TEST_ALL_PREFIXES(test::MixerTest, Publish);
59 // Used for sorting and mixing results.
60 struct APP_LIST_EXPORT SortData {
61 SortData();
62 SortData(SearchResult* result, double score);
64 bool operator<(const SortData& other) const;
66 SearchResult* result; // Not owned.
67 double score;
69 typedef std::vector<Mixer::SortData> SortedResults;
71 class Group;
72 typedef std::map<GroupId, linked_ptr<Group>> Groups;
74 // Publishes the given |new_results| to |ui_results|, deleting any existing
75 // results that are not in |new_results|. Results that already exist in
76 // |ui_results| are reused to avoid flickering caused by icon reload.
77 static void Publish(const SortedResults& results,
78 AppListModel::SearchResults* ui_results);
80 // Removes duplicates from |results|.
81 static void RemoveDuplicates(SortedResults* results);
83 void FetchResults(bool is_voice_query, const KnownResults& known_results);
85 AppListModel::SearchResults* ui_results_; // Not owned.
86 Groups groups_;
88 DISALLOW_COPY_AND_ASSIGN(Mixer);
91 } // namespace app_list
93 #endif // UI_APP_LIST_SEARCH_MIXER_H_