| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" | 5 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 11 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 12 #include "base/time/default_clock.h" | 13 #include "base/time/default_clock.h" |
| 13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/app_list/search/app_search_provider.h" | 16 #include "chrome/browser/ui/app_list/search/app_search_provider.h" |
| 16 #include "chrome/browser/ui/app_list/search/history_factory.h" | 17 #include "chrome/browser/ui/app_list/search/history_factory.h" |
| 17 #include "chrome/browser/ui/app_list/search/omnibox_provider.h" | 18 #include "chrome/browser/ui/app_list/search/omnibox_provider.h" |
| 18 #include "chrome/browser/ui/app_list/search/people/people_provider.h" | 19 #include "chrome/browser/ui/app_list/search/people/people_provider.h" |
| 19 #include "chrome/browser/ui/app_list/search/suggestions/suggestions_search_provi
der.h" | 20 #include "chrome/browser/ui/app_list/search/suggestions/suggestions_search_provi
der.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // enabled. | 53 // enabled. |
| 53 bool IsSuggestionsSearchProviderEnabled() { | 54 bool IsSuggestionsSearchProviderEnabled() { |
| 54 return base::StartsWith( | 55 return base::StartsWith( |
| 55 base::FieldTrialList::FindFullName(kSuggestionsProviderFieldTrialName), | 56 base::FieldTrialList::FindFullName(kSuggestionsProviderFieldTrialName), |
| 56 kSuggestionsProviderFieldTrialEnabledPrefix, | 57 kSuggestionsProviderFieldTrialEnabledPrefix, |
| 57 base::CompareCase::SENSITIVE); | 58 base::CompareCase::SENSITIVE); |
| 58 } | 59 } |
| 59 | 60 |
| 60 } // namespace | 61 } // namespace |
| 61 | 62 |
| 62 scoped_ptr<SearchController> CreateSearchController( | 63 std::unique_ptr<SearchController> CreateSearchController( |
| 63 Profile* profile, | 64 Profile* profile, |
| 64 AppListModel* model, | 65 AppListModel* model, |
| 65 AppListControllerDelegate* list_controller) { | 66 AppListControllerDelegate* list_controller) { |
| 66 scoped_ptr<SearchController> controller( | 67 std::unique_ptr<SearchController> controller( |
| 67 new SearchController(model->search_box(), model->results(), | 68 new SearchController(model->search_box(), model->results(), |
| 68 HistoryFactory::GetForBrowserContext(profile))); | 69 HistoryFactory::GetForBrowserContext(profile))); |
| 69 | 70 |
| 70 // Add mixer groups. There are four main groups: apps, people, webstore and | 71 // Add mixer groups. There are four main groups: apps, people, webstore and |
| 71 // omnibox. The behaviour depends on the AppListMixer field trial: | 72 // omnibox. The behaviour depends on the AppListMixer field trial: |
| 72 // - If default: The apps, people and webstore groups each have a fixed | 73 // - If default: The apps, people and webstore groups each have a fixed |
| 73 // maximum number of results. The omnibox group fills the remaining slots | 74 // maximum number of results. The omnibox group fills the remaining slots |
| 74 // (with a minimum of one result). | 75 // (with a minimum of one result). |
| 75 // - If "Blended": Each group has a "soft" maximum number of results. However, | 76 // - If "Blended": Each group has a "soft" maximum number of results. However, |
| 76 // if a query turns up very few results, the mixer may take more than this | 77 // if a query turns up very few results, the mixer may take more than this |
| 77 // maximum from a particular group. | 78 // maximum from a particular group. |
| 78 size_t apps_group_id = controller->AddGroup(kMaxAppsGroupResults, 3.0, 1.0); | 79 size_t apps_group_id = controller->AddGroup(kMaxAppsGroupResults, 3.0, 1.0); |
| 79 size_t omnibox_group_id = | 80 size_t omnibox_group_id = |
| 80 controller->AddOmniboxGroup(kMaxOmniboxResults, 2.0, 1.0); | 81 controller->AddOmniboxGroup(kMaxOmniboxResults, 2.0, 1.0); |
| 81 size_t webstore_group_id = | 82 size_t webstore_group_id = |
| 82 controller->AddGroup(kMaxWebstoreResults, 1.0, 0.4); | 83 controller->AddGroup(kMaxWebstoreResults, 1.0, 0.4); |
| 83 size_t people_group_id = controller->AddGroup(kMaxPeopleResults, 0.0, 0.85); | 84 size_t people_group_id = controller->AddGroup(kMaxPeopleResults, 0.0, 0.85); |
| 84 | 85 |
| 85 // Add search providers. | 86 // Add search providers. |
| 86 controller->AddProvider( | 87 controller->AddProvider( |
| 87 apps_group_id, | 88 apps_group_id, |
| 88 scoped_ptr<SearchProvider>(new AppSearchProvider( | 89 std::unique_ptr<SearchProvider>(new AppSearchProvider( |
| 89 profile, list_controller, make_scoped_ptr(new base::DefaultClock()), | 90 profile, list_controller, base::WrapUnique(new base::DefaultClock()), |
| 90 model->top_level_item_list()))); | 91 model->top_level_item_list()))); |
| 91 controller->AddProvider(omnibox_group_id, | 92 controller->AddProvider(omnibox_group_id, |
| 92 scoped_ptr<SearchProvider>( | 93 std::unique_ptr<SearchProvider>( |
| 93 new OmniboxProvider(profile, list_controller))); | 94 new OmniboxProvider(profile, list_controller))); |
| 94 controller->AddProvider(webstore_group_id, | 95 controller->AddProvider(webstore_group_id, |
| 95 scoped_ptr<SearchProvider>( | 96 std::unique_ptr<SearchProvider>( |
| 96 new WebstoreProvider(profile, list_controller))); | 97 new WebstoreProvider(profile, list_controller))); |
| 97 controller->AddProvider( | 98 controller->AddProvider(people_group_id, |
| 98 people_group_id, | 99 std::unique_ptr<SearchProvider>( |
| 99 scoped_ptr<SearchProvider>(new PeopleProvider(profile, list_controller))); | 100 new PeopleProvider(profile, list_controller))); |
| 100 if (IsSuggestionsSearchProviderEnabled()) { | 101 if (IsSuggestionsSearchProviderEnabled()) { |
| 101 size_t suggestions_group_id = | 102 size_t suggestions_group_id = |
| 102 controller->AddGroup(kMaxSuggestionsResults, 3.0, 1.0); | 103 controller->AddGroup(kMaxSuggestionsResults, 3.0, 1.0); |
| 103 controller->AddProvider( | 104 controller->AddProvider( |
| 104 suggestions_group_id, | 105 suggestions_group_id, |
| 105 scoped_ptr<SearchProvider>( | 106 std::unique_ptr<SearchProvider>( |
| 106 new SuggestionsSearchProvider(profile, list_controller))); | 107 new SuggestionsSearchProvider(profile, list_controller))); |
| 107 } | 108 } |
| 108 | 109 |
| 109 // LauncherSearchProvider is added only when flag is enabled, not in guest | 110 // LauncherSearchProvider is added only when flag is enabled, not in guest |
| 110 // session and running on Chrome OS. | 111 // session and running on Chrome OS. |
| 111 #if defined(OS_CHROMEOS) | 112 #if defined(OS_CHROMEOS) |
| 112 if (app_list::switches::IsDriveSearchInChromeLauncherEnabled() && | 113 if (app_list::switches::IsDriveSearchInChromeLauncherEnabled() && |
| 113 !profile->IsGuestSession()) { | 114 !profile->IsGuestSession()) { |
| 114 size_t search_api_group_id = | 115 size_t search_api_group_id = |
| 115 controller->AddGroup(kMaxLauncherSearchResults, 0.0, 1.0); | 116 controller->AddGroup(kMaxLauncherSearchResults, 0.0, 1.0); |
| 116 controller->AddProvider( | 117 controller->AddProvider( |
| 117 search_api_group_id, | 118 search_api_group_id, |
| 118 scoped_ptr<SearchProvider>(new LauncherSearchProvider(profile))); | 119 std::unique_ptr<SearchProvider>(new LauncherSearchProvider(profile))); |
| 119 } | 120 } |
| 120 #endif | 121 #endif |
| 121 | 122 |
| 122 return controller; | 123 return controller; |
| 123 } | 124 } |
| 124 | 125 |
| 125 } // namespace app_list | 126 } // namespace app_list |
| OLD | NEW |