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 CHROME_BROWSER_UI_APP_LIST_SEARCH_MIXER_H_ | 5 #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_MIXER_H_ |
6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_MIXER_H_ | 6 #define CHROME_BROWSER_UI_APP_LIST_SEARCH_MIXER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "chrome/browser/ui/app_list/search/history_types.h" | 10 #include "chrome/browser/ui/app_list/search/history_types.h" |
11 #include "ui/app_list/app_list_model.h" | 11 #include "ui/app_list/app_list_model.h" |
12 | 12 |
13 namespace app_list { | 13 namespace app_list { |
14 | 14 |
15 class ChromeSearchResult; | |
15 class SearchProvider; | 16 class SearchProvider; |
16 | 17 |
17 // Mixer collects results from providers, sorts them and publishes them to the | 18 // Mixer collects results from providers, sorts them and publishes them to the |
18 // SearchResults UI model. The targeted results have 6 slots to hold the | 19 // SearchResults UI model. The targeted results have 6 slots to hold the |
19 // result. These slots could be viewed as having three groups: main group | 20 // result. These slots could be viewed as having three groups: main group |
20 // (local apps and contacts), omnibox group and web store group. The | 21 // (local apps and contacts), omnibox group and web store group. The |
21 // main group takes no more than 4 slots. The web store takes no more than 2 | 22 // main group takes no more than 4 slots. The web store takes no more than 2 |
22 // slots. The omnibox group takes all the remaining slots. | 23 // slots. The omnibox group takes all the remaining slots. |
23 class Mixer { | 24 class Mixer { |
24 public: | 25 public: |
26 // Used for sorting and mixing results. | |
27 struct SortData { | |
28 SortData(); | |
29 SortData(ChromeSearchResult* result, double score); | |
30 | |
31 bool operator<(const SortData& other) const; | |
32 | |
33 ChromeSearchResult* result; // Not owned. | |
34 double score; | |
35 }; | |
36 | |
25 // The enum represents mixer groups. Note this must matches the order | 37 // The enum represents mixer groups. Note this must matches the order |
26 // of group creation in Init(). | 38 // of group creation in Init(). |
27 enum GroupId { | 39 enum GroupId { |
28 MAIN_GROUP = 0, | 40 MAIN_GROUP = 0, |
29 OMNIBOX_GROUP = 1, | 41 OMNIBOX_GROUP = 1, |
30 WEBSTORE_GROUP = 2, | 42 WEBSTORE_GROUP = 2, |
31 PEOPLE_GROUP = 3, | 43 PEOPLE_GROUP = 3, |
32 }; | 44 }; |
33 | 45 |
34 explicit Mixer(AppListModel::SearchResults* ui_results); | 46 explicit Mixer(AppListModel::SearchResults* ui_results); |
35 ~Mixer(); | 47 ~Mixer(); |
36 | 48 |
37 // Creates mixer groups. | 49 // Creates mixer groups. |
38 void Init(); | 50 void Init(); |
39 | 51 |
40 // Associates a provider with a mixer group. | 52 // Associates a provider with a mixer group. |
41 void AddProviderToGroup(GroupId group, SearchProvider* provider); | 53 void AddProviderToGroup(GroupId group, SearchProvider* provider); |
42 | 54 |
43 // Collects the results, sorts and publishes them. | 55 // Collects the results, sorts and publishes them. |
44 void MixAndPublish(const KnownResults& known_results); | 56 void MixAndPublish(const KnownResults& known_results); |
45 | 57 |
58 // Publishes the given |results| to |ui_results|. Reuse existing ones to avoid | |
59 // flickering. | |
60 static void Publish(const std::vector<SortData>& results, | |
Matt Giuca
2014/07/08 01:48:23
I think the standard practice here would be to mak
calamity
2014/07/08 04:23:00
Done-ish. SortData still needs to be public to be
Matt Giuca
2014/07/08 05:31:45
Use FRIEND_TEST_ALL_PREFIXES to actually friend th
| |
61 AppListModel::SearchResults* ui_results); | |
62 | |
46 private: | 63 private: |
47 class Group; | 64 class Group; |
48 typedef ScopedVector<Group> Groups; | 65 typedef ScopedVector<Group> Groups; |
49 | 66 |
50 void FetchResults(const KnownResults& known_results); | 67 void FetchResults(const KnownResults& known_results); |
51 | 68 |
52 AppListModel::SearchResults* ui_results_; // Not owned. | 69 AppListModel::SearchResults* ui_results_; // Not owned. |
53 Groups groups_; | 70 Groups groups_; |
54 | 71 |
55 DISALLOW_COPY_AND_ASSIGN(Mixer); | 72 DISALLOW_COPY_AND_ASSIGN(Mixer); |
56 }; | 73 }; |
57 | 74 |
58 } // namespace app_list | 75 } // namespace app_list |
59 | 76 |
60 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_MIXER_H_ | 77 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_MIXER_H_ |
OLD | NEW |