OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_APP_LIST_SEARCH_MIXER_H_ | 5 #ifndef UI_APP_LIST_SEARCH_MIXER_H_ |
6 #define UI_APP_LIST_SEARCH_MIXER_H_ | 6 #define UI_APP_LIST_SEARCH_MIXER_H_ |
7 | 7 |
8 #include <map> | |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
13 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/scoped_vector.h" |
14 #include "ui/app_list/app_list_export.h" | 13 #include "ui/app_list/app_list_export.h" |
15 #include "ui/app_list/app_list_model.h" | 14 #include "ui/app_list/app_list_model.h" |
16 #include "ui/app_list/search/history_types.h" | 15 #include "ui/app_list/search/history_types.h" |
17 | 16 |
18 namespace app_list { | 17 namespace app_list { |
19 | 18 |
20 namespace test { | 19 namespace test { |
21 FORWARD_DECLARE_TEST(MixerTest, Publish); | 20 FORWARD_DECLARE_TEST(MixerTest, Publish); |
22 } | 21 } |
23 | 22 |
24 class SearchProvider; | 23 class SearchProvider; |
25 class SearchResult; | 24 class SearchResult; |
26 | 25 |
27 // Mixer collects results from providers, sorts them and publishes them to the | 26 // 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 | 27 // 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 | 28 // result. The search controller can specify any number of groups, each with a |
30 // (local apps and contacts), omnibox group and web store group. The | 29 // different number of results and priority boost. The special group with ID |
31 // main group takes no more than 4 slots. The web store takes no more than 2 | 30 // OMNIBOX_GROUP is expected to contain omnibox results, and will be treated |
32 // slots. The omnibox group takes all the remaining slots. | 31 // specially. |
33 class APP_LIST_EXPORT Mixer { | 32 class APP_LIST_EXPORT Mixer { |
34 public: | 33 public: |
35 // The enum represents mixer groups. Each must have a Group added in Init(). | 34 // The ID of the omnibox group. The group with this ID will be treated |
36 enum GroupId { | 35 // specially by the Mixer (it will be truncated such that it fills the |
37 MAIN_GROUP = 0, | 36 // remaining slots without overflowing, but with at least one result). |
38 OMNIBOX_GROUP = 1, | 37 // TODO(mgiuca): Omnibox group should not be treated specially. |
39 WEBSTORE_GROUP = 2, | 38 static const size_t OMNIBOX_GROUP; |
calamity
2015/04/10 03:34:18
Can we make an omnibox_group_ field that gets set
Matt Giuca
2015/04/10 03:49:19
Done.
| |
40 PEOPLE_GROUP = 3, | |
41 SUGGESTIONS_GROUP = 4, | |
42 }; | |
43 | 39 |
44 explicit Mixer(AppListModel::SearchResults* ui_results); | 40 explicit Mixer(AppListModel::SearchResults* ui_results); |
45 ~Mixer(); | 41 ~Mixer(); |
46 | 42 |
47 // Creates mixer groups. | 43 // Adds a new mixer group. A maximum of |max_results| results will be |
48 void Init(); | 44 // displayed from this group (if 0, will allow unlimited results from this |
45 // group). Each result in the group will have its score boosted by |boost|. | |
46 // Returns the group's group_id. | |
47 size_t AddGroup(size_t max_results, double boost); | |
49 | 48 |
50 // Associates a provider with a mixer group. | 49 // Associates a provider with a mixer group. |
51 void AddProviderToGroup(GroupId group, SearchProvider* provider); | 50 void AddProviderToGroup(size_t group_id, SearchProvider* provider); |
52 | 51 |
53 // Collects the results, sorts and publishes them. | 52 // Collects the results, sorts and publishes them. |
54 void MixAndPublish(bool is_voice_query, const KnownResults& known_results); | 53 void MixAndPublish(bool is_voice_query, const KnownResults& known_results); |
55 | 54 |
56 private: | 55 private: |
57 FRIEND_TEST_ALL_PREFIXES(test::MixerTest, Publish); | 56 FRIEND_TEST_ALL_PREFIXES(test::MixerTest, Publish); |
58 | 57 |
59 // Used for sorting and mixing results. | 58 // Used for sorting and mixing results. |
60 struct APP_LIST_EXPORT SortData { | 59 struct APP_LIST_EXPORT SortData { |
61 SortData(); | 60 SortData(); |
62 SortData(SearchResult* result, double score); | 61 SortData(SearchResult* result, double score); |
63 | 62 |
64 bool operator<(const SortData& other) const; | 63 bool operator<(const SortData& other) const; |
65 | 64 |
66 SearchResult* result; // Not owned. | 65 SearchResult* result; // Not owned. |
67 double score; | 66 double score; |
68 }; | 67 }; |
69 typedef std::vector<Mixer::SortData> SortedResults; | 68 typedef std::vector<Mixer::SortData> SortedResults; |
70 | 69 |
71 class Group; | 70 class Group; |
72 typedef std::map<GroupId, linked_ptr<Group>> Groups; | 71 typedef ScopedVector<Group> Groups; |
73 | 72 |
74 // Publishes the given |new_results| to |ui_results|, deleting any existing | 73 // Publishes the given |new_results| to |ui_results|, deleting any existing |
75 // results that are not in |new_results|. Results that already exist in | 74 // results that are not in |new_results|. Results that already exist in |
76 // |ui_results| are reused to avoid flickering caused by icon reload. | 75 // |ui_results| are reused to avoid flickering caused by icon reload. |
77 static void Publish(const SortedResults& results, | 76 static void Publish(const SortedResults& results, |
78 AppListModel::SearchResults* ui_results); | 77 AppListModel::SearchResults* ui_results); |
79 | 78 |
80 // Removes duplicates from |results|. | 79 // Removes duplicates from |results|. |
81 static void RemoveDuplicates(SortedResults* results); | 80 static void RemoveDuplicates(SortedResults* results); |
82 | 81 |
83 void FetchResults(bool is_voice_query, const KnownResults& known_results); | 82 void FetchResults(bool is_voice_query, const KnownResults& known_results); |
84 | 83 |
85 AppListModel::SearchResults* ui_results_; // Not owned. | 84 AppListModel::SearchResults* ui_results_; // Not owned. |
86 Groups groups_; | 85 Groups groups_; |
87 | 86 |
88 DISALLOW_COPY_AND_ASSIGN(Mixer); | 87 DISALLOW_COPY_AND_ASSIGN(Mixer); |
89 }; | 88 }; |
90 | 89 |
91 } // namespace app_list | 90 } // namespace app_list |
92 | 91 |
93 #endif // UI_APP_LIST_SEARCH_MIXER_H_ | 92 #endif // UI_APP_LIST_SEARCH_MIXER_H_ |
OLD | NEW |