Chromium Code Reviews| 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..03e7a781fb1be5f3aa6c05470f3e35cc349b1baf 100644 |
| --- a/chrome/browser/ui/app_list/app_list_view_delegate.cc |
| +++ b/chrome/browser/ui/app_list/app_list_view_delegate.cc |
| @@ -4,12 +4,16 @@ |
| #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" |
| @@ -27,6 +31,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 +56,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,63 +77,86 @@ 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) |
| - return; |
| + model_->SetSignedIn(!GetSigninDelegate()->NeedSignin()); |
| - 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(); |
| + |
| + apps_builder_->SwitchProfile(profile_); |
| + |
| + 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)); |
| + app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, |
| + model_)); |
| #endif |
| - OnProfileChanged(); |
| - } else { |
| - model_ = NULL; |
| - apps_builder_.reset(); |
| - search_controller_.reset(); |
| - signin_delegate_.reset(); |
| + OnProfileChanged(); |
| + |
| + // Update search results to show results for new profile. |
| + 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())); |
| + |
| + 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 |
| - } |
| + // Initialize the profile information in the app list menu. |
| + OnProfileChanged(); |
| } |
| app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { |
| @@ -220,6 +262,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 +274,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; |
|
xiyuan
2013/09/11 05:01:49
Why is this not needed?
calamity
2013/09/13 18:02:35
We need to remove this so that the menu updates on
|
| - |
| OnProfileChanged(); |
| } |