| 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 e53fa9bdd092c35d14cd52b1973d63fc9a93da9b..b1f46a70e27cd02ca674f61d48cd9bf192603574 100644
|
| --- a/chrome/browser/ui/app_list/app_list_view_delegate.cc
|
| +++ b/chrome/browser/ui/app_list/app_list_view_delegate.cc
|
| @@ -4,17 +4,20 @@
|
|
|
| #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
|
|
|
| +#include <vector>
|
| +
|
| #include "base/callback.h"
|
| #include "base/files/file_path.h"
|
| +#include "base/stl_util.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/chrome_notification_types.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_manager.h"
|
| #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
|
| #include "chrome/browser/ui/app_list/apps_model_builder.h"
|
| #include "chrome/browser/ui/app_list/chrome_app_list_item.h"
|
| -#include "chrome/browser/ui/app_list/chrome_signin_delegate.h"
|
| #include "chrome/browser/ui/app_list/search/search_controller.h"
|
| #include "chrome/browser/ui/browser_finder.h"
|
| #include "chrome/browser/ui/chrome_pages.h"
|
| @@ -27,6 +30,7 @@
|
| #include "content/public/browser/notification_source.h"
|
| #include "content/public/browser/page_navigator.h"
|
| #include "content/public/browser/user_metrics.h"
|
| +#include "ui/app_list/search_box_model.h"
|
|
|
| #if defined(USE_ASH)
|
| #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h"
|
| @@ -51,6 +55,20 @@ void CreateShortcutInWebAppDir(
|
| }
|
| #endif
|
|
|
| +void PopulateUsers(const ProfileInfoCache& profile_info,
|
| + const base::FilePath& active_profile_path,
|
| + app_list::AppListModel::Users* users) {
|
| + const size_t count = profile_info.GetNumberOfProfiles();
|
| + for (size_t i = 0; i < count; ++i) {
|
| + app_list::AppListModel::User user;
|
| + user.name = profile_info.GetNameOfProfileAtIndex(i);
|
| + user.email = profile_info.GetUserNameOfProfileAtIndex(i);
|
| + user.profile_path = profile_info.GetPathOfProfileAtIndex(i);
|
| + user.active = active_profile_path == user.profile_path;
|
| + users->push_back(user);
|
| + }
|
| +}
|
| +
|
| } // namespace
|
|
|
| AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
|
| @@ -58,67 +76,87 @@ AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
|
| : controller_(controller),
|
| profile_(profile),
|
| model_(NULL) {
|
| + RegisterForNotifications();
|
| + g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
|
| +}
|
| +
|
| +AppListViewDelegate::~AppListViewDelegate() {
|
| + g_browser_process->
|
| + profile_manager()->GetProfileInfoCache().RemoveObserver(this);
|
| +}
|
| +
|
| +void AppListViewDelegate::RegisterForNotifications() {
|
| + registrar_.RemoveAll();
|
| DCHECK(profile_);
|
| +
|
| registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
|
| content::Source<Profile>(profile_));
|
| registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
|
| content::Source<Profile>(profile_));
|
| registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
|
| content::Source<Profile>(profile_));
|
| - g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
|
| -}
|
| -
|
| -AppListViewDelegate::~AppListViewDelegate() {
|
| - g_browser_process->
|
| - profile_manager()->GetProfileInfoCache().RemoveObserver(this);
|
| }
|
|
|
| void AppListViewDelegate::OnProfileChanged() {
|
| - model_->SetSignedIn(!signin_delegate_->NeedSignin());
|
| - ProfileInfoCache& cache =
|
| - g_browser_process->profile_manager()->GetProfileInfoCache();
|
| - // Populate the current user details.
|
| - size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
|
| - // The profile won't exist in the cache if the current app list profile is
|
| - // being deleted.
|
| - if (profile_index == std::string::npos)
|
| + search_controller_.reset(new app_list::SearchController(
|
| + profile_, model_->search_box(), model_->results(), controller_.get()));
|
| +
|
| + signin_delegate_.SetProfile(profile_);
|
| +
|
| +#if defined(USE_ASH)
|
| + app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
|
| + model_));
|
| +#endif
|
| +
|
| + model_->SetSignedIn(!GetSigninDelegate()->NeedSignin());
|
| +
|
| + // Don't populate the app list users if we are on the ash desktop.
|
| + chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
|
| + controller_->GetAppListWindow());
|
| + if (desktop == chrome::HOST_DESKTOP_TYPE_ASH)
|
| return;
|
|
|
| - model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index),
|
| - cache.GetUserNameOfProfileAtIndex(profile_index));
|
| + // Populate the app list users.
|
| + app_list::AppListModel::Users users;
|
| + PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(),
|
| + profile_->GetPath(), &users);
|
| + model_->SetUsers(users);
|
| }
|
|
|
| -void AppListViewDelegate::SetModel(app_list::AppListModel* model) {
|
| - if (model) {
|
| - model_ = model;
|
| - apps_builder_.reset(new AppsModelBuilder(profile_,
|
| - model->apps(),
|
| - controller_.get()));
|
| - apps_builder_->Build();
|
| +void AppListViewDelegate::SetProfileByPath(const 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_));
|
| + RegisterForNotifications();
|
|
|
| -#if defined(USE_ASH)
|
| - app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
|
| - model));
|
| -#endif
|
| - OnProfileChanged();
|
| - } else {
|
| - model_ = NULL;
|
| - apps_builder_.reset();
|
| - search_controller_.reset();
|
| - signin_delegate_.reset();
|
| -#if defined(USE_ASH)
|
| - app_sync_ui_state_watcher_.reset();
|
| -#endif
|
| - }
|
| + apps_builder_->SwitchProfile(profile_);
|
| +
|
| + OnProfileChanged();
|
| +
|
| + // Clear search query.
|
| + model_->search_box()->SetText(base::string16());
|
| +}
|
| +
|
| +void AppListViewDelegate::InitModel(app_list::AppListModel* model) {
|
| + DCHECK(!model_);
|
| + DCHECK(model);
|
| + model_ = model;
|
| +
|
| + // Initialize apps model.
|
| + apps_builder_.reset(new AppsModelBuilder(profile_,
|
| + model->apps(),
|
| + controller_.get()));
|
| +
|
| + // Initialize the profile information in the app list menu.
|
| + OnProfileChanged();
|
| }
|
|
|
| app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() {
|
| - return signin_delegate_.get();
|
| + return &signin_delegate_;
|
| }
|
|
|
| void AppListViewDelegate::ActivateAppListItem(
|
| @@ -220,6 +258,11 @@ void AppListViewDelegate::OpenFeedback() {
|
| chrome::kAppLauncherCategoryTag);
|
| }
|
|
|
| +void AppListViewDelegate::ShowForProfileByPath(
|
| + const base::FilePath& profile_path) {
|
| + controller_->ShowForProfileByPath(profile_path);
|
| +}
|
| +
|
| void AppListViewDelegate::Observe(
|
| int type,
|
| const content::NotificationSource& source,
|
| @@ -227,11 +270,12 @@ void AppListViewDelegate::Observe(
|
| OnProfileChanged();
|
| }
|
|
|
| +void AppListViewDelegate::OnProfileAdded(const base::FilePath& profile_path) {
|
| + OnProfileChanged();
|
| +}
|
| +
|
| void AppListViewDelegate::OnProfileNameChanged(
|
| const base::FilePath& profile_path,
|
| const base::string16& old_profile_name) {
|
| - if (profile_->GetPath() != profile_path)
|
| - return;
|
| -
|
| OnProfileChanged();
|
| }
|
|
|