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_
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"
21 FORWARD_DECLARE_TEST(MixerTest
, Publish
);
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
{
35 // The enum represents mixer groups. Each must have a Group added in Init().
41 SUGGESTIONS_GROUP
= 4,
42 LAUNCHER_SEARCH_API_GROUP
= 5
45 explicit Mixer(AppListModel::SearchResults
* ui_results
);
48 // Creates mixer groups.
51 // Associates a provider with a mixer group.
52 void AddProviderToGroup(GroupId group
, SearchProvider
* provider
);
54 // Collects the results, sorts and publishes them.
55 void MixAndPublish(bool is_voice_query
, const KnownResults
& known_results
);
58 FRIEND_TEST_ALL_PREFIXES(test::MixerTest
, Publish
);
60 // Used for sorting and mixing results.
61 struct APP_LIST_EXPORT SortData
{
63 SortData(SearchResult
* result
, double score
);
65 bool operator<(const SortData
& other
) const;
67 SearchResult
* result
; // Not owned.
70 typedef std::vector
<Mixer::SortData
> SortedResults
;
73 typedef std::map
<GroupId
, linked_ptr
<Group
>> Groups
;
75 // Publishes the given |new_results| to |ui_results|, deleting any existing
76 // results that are not in |new_results|. Results that already exist in
77 // |ui_results| are reused to avoid flickering caused by icon reload.
78 static void Publish(const SortedResults
& results
,
79 AppListModel::SearchResults
* ui_results
);
81 // Removes duplicates from |results|.
82 static void RemoveDuplicates(SortedResults
* results
);
84 void FetchResults(bool is_voice_query
, const KnownResults
& known_results
);
86 AppListModel::SearchResults
* ui_results_
; // Not owned.
89 DISALLOW_COPY_AND_ASSIGN(Mixer
);
92 } // namespace app_list
94 #endif // UI_APP_LIST_SEARCH_MIXER_H_