| Index: chrome/browser/ui/views/aura/app_list/app_list_model_builder.cc
|
| diff --git a/chrome/browser/ui/views/aura/app_list/app_list_model_builder.cc b/chrome/browser/ui/views/aura/app_list/app_list_model_builder.cc
|
| index 6bd1ef1806f046e065f8b1ef4b21f2636130cd84..9b98a6398603729bab429426e86780d29c86c2d5 100644
|
| --- a/chrome/browser/ui/views/aura/app_list/app_list_model_builder.cc
|
| +++ b/chrome/browser/ui/views/aura/app_list/app_list_model_builder.cc
|
| @@ -4,7 +4,6 @@
|
|
|
| #include "chrome/browser/ui/views/aura/app_list/app_list_model_builder.h"
|
|
|
| -#include "ash/app_list/app_list_item_group_model.h"
|
| #include "chrome/app/chrome_command_ids.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| @@ -22,32 +21,10 @@
|
|
|
| namespace {
|
|
|
| -// Gets or creates group for given |extension| in |model|. The created group
|
| -// is added to |model| and owned by it.
|
| -ash::AppListItemGroupModel* GetOrCreateGroup(
|
| - int page_index,
|
| - const ListValue* app_page_names,
|
| - ash::AppListModel* model) {
|
| - if (page_index >= model->group_count()) {
|
| - for (int i = model->group_count(); i <= page_index; ++i) {
|
| - std::string title;
|
| - if (!app_page_names->GetString(i, &title))
|
| - title = l10n_util::GetStringUTF8(IDS_APP_DEFAULT_PAGE_NAME);
|
| -
|
| - ash::AppListItemGroupModel* group =
|
| - new ash::AppListItemGroupModel(title);
|
| - model->AddGroup(group);
|
| - }
|
| - }
|
| -
|
| - return model->GetGroup(page_index);
|
| -}
|
| -
|
| -// Binary predict to sort extension apps. Smaller launch ordinal takes
|
| -// precedence.
|
| -bool ExtensionAppPrecedes(const ExtensionAppItem* a,
|
| - const ExtensionAppItem* b) {
|
| - return a->launch_ordinal().LessThan(b->launch_ordinal());
|
| +// Binary predict to sort app list items alphabetically.
|
| +bool AppPrecedes(const ash::AppListItemModel* a,
|
| + const ash::AppListItemModel* b) {
|
| + return a->title() < b->title();
|
| }
|
|
|
| } // namespace
|
| @@ -62,59 +39,43 @@ AppListModelBuilder::~AppListModelBuilder() {
|
| }
|
|
|
| void AppListModelBuilder::Build() {
|
| - GetExtensionApps();
|
| - GetBrowserCommands();
|
| + Items items;
|
| +
|
| + GetExtensionApps(&items);
|
| + GetBrowserCommands(&items);
|
| +
|
| + std::sort(items.begin(), items.end(), &AppPrecedes);
|
| + for (Items::const_iterator it = items.begin(); it != items.end(); ++it) {
|
| + model_->AddItem(*it);
|
| + }
|
| }
|
|
|
| -void AppListModelBuilder::GetExtensionApps() {
|
| +void AppListModelBuilder::GetExtensionApps(Items* items) {
|
| DCHECK(profile_);
|
| ExtensionService* service = profile_->GetExtensionService();
|
| if (!service)
|
| return;
|
|
|
| // Get extension apps.
|
| - std::vector<ExtensionAppItem*> items;
|
| const ExtensionSet* extensions = service->extensions();
|
| for (ExtensionSet::const_iterator app = extensions->begin();
|
| app != extensions->end(); ++app) {
|
| if ((*app)->ShouldDisplayInLauncher())
|
| - items.push_back(new ExtensionAppItem(profile_, *app));
|
| - }
|
| -
|
| - // Sort by launch ordinal.
|
| - std::sort(items.begin(), items.end(), &ExtensionAppPrecedes);
|
| -
|
| - // Put all items into model and group them by page ordinal.
|
| - PrefService* prefs = profile_->GetPrefs();
|
| - const ListValue* app_page_names = prefs->GetList(prefs::kNtpAppPageNames);
|
| - for (size_t i = 0; i < items.size(); ++i) {
|
| - ExtensionAppItem* item = items[i];
|
| -
|
| - ash::AppListItemGroupModel* group = GetOrCreateGroup(
|
| - item->page_index(),
|
| - app_page_names,
|
| - model_);
|
| -
|
| - group->AddItem(item);
|
| + items->push_back(new ExtensionAppItem(profile_, *app));
|
| }
|
| }
|
|
|
| -void AppListModelBuilder::GetBrowserCommands() {
|
| +void AppListModelBuilder::GetBrowserCommands(Items* items) {
|
| Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
|
| if (!browser)
|
| return;
|
|
|
| - // Uses the first group to put browser commands
|
| - if (model_->group_count() == 0)
|
| - model_->AddGroup(new ash::AppListItemGroupModel(""));
|
| - ash::AppListItemGroupModel* group = model_->GetGroup(0);
|
| -
|
| - group->AddItem(new BrowserCommandItem(browser,
|
| - IDC_NEW_INCOGNITO_WINDOW,
|
| - IDS_APP_LIST_INCOGNITO,
|
| - IDR_APP_LIST_INCOGNITO));
|
| - group->AddItem(new BrowserCommandItem(browser,
|
| - IDC_OPTIONS,
|
| - IDS_APP_LIST_SETTINGS,
|
| - IDR_APP_LIST_SETTINGS));
|
| + items->push_back(new BrowserCommandItem(browser,
|
| + IDC_NEW_INCOGNITO_WINDOW,
|
| + IDS_APP_LIST_INCOGNITO,
|
| + IDR_APP_LIST_INCOGNITO));
|
| + items->push_back(new BrowserCommandItem(browser,
|
| + IDC_OPTIONS,
|
| + IDS_APP_LIST_SETTINGS,
|
| + IDR_APP_LIST_SETTINGS));
|
| }
|
|
|