Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(650)

Unified Diff: chrome/browser/ui/app_list/app_list_view_delegate.cc

Issue 20656002: Add profile selector menu to app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: small fixups Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/app_list/app_list_view_delegate.cc
diff --git a/chrome/browser/ui/app_list/app_list_view_delegate.cc b/chrome/browser/ui/app_list/app_list_view_delegate.cc
index ee4769fc650c333695c975dc3b291ad0fd8c40c5..d5fd1a53f2fa83457f9b65242535851e8a4ff196 100644
--- a/chrome/browser/ui/app_list/app_list_view_delegate.cc
+++ b/chrome/browser/ui/app_list/app_list_view_delegate.cc
@@ -6,9 +6,12 @@
#include "base/callback.h"
#include "base/files/file_path.h"
+#include "base/stl_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/feedback/feedback_util.h"
+#include "chrome/browser/profiles/profile_info_cache.h"
+#include "chrome/browser/profiles/profile_info_util.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/apps_model_builder.h"
@@ -25,6 +28,8 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/user_metrics.h"
+#include "ui/app_list/search_box_model.h"
+#include "ui/base/profile_selector/avatar_menu_item_model.h"
#if defined(USE_ASH)
#include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h"
@@ -54,33 +59,59 @@ void CreateShortcutInWebAppDir(
AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
Profile* profile)
: controller_(controller),
- profile_(profile) {}
+ profile_(profile),
+ model_(NULL) {}
AppListViewDelegate::~AppListViewDelegate() {}
-void AppListViewDelegate::SetModel(app_list::AppListModel* model) {
- if (model) {
- apps_builder_.reset(new AppsModelBuilder(profile_,
- model->apps(),
- controller_.get()));
- apps_builder_->Build();
+void AppListViewDelegate::SetProfileByPath(base::FilePath profile_path) {
+ DCHECK(model_);
- search_controller_.reset(new app_list::SearchController(
- profile_, model->search_box(), model->results(), controller_.get()));
+ // The profile must be loaded before this is called.
+ profile_ =
+ g_browser_process->profile_manager()->GetProfileByPath(profile_path);
+ DCHECK(profile_);
- signin_delegate_.reset(new ChromeSigninDelegate(profile_));
+ apps_builder_->SetProfile(profile_);
+
+ search_controller_.reset(new app_list::SearchController(
+ profile_, model_->search_box(), model_->results(), controller_.get()));
+
+ signin_delegate_->SetProfileByPath(profile_path);
#if defined(USE_ASH)
- app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
- model));
+ app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
+ model_));
#endif
- } else {
- apps_builder_.reset();
- search_controller_.reset();
+
+ UpdateModelWithCurrentProfiles();
+
+ if (!model_->search_box()->text().empty())
+ StartSearch();
+}
+
+void AppListViewDelegate::InitModel(app_list::AppListModel* model) {
+ DCHECK(model);
koz (OOO until 15th September) 2013/08/02 01:51:16 DCHECK(!model_), too.
calamity 2013/08/02 09:59:54 Done.
+ model_ = model;
+
+ // Initialize the profile information in the app list menu.
+ UpdateModelWithCurrentProfiles();
+
+ // Initialize apps model.
+ apps_builder_.reset(new AppsModelBuilder(profile_,
+ model->apps(),
+ controller_.get()));
+ apps_builder_->Build();
+
+ search_controller_.reset(new app_list::SearchController(
+ profile_, model->search_box(), model->results(), controller_.get()));
+
+ signin_delegate_.reset(new ChromeSigninDelegate(profile_));
+
#if defined(USE_ASH)
- app_sync_ui_state_watcher_.reset();
+ app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
+ model));
#endif
- }
}
app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() {
@@ -160,26 +191,6 @@ gfx::ImageSkia AppListViewDelegate::GetWindowIcon() {
return controller_->GetWindowIcon();
}
-string16 AppListViewDelegate::GetCurrentUserName() {
- ProfileInfoCache& cache =
- g_browser_process->profile_manager()->GetProfileInfoCache();
- size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
- if (profile_index != std::string::npos)
- return cache.GetNameOfProfileAtIndex(profile_index);
-
- return string16();
-}
-
-string16 AppListViewDelegate::GetCurrentUserEmail() {
- ProfileInfoCache& cache =
- g_browser_process->profile_manager()->GetProfileInfoCache();
- size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
- if (profile_index != std::string::npos)
- return cache.GetUserNameOfProfileAtIndex(profile_index);
-
- return string16();
-}
-
void AppListViewDelegate::OpenSettings() {
ExtensionService* service = profile_->GetExtensionService();
DCHECK(service);
@@ -209,3 +220,24 @@ void AppListViewDelegate::OpenFeedback() {
chrome::ShowFeedbackPage(browser, std::string(),
chrome::kAppLauncherCategoryTag);
}
+
+void AppListViewDelegate::ShowForProfileByPath(base::FilePath profile_path) {
+ controller_->ShowForProfileByPath(profile_path);
+}
+
+void AppListViewDelegate::UpdateModelWithCurrentProfiles() {
+ ProfileInfoCache& cache =
+ g_browser_process->profile_manager()->GetProfileInfoCache();
+ // Populate the current user details.
+ size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
+ DCHECK_NE(profile_index, std::string::npos);
+ model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index),
+ cache.GetUserNameOfProfileAtIndex(profile_index));
+
+ // Populate the profile menu items;
+ app_list::AppListModel::ProfileMenuItems profile_menu_items;
+ profiles::PopulateAvatarMenuItemModels(profile_menu_items,
+ &cache,
+ base::FilePath());
+ model_->SetProfileMenuItems(profile_menu_items);
+}

Powered by Google App Engine
This is Rietveld 408576698