Chromium Code Reviews| 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/gtest_prod_util.h" | |
| 9 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| 10 #include "chrome/browser/ui/app_list/search/history_types.h" | 11 #include "chrome/browser/ui/app_list/search/history_types.h" |
| 11 #include "ui/app_list/app_list_model.h" | 12 #include "ui/app_list/app_list_model.h" |
| 12 | 13 |
| 13 namespace app_list { | 14 namespace app_list { |
| 14 | 15 |
| 16 namespace test { | |
| 17 FORWARD_DECLARE_TEST(MixerTest, Publish); | |
| 18 } | |
| 19 | |
| 20 class ChromeSearchResult; | |
| 15 class SearchProvider; | 21 class SearchProvider; |
| 16 | 22 |
| 17 // Mixer collects results from providers, sorts them and publishes them to the | 23 // 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 | 24 // 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 | 25 // result. These slots could be viewed as having three groups: main group |
| 20 // (local apps and contacts), omnibox group and web store group. The | 26 // (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 | 27 // 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. | 28 // slots. The omnibox group takes all the remaining slots. |
| 23 class Mixer { | 29 class Mixer { |
| 24 public: | 30 public: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 37 // Creates mixer groups. | 43 // Creates mixer groups. |
| 38 void Init(); | 44 void Init(); |
| 39 | 45 |
| 40 // Associates a provider with a mixer group. | 46 // Associates a provider with a mixer group. |
| 41 void AddProviderToGroup(GroupId group, SearchProvider* provider); | 47 void AddProviderToGroup(GroupId group, SearchProvider* provider); |
| 42 | 48 |
| 43 // Collects the results, sorts and publishes them. | 49 // Collects the results, sorts and publishes them. |
| 44 void MixAndPublish(const KnownResults& known_results); | 50 void MixAndPublish(const KnownResults& known_results); |
| 45 | 51 |
| 46 private: | 52 private: |
| 53 FRIEND_TEST_ALL_PREFIXES(test::MixerTest, Publish); | |
| 54 | |
| 55 // Used for sorting and mixing results. | |
| 56 struct SortData { | |
| 57 SortData(); | |
| 58 SortData(ChromeSearchResult* result, double score); | |
| 59 | |
| 60 bool operator<(const SortData& other) const; | |
| 61 | |
| 62 ChromeSearchResult* result; // Not owned. | |
| 63 double score; | |
| 64 }; | |
| 65 typedef std::vector<Mixer::SortData> SortedResults; | |
| 66 | |
| 47 class Group; | 67 class Group; |
| 48 typedef ScopedVector<Group> Groups; | 68 typedef ScopedVector<Group> Groups; |
| 49 | 69 |
| 70 // Publishes the given |results| to |ui_results|. Reuse existing ones to avoid | |
| 71 // flickering. | |
| 72 void Publish(const SortedResults& results, | |
|
Matt Giuca
2014/07/08 06:09:08
Please make this (and RemoveDuplicates) static. (T
calamity
2014/07/08 07:54:31
Done.
| |
| 73 AppListModel::SearchResults* ui_results); | |
| 74 | |
| 50 void FetchResults(const KnownResults& known_results); | 75 void FetchResults(const KnownResults& known_results); |
| 51 | 76 |
| 77 // Removes duplicates from |results|. | |
| 78 void RemoveDuplicates(SortedResults* results); | |
| 79 | |
| 52 AppListModel::SearchResults* ui_results_; // Not owned. | 80 AppListModel::SearchResults* ui_results_; // Not owned. |
| 53 Groups groups_; | 81 Groups groups_; |
| 54 | 82 |
| 55 DISALLOW_COPY_AND_ASSIGN(Mixer); | 83 DISALLOW_COPY_AND_ASSIGN(Mixer); |
| 56 }; | 84 }; |
| 57 | 85 |
| 58 } // namespace app_list | 86 } // namespace app_list |
| 59 | 87 |
| 60 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_MIXER_H_ | 88 #endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_MIXER_H_ |
| OLD | NEW |