| 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 7d56c8a1259028d06028a8d6372219c8c6043730..8283eb281ec8effb4818ba34981f012743c9da66 100644
|
| --- a/chrome/browser/ui/app_list/app_list_view_delegate.cc
|
| +++ b/chrome/browser/ui/app_list/app_list_view_delegate.cc
|
| @@ -6,10 +6,13 @@
|
|
|
| #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_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"
|
| @@ -29,6 +32,8 @@
|
| #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"
|
| +#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"
|
| @@ -60,7 +65,18 @@ AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
|
| : controller_(controller),
|
| profile_(profile),
|
| model_(NULL) {
|
| + RegisterForNotifications();
|
| +}
|
| +
|
| +AppListViewDelegate::~AppListViewDelegate() {
|
| + if (signin_delegate_.get())
|
| + signin_delegate_->RemoveObserver(this);
|
| +}
|
| +
|
| +void AppListViewDelegate::RegisterForNotifications() {
|
| + registrar_.RemoveAll();
|
| DCHECK(profile_);
|
| +
|
| registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
|
| content::NotificationService::AllSources());
|
| registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
|
| @@ -71,13 +87,8 @@ AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
|
| content::Source<Profile>(profile_));
|
| }
|
|
|
| -AppListViewDelegate::~AppListViewDelegate() {
|
| - if (signin_delegate_.get())
|
| - signin_delegate_->RemoveObserver(this);
|
| -}
|
| -
|
| void AppListViewDelegate::OnProfileChanged() {
|
| - model_->SetSignedIn(!signin_delegate_->NeedSignin());
|
| + model_->SetSignedIn(!GetSigninDelegate()->NeedSignin());
|
| ProfileInfoCache& cache =
|
| g_browser_process->profile_manager()->GetProfileInfoCache();
|
| // Populate the current user details.
|
| @@ -89,37 +100,64 @@ void AppListViewDelegate::OnProfileChanged() {
|
|
|
| model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index),
|
| cache.GetUserNameOfProfileAtIndex(profile_index));
|
| +
|
| + // Populate the profile menu items.
|
| + app_list::AppListModel::ProfileMenuItems profile_menu_items;
|
| + profiles::PopulateAvatarMenuItemModels(&cache,
|
| + profile_->GetPath(),
|
| + &profile_menu_items);
|
| + model_->SetProfileMenuItems(profile_menu_items);
|
| }
|
|
|
| -void AppListViewDelegate::SetModel(app_list::AppListModel* model) {
|
| - if (signin_delegate_.get())
|
| - signin_delegate_->RemoveObserver(this);
|
| - 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_);
|
| +
|
| + RegisterForNotifications();
|
| +
|
| + apps_builder_->SetProfile(profile_);
|
| +
|
| + search_controller_.reset(new app_list::SearchController(
|
| + profile_, model_->search_box(), model_->results(), controller_.get()));
|
|
|
| - signin_delegate_.reset(new ChromeSigninDelegate(profile_));
|
| - signin_delegate_->AddObserver(this);
|
| + signin_delegate_->SetProfile(profile_);
|
|
|
| #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
|
| - OnProfileChanged();
|
| - } else {
|
| - model_ = NULL;
|
| - apps_builder_.reset();
|
| - search_controller_.reset();
|
| + OnProfileChanged();
|
| + if (!model_->search_box()->text().empty())
|
| + StartSearch();
|
| +}
|
| +
|
| +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()));
|
| + apps_builder_->Build();
|
| +
|
| + search_controller_.reset(new app_list::SearchController(
|
| + profile_, model->search_box(), model->results(), controller_.get()));
|
| +
|
| + signin_delegate_.reset(new ChromeSigninDelegate(profile_));
|
| + signin_delegate_->AddObserver(this);
|
| +
|
| #if defined(USE_ASH)
|
| - app_sync_ui_state_watcher_.reset();
|
| + app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
|
| + model));
|
| #endif
|
| - }
|
| + // Initialize the profile information in the app list menu.
|
| + OnProfileChanged();
|
| }
|
|
|
| app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() {
|
| @@ -229,6 +267,11 @@ void AppListViewDelegate::OpenFeedback() {
|
| chrome::kAppLauncherCategoryTag);
|
| }
|
|
|
| +void AppListViewDelegate::ShowForProfileByPath(
|
| + const base::FilePath& profile_path) {
|
| + controller_->ShowForProfileByPath(profile_path);
|
| +}
|
| +
|
| void AppListViewDelegate::OnSigninSuccess() {
|
| OnProfileChanged();
|
| }
|
|
|